Sabtu, 06 November 2010

Tutorial Java part - 2

public class Computer{private String monitorSpec;
private String mouseSpec;
private String keyboardSpec;

public void setMonitorSpec(String monitor){
monitorSpec = monitor;
}

public void setMouseSpec(String mouse){
mouseSpec = mouse;
}

public void setKeyboardSpec(String keyboard){
keyboardSpec = keyboard;}

public String getMonitorSpec(){
return monitorSpec;
}

public String getMouseSpec(){
return mouseSpec;
}

public String getKeyboardSpec(){
return keyboardSpec;}

public String toString(){
return "merek monitor anda" + " " + getMonitorSpec() + " " + "Merek mouse anda adalah" + " " + getMouseSpec() + " " + "Merek keyboard anda adalah " + getKeyboardSpec() ;
}


public String start(){
return "Computer is turn on… " ;}

public String shutDown(){
return "Computer is turn off";}

}




/*untuk kelas drivernya*/
class ComputerTestDrive{
public static void main(String[] args){
Computer P = new Computer();
P.setMonitorSpec("Dell");
P.setMouseSpec("optikal mouse");
P.setKeyboardSpec("sony");
System.out.println("\n" + P.toString());;
System.out.println( P.start());
System.out.println( P.shutDown());
}
}

Tidak ada komentar:

Posting Komentar