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

GUI: Image Viewer V3

Hi guys! In this post, we will make an Image Viewer v3 with GUI Programming. This is the classes we need to make the program: ImageViewer ImagePanel ImageFileManager OFImage Filter LighterFilter DarkerFilter ThresholdFilter FishEyeFilter Here is the source code for each of those classes ImageViewer 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.List; import java.util.ArrayList; import java.util.Iterator; /** * ImageViewer is the main class of the image viewer application. * It builds and displays the application GUI and * initializes all other components. * * @author (Elkana Hans Widersen) * @version 1.0 */ public class ImageViewer { // static fields: private static final String version = "Version 3.0"; private static JFileChooser fileChooser = new JFileChooser(System.getP...

Fox and Rabbit Simulator

Hi guys! I'm going to show you a Fox and Rabbit Simulator made in BlueJ. We're going to use these classes Simulator SimulatorView Location Field FieldStats Counter Randomizer Rabbit Fox Here is the source code of those classes: Simulator import java.util.Random; import java.util.List; import java.util.ArrayList; import java.util.Iterator; import java.awt.Color; /** * A simple predator-prey simulator, based on a rectangular field * containing rabbits and foxes. * * @author Elkana Hans Widersen * @version 1.0 */ public class Simulator { /** * Constants representing configuration information for the simulation. */ private static final int def_width = 50; // The default width for the grid. private static final int def_depth = 50; // The default depth of the grid. private static final double foxProbability = 0.02; // The probability that a fo...

UTS Parking Meter

Hai semuanya. Pos ini berisi tentang cara mengimplementasikan ke dalam bahasa Java sebuah mesin parkir elektronik. Sebagai contoh, coba lihat Mesin Parkir Elektronik yang telah dikembangkan oleh Dinas Perhubungan Kota Surabaya di sekitar Taman Bungkul. Proyek ini menggunakan 2 class, di antaranya: ParkingMeter InputReader Berikut source codenya: ParkingMeter /** * Class ini untuk class inti(main). * * @author (Elkana Hans Widersen/05111740000127/PBO A) * @version (15/10/2018) */ import java.util.Calendar; import java.util.Date; public class ParkingMeter{ private InputReader reader; private String TerminalID, JenisKendaraan, Nopol; private int NoTiket = 0, TarifParkir, SaldoAwal; private Calendar calendar; private Date today, tomorrow; public ParkingMeter() { reader = new InputReader(); calendar = Calendar.getInstance(); TerminalID = "00000001"; } ...