Comp Sci Creating a Transmitter Class for Mobile Phones

AI Thread Summary
The discussion focuses on creating a Transmitter class for a mobile phone application, which requires storing x, y coordinates and a signal radius. The x and y coordinates must fall within specific ranges, and the radius must be between 300 and 500 meters. Participants emphasize the need for constructors to validate input values before assigning them to class fields. There is also a mention of a testing class, TransmitterTest, which will help ensure the Transmitter class functions correctly. The conversation highlights common coding errors and the importance of proper parameter handling in constructors.
  • #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.
 
Physics news on Phys.org
  • #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 ;
    }

}
 

Similar threads

Replies
2
Views
2K
Replies
12
Views
2K
Replies
7
Views
3K
Replies
15
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
5
Views
3K
Replies
2
Views
4K
Back
Top