Java Reference
In-Depth Information
invoked, an argument must be passed in to each parameter in the method's
parameter list.
The following Radio class has several fields and methods. Study the class
and determine how many fields and methods it has. What is the parameter list
for each method in the Radio class?
public class Radio
{
public int volume; //0 -10
public float tuning; //Current station tuned in
public char band; //'A' for AM or 'F' for FM
public void turnOn(int v, float t, char b)
{
System.out.println(“Turning on the radio”);
setVolume(v);
setBand(b);
tuning = t;
}
public void setVolume(int volume)
{
//Make sure the input is valid (between 0 and 10).
System.out.println(“Setting the volume to “ + volume);
if(volume >= 0 && volume <= 10)
{
this.volume = volume;
}
else
{
this.volume = 0;
}
//Let's see what happens here.
volume = -5;
}
public void setBand(char b)
{
System.out.println(“Setting the band to “ + b);
//Make sure the input is valid ('A' or 'F').
if(b == 'A' || b == 'F')
{
band = b;
}
else
{
band = 'F';
}
Search WWH ::




Custom Search