- #1
blah45
- 65
- 0
Homework Statement
Introduction
You are part of a team working on a software system for a mobile phone company. You have been asked to write a class capable of storing the details of a transmitter.
The class will need fields to store the x,y coordinates of the transmitter and the transmitter's signal radius (in metres). The x,y coordinates are integer values. The x range is 800 to 1280 and the y range is 100 to 440. The minimum transmitter radius is 300 metres and the maximum is 500 metres.
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
The distance between a phone user and a transmitter can be calculated using the formula
x1,y1 could be the coordinates of the phone user and x2,y2 the coordinates of the transmitter. Java provides a Math class that includes a sqrt method as well as many other useful mathematical operations.
The Task
Create a class called Transmitter that stores the three specified fields (i.e. x, y and radius) and provides the following features
• a constructor that when passed three parameters (i.e. the x and y coordinates and the transmitter radius) creates an instance of the class
• a constructor that when passed two parameters (i.e. the x and y coordinates) sets the radius to a default value (i.e. 300) creates an instance of the class
• an accessor method for all three fields
• a mutator method for the radius field ONLY
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.
The Attempt at a Solution
I had a solution but my pc won't open the java file for some reason
If anyone can help thanks