Creating a Transmitter Class for Mobile Phones

In summary, the conversation discusses the task of creating a Transmitter class for a software system for a mobile phone company. The class needs to have fields for storing x, y coordinates and the transmitter's signal radius, with specific ranges for these values. The class also needs to have a constructor, accessor and mutator methods, and a method for calculating the best signal strength for a given phone's coordinates. The conversation also mentions a test class, TransmitterTest, and provides some guidelines for its implementation. Finally, the individual shares their attempted solution for the constructor but mentions difficulty opening the java file.
  • #36
Please read my comments in post #32.
 
Physics news on Phys.org
  • #37
I did i thought that's what you menat to change.

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.
 
  • #38
Cathal Cronin said:
I did i thought that's what you menat to change.
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.

The member variables for your class are X, Y, and Radius. X1, Y1, and Radius1 are parameters in the constructors. You should NOT be setting X1, Y1, and Radius1.
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.
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( ... );)
 
  • #39
This is definately it :)

i have a System.out.println() method that prints out all the x,y cords but it uses the last set to calculate the signal strength.
For the next part i don't really understand what I've done wrong, it genrates the random corodinates for x,y for however many transmitters the user puts in.
I know I'm probably wrong but like before I'm confused where to go with it,it seems right to me.

Code:
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;
    }

}
 
Last edited:
  • #40
That will work, but has some extra cruft in it that should be removed.

Code:
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 ;

}
There are similar lines in the following code where you set Y1 = Y and Radius1 = Radius. They should be removed.
In the second constructor there are two lines where you set X1 = X and Y1 = Y. They should be removed, too.
 
  • #41
okay done can u help with the test part I'm very confused with it
 
  • #42
A mobile phone user's signal strength is determined by their distance from a transmitter. If the distance is greater than the transmitter radius then the signal strength is zero. Otherwise the signal strength is determined as follows
(1 - (distance/radius)) * radius
.
.
.
Testing the Transmitter Class
To test the transmitter class you should create another class called TransmitterTest. The test class should look like the following
public class TransmitterTest
{
private Transmitter[] network ;

public TransmitterTest(int networkSize)
{
network = new Transmitter[networkSize] ;
//
// PUT YOUR CODE HERE
// to load the network array with
// "networkSize" instances of the Transmitter class.
// The x,y coordinates of the transmitters should be
// randomly generated. You can specify a radius or
// use the Transmitter Class default.
}

// PUT YOUR CODE HERE
// to do the operation(s) specified below

}

• Include a method called bestSignal that has the following header
public int bestSignal(int phoneX, int phoneY)
The method is passed the x,y coordinates of a phone and calculates the distance from the phone to each transmitter in the network. It returns the array index of the network transmitter that provides the best (i.e. highest) signal strength. If none of the transmitters provides a signal level greater than zero the method should return a -1 value.
------------------------------------------------------------------------------------
You're going to need a Main method that sets a value for networkSize and creates the network array with that many Transmitter objects in it. You'll need a loop that executes networkSize times, once for each Transmitter object in the network array.

For each Transmitter object generate random numbers for the x and y coordinates and the radius.

The bestSignal method should go through the network array and calculate the distance from the specified phone (the one with coordinates phoneX and phoneY), and return the index of the Transmitter array with the highest signal strength. In your earlier code you had bestSignal returning the distance, which isn't what it's supposed to do.
 
  • #43
i basically have that don't i. all i need to do is the best signal part isn't it?
 
  • #44
No, you don't "basically have that."

1. You don't have Main().
2. You aren't creating any Transmitter objects in your network array.
3. The values you are generating for X, Y, and Radius aren't correct. For example, in your code you have
Code:
X = randnumb.nextInt(800) + 480 ;
This will give you a value for X in the range [480, 1280]. What you want is a value in the range [800, 1280]
There's a similar problem for Y, where you have
Code:
Y = randnumb.nextInt(100) + 340 ;
This will give you a value in the range [340, 440], not [100, 440] as you're supposed to have.
4. You're doing something very silly with Radius.
Code:
Radius = Radius ;
There's NEVER a good reason to to this. It doesn't do any harm, but it's silly to set a variable to the value it already has.
5. The Transmitter objects should have random values for Radius, but your code isn't doing this - it uses the value 300 all the time.
6. What is the purpose of countX, countY, and countRad? By the time you get to i++ in your loop, i will have the same value as these other three variables, so what's the use of having them?
 
  • #45
oh okay, right i don't understand the main() part. how do i make it create a transmitter instance inside another class?

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

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
 
  • #46
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?
By using either of the two constructors you wrote for the Transmitter class.
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
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 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
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.
 
  • #47
yeah your right I'm trying to do it now i'll out up what I've done in a few mins
 
  • #48
How do i use the transmitters i made do i rewrite the code in or is there a way of calling a class within a class? do i apply the distance formula for each instance of the transmitters that i call
 
  • #49
it's not fully finished but is the random generation right?

Code:
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 ;
    }
   
}
 
  • #50
i'm so confused i don't know how to input each x,y and radius into each transmitter that gets created in the array, does it go in the loop or what??
 
  • #51
Yes, your random numbers look fine. They're now in the right intervals.

For your other question, the x, y, and radius values don't come from user input - they are generated as random numbers. And yes, each iteration of the loop needs to generate an x, a y, and a radius, then call a Transmitter constructor, passing those values of x, y, and radius in the constructor call.

You're going to have a statement like this inside the loop:
Code:
// generate random x, y, and radius values
network[i] = new Transmitter(x, y, radius);

So, network will be a Transmitter object.
network[2].getX() will return the X value for the Transmitter object at index 2 in the array.
network[m].getY() will return the Y value for the Transmitter object at index m in the array.
I think I remember that you have a getRadius() method. It would work the same way.
 
  • #52
is this part right now

Code:
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++ ;
        }

        
    }
 
  • #53
No.
1. You are calling the Transmitter constructor before you generate the values for X, Y, and Radius.
2. You're still missing a Main() function, which should be a member function of the TransmitterTest class.
3. Your calls to the getX, getY, and getRadius accessors aren't doing anything useful. Each of them evaluates to something, but since the values aren't stored anywhere or displayed, these calls have no useful effect.
 
  • #54
i don't understand the main() can u show me
 
  • #55
This qt has to be done by 4 and I'm going to send it at 3:45 but this i what i have for the test i know it's wrong but there's no more time for me to figure out how to fix it

Code:
///////////////////////////////|
////////  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 ;
    }

}
 
<h2>1. What is a transmitter class for mobile phones?</h2><p>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.</p><h2>2. Why is a transmitter class important for mobile phones?</h2><p>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.</p><h2>3. How is a transmitter class created for mobile phones?</h2><p>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.</p><h2>4. What are the key components of a transmitter class for mobile phones?</h2><p>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.</p><h2>5. Can a transmitter class be upgraded or improved?</h2><p>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.</p>

1. What is a transmitter class for mobile phones?

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.

2. Why is a transmitter class important for mobile phones?

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.

3. How is a transmitter class created for mobile phones?

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.

4. What are the key components of a transmitter class for mobile phones?

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.

5. Can a transmitter class be upgraded or improved?

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.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
23
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Back
Top