我有一个只有 99 个频道和 20 个作为最高音量的电视课程,但是当我将音量和频道设置器添加到音量而不是添加 1 到 10(这是我的默认音量)时,我的音量和频道设置器也无法正常工作,它只添加一个到给定的音量数字我的电视课
public class TV
{
private String flag;
private int ch;
private int vol = 10;
public TV(String onOffSwitch, int channel, int volume)
{
flag = onOffSwitch;
ch = channel;
vol = volume;
}
public void setFlag(String onOffSwitch)
{
onOffSwitch = "Off";
}// End of setFlag
public String getFlag()
{
return flag;
}// End of getFlag
public void setCh (int newChannel)
{
if (newChannel >= 99)
{
ch = 99;
}else
{
ch = newChannel;
}
if(newChannel < 0)
{
ch = 0;
}
}//end of setCh
public int getCh ()
{
return ch;
}// End of getCh
public void setVol(int newVolume)
{
if(newVolume >= 20)
{
vol = 20;
}
if(newVolume < 0)
{
vol=0;
}
}// End of SetVolume
public void incrementVolume()
{
vol++;
}
public int getVol()
{
return vol;
}// ENd of getVolume
public String toString()
{
return String.format("%s :%s\n%s:%d\n%s :%d","TV is switched", flag,"TV channel",ch,"TV volume",vol);
}
}// End of TV class
我的试驾课
import java.util.Scanner;
public class TvTest
{
public static void main (String[] args)
{
String tvStatus;
int chan;
int volu;
Scanner input = new Scanner(System.in);
TV tv2 = new TV("off",105,10);
System.out.print(tv2);
System.out.println();
System.out.print("Turn TV On or Off ?");
tvStatus = input.nextLine();
System.out.print("Channel : ");
chan = input.nextInt();
System.out.print("Volume : ");
volu = input.nextInt();
TV tv1 = new TV(tvStatus,chan,volu);
tv1.incrementVolume();
System.out.println(tv1);
}
}
和测试输出
TV is switched :off
TV channel:105
TV volume :10
Turn TV On or Off ?on
Channel : 105
Volume : 1
TV is switched :on
TV channel:105
TV volume :2
为什么我的二传手不工作???