- #36
Mark44
Mentor
- 37,621
- 9,849
Please read my comments in post #32.
2. In both constructors, if the values for x and y are not in the required range, you set X1 and Y1, not the member variables X and Y. Same problem for the first constructor, where Radius1, not Radius, gets set.Cathal Cronin said:I did i thought that's what you menat to change.
No, there should be, I'm pretty sure, a method named Main. If you want to see the values, put in some output statements (System.out.println( ... );)Cathal Cronin said:for post #34
I put in the accesors just for me iwanted to see the values that were being returned.
the main method is the transmitter test.
public class Transmitter
{
public int X ;
public int Y ;
public int Radius = 300 ;
public Transmitter(int X1, int Y1, int Radius1)
{
if(X1 < 800 || X1 > 1280)
{
System.out.println("ERROR, The X value you've entered is incorrect.") ;
System.out.println("Range MUST be : 800 to 128") ;
System.out.println("A default value will be set to 800");
X1 = X ; //Minimum value ( deafult range)//
X = 800 ;
}
else
{
X = X1;
}
if(Y1 < 100 || Y1 > 440)
{
System.out.println("ERROR!, The Y value you've entered is incorrect.") ;
System.out.println("Range MUST be : 100 to 440") ;
System.out.println("A default value will be set to 100");
Y1 = Y ; //Minimum value ( deafult range)//
Y = 100 ;
}
else
{
Y = Y1 ;
}
if(Radius1 < 300 || Radius1 > 500)
{
System.out.println("ERROR!, The Radius value you've entered is incorrect.") ;
System.out.println("Range MUST be : 300 to 500") ;
System.out.println("A default value will be set to 300");
Radius1 = Radius ; //Minimum value ( deafult range)//) ;
Radius = 300 ;
}
else
{
Radius1 = Radius ;
}
}
public Transmitter(int X1, int Y1)
{
if(X1 < 800 || X1 > 1280)
{
System.out.println("ERROR, The X value you've entered is incorrect.") ;
System.out.println("Range MUST be : 800 to 1280") ;
System.out.println("A default value will be set to 800");
X1 = X ;
X = 800 ; //Minimum value ( deafult range)//
}
else
{
X = X1 ;
}
if(Y1 < 100 || Y1 > 440)
{
System.out.println("ERROR!, The Y value you've entered is incorrect.") ;
System.out.println("Range MUST be : 100 to 440") ;
System.out.println("A default value will be set to 100");
Y1 = Y ; //Minimum value ( deafult range)//
Y = 100 ;
}
else
{
Y = Y1;
}
}
///---Accessers---//
public int getX()
{
return X ;
}
public int getY()
{
return Y ;
}
public int getRadius()
{
return Radius ;
}
///---Mutators---///
public void setRadius(int rad)
{
Radius = rad;
}
}
if(X1 < 800 || X1 > 1280)
{
System.out.println("ERROR, The X value you've entered is incorrect.") ;
System.out.println("Range MUST be : 800 to 128") ;
System.out.println("A default value will be set to 800");
X1 = X ; //<-- Take out this line
X = 800 ;
}
X = randnumb.nextInt(800) + 480 ;
Y = randnumb.nextInt(100) + 340 ;
Radius = Radius ;
By using either of the two constructors you wrote for the Transmitter class.Cathal Cronin said:oh okay, right i don't understand the main() part. how do i make it create a transmitter instance inside another class?
You really should get rid of the countX, countY, and countRadius variables. I guarantee that they won't do anything except confuse you further.Cathal Cronin said:The count parts we're so that when it had 1 value it stored that then generated another one depending on how many transmitters you wantted
Your instructor is going to wonder why all of your Transmitter objects (when you actually get to the point where you create some) have the same radius. He/she will probably deduct points if you do this.Cathal Cronin said:the radius is being set to the default radius in the transmitter that just has X1,Y1 as paprameters, i thought it would be easier if i just used the x and y instead of using all the variables
import java.util.Random ;
public class TransmitterTest
{
public int X ;
public int Y ;
public int X2 ;
public int Y2 ;
public int RadiusDefalut = 300 ;
public int Radius ;
private Transmitter[] network ;
public TransmitterTest(int networkSize)
{
network = new Transmitter[networkSize] ;
int i = 0 ;
while (i < networkSize)
{
Random randX = new Random() ;
X = randX.nextInt(480) + 800 ;
System.out.println(X) ;
Random randY = new Random() ;
Y = randY.nextInt(340) + 100 ;
System.out.println(Y + " ") ;
Random randRadius = new Random() ;
Radius = randRadius.nextInt(200) + 300 ;
System.out.println(Radius);
i++ ;
}
}
public int bestSignal(int phoneX, int phoneY)
{
int bestSignal ;
int X1 = X ;
int Y1 = Y ;
int X2 = phoneX ;
int Y2 = phoneY ;
int distance = (int)Math.sqrt( (X2 - X1)*(X2 - X1) + (Y2 - Y1)*(Y2 - Y1)) ;
bestSignal = (1 - ((distance/Radius)) * (Radius)) ;
return bestSignal ;
}
}
// generate random x, y, and radius values
network[i] = new Transmitter(x, y, radius);
import java.util.Random ;
public class TransmitterTest
{
public int X ;
public int Y ;
public int X2 ;
public int Y2 ;
public int RadiusDefalut = 300 ;
public int Radius ;
private Transmitter[] network ;
public TransmitterTest(int networkSize)
{
network = new Transmitter[networkSize] ;
int i = 0 ;
int p = 0 ;
while (i < networkSize)
{
network[i] = new Transmitter(X,Y,Radius) ;
Random randX = new Random() ;
X = randX.nextInt(480) + 800 ;
System.out.println(X) ;
network[i].getX() ;
Random randY = new Random() ;
Y = randY.nextInt(340) + 100 ;
System.out.println(Y) ;
network[i].getY();
Random randRadius = new Random() ;
Radius = randRadius.nextInt(200) + 300 ;
System.out.println(Radius);
network[i].getRadius() ;
i++ ;
}
}
///////////////////////////////|
//////// Cathal Cronin //////|
//////// ID : 10131531 //////|
///////////////////////////////|
import java.util.Random ;
public class TransmitterTest
{
public int X ;
public int Y ;
public int Radius ;
private Transmitter[] network ;
public TransmitterTest(int networkSize)
{
network = new Transmitter[networkSize] ;
int i = 0 ;
while (i < networkSize)
{
Random randX = new Random() ;
X = randX.nextInt(480) + 800 ;
System.out.println(X) ;
Random randY = new Random() ;
Y = randY.nextInt(340) + 100 ;
System.out.println(Y) ;
Random randRadius = new Random() ;
Radius = randRadius.nextInt(200) + 300 ;
System.out.println(Radius) ;
network[i] = new Transmitter(X,Y,Radius) ;
i++ ;
}
}
public int bestSignal(int phoneX, int phoneY)
{
int bestSignal ;
int X1 = X ;
int Y1 = Y ;
int X2 = phoneX ;
int Y2 = phoneY ;
int distance = (int)Math.sqrt( (X2 - X1)*(X2 - X1) + (Y2 - Y1)*(Y2 - Y1)) ;
bestSignal = (1 - distance/Radius * Radius) ;
return bestSignal ;
}
}
See http://download.oracle.com/javase/tutorial/getStarted/application/index.html.Cathal Cronin said:i don't understand the main() can u show me