构造函数问题

时间:2017-08-29 00:55:38

标签: java

我无法获得构造函数中变量(volume)的值,其他2个变量(boolean on和play)我可以管理没问题。当我尝试在我的对象中调用openMenu()方法时它不会显示音量变量,当我创建一个姿势时它应该从50开始,我测试了volumUp和volumDown,然后它们添加到音量,但是初始值未设置。

public class ControleClass implements controle_Interface {

private int volume;
private boolean on;
private boolean play;



public void  ControleClass (){
    this.volume = 50;
    this.on = true;
    this.play = false;

}

public int getVolume() {
    return this.volume;
}

public boolean isOn() {
    return this.on;
}

public boolean isPlay() {
    return this.play;
}

public void setVolume(int volume) {
    this.volume = volume;
}

public void setOn(boolean on) {
    this.on = on;
}

public void setPlay(boolean play) {
    this.play = play;
}

@Override
public void on() {
    this.setOn(true);
}

@Override
public void off() {
    this.setOn(false);
}

**@Override
public void openMenu() {
    System.out.println("Is on? " + this.isOn()); **//it shows this status np**
    System.out.println("Is playing? " + this.isPlay());//Also this one
    System.out.println("Volume " + this.getVolume());//But not this one
    for (int i = 0; i < this.getVolume(); i += 5){
        System.out.println("V ");
    }**

}

@Override
public void closeMenu() {
    System.out.println("Closing menu...");
}

@Override
public void volumUp() {
    if (this.isOn() && this.volume < 100){
      this.setVolume(getVolume() + 5); 
    }
}

@Override
public void volumDown() {
    if (this.isOn() && this.volume >= 0){
        this.setVolume(getVolume() - 5);
    }
}

@Override
public void muteOn() {
    if(this.isOn()){
       this.setVolume(0);
    }
}

@Override
public void muteOff() {
    if(this.isOn()){
        this.setVolume(50);
    }
}

@Override
public void play() {
    if(this.isOn() && !(this.isPlay())){
        this.setPlay(true);


    }
}

@Override
public void pause() {
   if(this.isOn() && this.isPlay()){
       this.setPlay(false);
   }
}

0 个答案:

没有答案