Langsung ke konten utama

Tugas PBO Remote AC

Hey guys! In this post I'm going to show you how to make an AC Remote using BlueJ.
I'm going to use 2 classes, which are:
  1. Main
  2. ACRemote

Main

 /*  
  * Main function for the AC Remote  
  *  
  * Elkana Hans Widersen  
  * 05111740000127  
  * 23 September 2018  
  */  
 import java.util.Scanner;  
 public class Main{  
   public static void main(String args[]){  
     int menu;  
     Scanner input = new Scanner(System.in);  
       
     //Creates the remote  
     ACRemote remote = new ACRemote();  
     while(true){  
       //displays the remote interface every loop  
       remote.display();  
         
       //scans for menu number  
       menu = input.nextInt();  
       switch(menu){  
         //changes the temperature  
         case 1: remote.TempUp(); break;  
         case 2: remote.TempDown(); break;  
           
         //sets the AC swing mode  
         case 3: remote.getSwing(); break;  
           
         //terminates when the AC turned off  
         case 4: System.exit(0); break;  
       }  
     }  
   }   
 }  

ACRemote

 /*  
  * AC Remote Function  
  *  
  * Elkana Hans Widersen  
  * 05111740000127  
  * 23 September 2018  
  */  
 public class ACRemote{  
   private int temp;  
   private String swing;  
     
   //AC Remote Declaration  
   public ACRemote(){  
     temp = 24;  
     swing = "OFF";  
   }  
     
   //Sets Swing Mode  
   public void getSwing(){   
     if(swing == "OFF") swing = "ON ";   
     else swing = "OFF";   
   }   
     
   //Decrease temperature  
   public void TempDown(){  
     if(temp == 18) temp = 18;  
     else temp--;  
   }  
   
   //Increase temperature  
   public void TempUp(){  
     if(temp == 30) temp = 30;  
     else temp++;  
   }  
     
   //Displays the remote interface  
   public void display(){   
     System.out.println("|-------------------|");   
     System.out.println("|   TOSHIBA   |");   
     System.out.println("| Air Conditioner |");  
     System.out.println("|-------------------|");  
     System.out.println("|     " + temp + "    |");  
     System.out.println("|-------------------|");   
     System.out.println("|  SWING = " + swing + "  |");   
     System.out.println("|-------------------|");   
     System.out.println("| 1. ^  2. v  |");  
     System.out.println("| 3. Swing ON/OFF |");   
     System.out.println("| 4. AC Power OFF |");   
     System.out.println("|-------------------|\n");  
   }  
 }  


When you are done, it should look like this:


Thank you and see you next time!

Komentar

Postingan populer dari blog ini

UAS GUI 3.1

Nama: Elkana Hans Widersen NRP: 05111740000127 Kelas: PBO-A 1. Inilah rancangan interface dari image editor yang saya buat: 2. Berikut diagram dari kelas-kelas penyusun image editor saya beserta relasinya: Image Viewer: Kelas utama yang mengatur fitur-fitur utama dari image editor. Image Panel: Kelas swing untuk menampilkan gambar dalam format OF. Image File Manager: Mengatur fungsi load dan save. OF Image: Mendefinisikan gambar dalam format OF. Filter: Abstraksi dari filter-filter yang tersedia. Darker Filter: Berisi settingan filter Darker. Lighter Filter: Berisi settingan filter Lighter . Threshold Filter:  Berisi settingan filter Threshold. Fish-eye Filter:  Berisi settingan filter Fish-eye. 3. Berikut implementasi dari kelas-kelas di atas: Image Viewer import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import java.io.File; import java.util...

Tugas 3 PBO A

Hey guys! This time I have been working on making my own Ticket Machine using BlueJ. I am using 2 classes, which is Main and TicketMachine . TicketMachine /* * This class contains the declaration of the Ticket Machine we are going to use.. * * @author (Elkana Hans Widersen) * @version (17/9/2018) */ import java.util.Scanner; public class TicketMachine{ Scanner scan = new Scanner(System.in); // The price of a ticket from this machine. private int price; // The amount of money entered by a customer so far. private int balance; // The amount of tickets about to be printed. private int ticket; // The total amount of money collected by this machine. private int total; /* * Create a machine that issues tickets of the given price. * Note that the price must be greater than zero, and there * are no checks to ensure this. */ public TicketMachine(int ticketCost){ ...