Java Reference
In-Depth Information
}
public void turnUp()
{
System.out.println(“Turning the volume up”);
if(volume < 10)
{
volume += 1; //Increase volume by 1
}
}
public void turnDown()
{
System.out.println(“Turning the volume down”);
if(volume > 0)
{
volume -= 1; //Decrease volume by 1
}
}
public float getTuning()
{
System.out.println(“Inside getTuning”);
return tuning;
}
public void changeBand()
{
System.out.println(“Switching bands”);
if(band == 'A')
{
band = 'F';
}
else
{
band = 'A';
}
}
}
Notice that the Radio class has three fields: volume, tuning, and band. The
Radio class also has seven methods. The turnOn() method has three parame-
ters: an int, a float, and a char. To invoke turnOn(), you must pass in an int,
float, and char (in that order) as arguments.
The setVolume() has one parameter: an int. To invoke setVolume(), you must
pass in an int argument. The setBand() method also has one parameter: a char.
Similarly, to invoke setBand() you must pass in a char argument.
The other four methods have no parameters. No arguments can be passed in
to these methods.
Search WWH ::




Custom Search