Sunday, September 23, 2018

PBO A-Tugas 4: Remote AC

Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A


Ini adalah tugas saya pada pertemuan minggu ke-5 dengan membuat Remote AC dengan menggunakan class Java/bahasa java.

A. Main
 import java.util.Scanner;    
  public class Main    
  {    
   public static void main(String args[])    
   {     
   Scanner scan= new Scanner(System.in);    
   int power,option;  
   RemoteAC remote=new RemoteAC();   
   while (true){  
   System.out.println("Sharp Air Conditioner \n");  
   System.out.println("To turn on press 1 \n");  
   power=scan.nextInt();    
   while (power==1){  
     remote.print();  
   option=scan.nextInt();    
   if(option==0){    
     power=0;break;    
   }   
   else if(option==1){    
    remote.tempplus();    
   }    
   else if(option==2){    
    remote.tempmin();    
   }    
   else if(option==3){    
    remote.changemode();   
   }  
   else if(option==4){  
    remote.changefanspeed();  
   }  
   else if(option==5){  
    remote.changeswing();  

   }  
   }  
} } }
B. Class RemoteAC
 /**  
  * Write a description of class RemoteAC here.  
  * @author Muhammad Naufal Refadi  
  * @version 22-9-2018  
  */  
 public class RemoteAC  
 {  
   private int temp;  
   private String mode;  
   private String swing;  
   private String fanspeed;  
   public RemoteAC()  
   {  
     temp=25;  
     mode= new String("AUTO");  
     swing= new String("ON");  
     fanspeed= new String("MEDIUM");  
   }  
   public int tempplus(){  
    if(temp<30){temp++;}  
    else{  
     System.out.println("The maximum temperature is 30");  
     }  
     return temp;  
   }  
   public int tempmin(){  
    if(temp>16){temp--;}  
    else{  
       System.out.println("The maximum temperature is 16");  
    }  
    return temp;  
   }  
   public String changemode(){  
     if(mode.equals("AUTO")){mode= new String("FAN");}  
     else if(mode.equals("FAN")){mode= new String("COOL");}  
     else if(mode.equals("COOL")){mode= new String("HEAT");}  
     else if(mode.equals("HEAT")){mode= new String("DRY");}  
     else if (mode.equals("DRY")){mode= new String("AUTO");}  
     System.out.println(mode);  
     return mode;  
   }  
   public String changefanspeed(){  
    if(fanspeed.equals("LOW")){fanspeed= new String("MEDIUM");}  
    else if(fanspeed.equals("MEDIUM")){fanspeed= new String("HIGH");}  
    else if(fanspeed.equals("HIGH")){fanspeed= new String("LOW");}  
    return fanspeed;  
   }  
   public String changeswing(){  
     if(swing.equals("ON")){swing= new String("OFF");}  
     else if(swing.equals("OFF")){swing= new String("ON");}  
     return swing;    
   }  
   public void print(){  
    System.out.println("#####################");   
    System.out.println("#  REMOTE CONTROL #");   
    System.out.println("# Air Conditioner #");   
    System.out.println("#  "+temp+" Celcius   #");   
    System.out.println("#  MODE = "+mode+"  #");  
    System.out.println("#  FAN = "+fanspeed+"  #");  
    System.out.println("#  SWING = "+swing+"   #");   
    System.out.println("#------OPTION-------#");   
    System.out.println("# 0.Turn OFF AC  #");  
    System.out.println("# 1.Temperature ^ #");   
    System.out.println("# 2.Temperature v #");   
    System.out.println("# 3.Change Mode  #");  
    System.out.println("# 4.Fan Speed   #");  
    System.out.println("# 5.Swing Mode   #");   
    System.out.println("#-------------------#");   
    System.out.println("#####################");   
    System.out.println();   
   }  
 }  

Screenshot Input dan Output
-Nyalakan Ac

 -Naikkan Suhu

-Turunkan suhu dan mengubah mode AC



-Naikkan fan speed

- Switch Swing mode On/OFF


No comments:

Post a Comment