วันจันทร์ที่ 6 กุมภาพันธ์ พ.ศ. 2555

TV

package
java_1;


public
class TV {

private int chanel = 1;//1-10

private int volume = 1;//0-5

private boolean status = false;// By default TV is off

private String brand = "";

public static int count = 0;


TV(){

count++;

brand = "Sony";

}

TV(String newBrand){

count++;

brand = newBrand;

}

TV(String newBrand,
int newchanel){

count++;

brand = newBrand;

chanel = newchanel;

}

public String getBrand(){

return brand;

}

public void turnOn(){

//Mutator of status variable

status = true;

}

public void turnOff(){

//Mutator of status variable

status = false;

}

public boolean getStatus(){

//Accessor of status variable

return status;

}

public void chanelUp(){

chanel++;

if(chanel > 10){

chanel = 1;


}

}

public void chanelDown(){

chanel--;

if(chanel < 1){

chanel = 10;

}

}

public int getChanel(){

if(status == false)

{

System.
out.println("Please TurnOn TV");

return 0;

}

else

return chanel;

}

public void volumeUp(){

if(volume < 5)

volume++;

else

System.
out.println("Maximum");

}

public void volumeDown(){

if(volume > 0)

volume--;

else

System.
out.println("Minimum");


}

public int getVolume(){

return volume;

}

public boolean equalsTV(TV o){

if(o.getChanel() != this.getChanel())

return false;

if(o.getStatus() != this.getStatus())

return false;

if(o.getVolume() != this.getVolume())

return false;

return true;

}


}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น