- #36
Mark44
Mentor
- 37,544
- 9,784
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
A transmitter class for mobile phones is a set of instructions and functions that allow a mobile phone to transmit and receive signals. It is a crucial component in the communication process, as it allows the phone to connect to a cellular network and communicate with other devices.
A transmitter class is important for mobile phones because it enables them to function as communication devices. Without a transmitter class, a mobile phone would not be able to send or receive calls, texts, or data, rendering it useless as a communication tool.
A transmitter class for mobile phones is created by programming a set of instructions and functions using a programming language such as Java or C++. The code is then compiled and integrated into the mobile phone's operating system, allowing it to function as a transmitter.
The key components of a transmitter class for mobile phones include a radio frequency (RF) module, an antenna, and a power amplifier. The RF module is responsible for converting digital signals into analog signals, while the antenna transmits and receives these signals. The power amplifier boosts the signal for better transmission and reception.
Yes, a transmitter class for mobile phones can be upgraded or improved through software updates or hardware modifications. These upgrades can improve the phone's signal strength, data transfer speed, and overall performance. However, the hardware limitations of the phone may also play a role in the effectiveness of these upgrades.