Sabtu, 29 September 2018

TUGAS 5 PBO - MEMBUAT JAM DIGITAL


 
 TUGAS 5 PEMROGRAMAN BERORIENTASI OBJEK




Nama    : Atika Rizki Nurakhmah
NRP      : 05111740000015
Kelas    : PBO - A

Kali ini saya mendapat tugas untuk latihan membuat jam digital. Untuk membuatnya diperlukan 3 class, yaitu :
  • NumberDisplay
  • ClockDisplay
  • TestClockDisplay
Begini tampilannya :



Berikut Source Code nya :
a. Source Code Class NumberDisplay
/**   
  * Source Code NumberDisplay  
  * @author (Atika Rizki Nurakhmah)   
  * @version (01/tugas5/29092018)   
  */   
 public class NumberDisplay {   
   private int limit;   
   private int value;  
   public NumberDisplay(int rollOverLimit)    
     {      
       limit = rollOverLimit;      
       value = 0;   
     }  
     public int getValue()   
   {   
     return value;   
   }  
   public void setValue(int replacementValue) {   
      if((replacementValue >= 0) && (replacementValue < limit))   
      {        
        value = replacementValue; }  
       }  
       public String getDisplayValue() {   
     if(value < 10) {   
       return "0" + value; }   
       else {   
       return "" + value; }   
     }  
     public void increment() {   
       value = (value + 1) % limit;   
     }  
 }  

b. Source Code Class ClockDisplay
/**   
  * Source Code ClockDisplay  
  * @author (Atika Rizki Nurakhmah)   
  * @version (02/tugas5/29092018)   
  */   
 public class ClockDisplay {   
   private NumberDisplay hours;   
   private NumberDisplay minutes;   
   private String displayString;   
   public ClockDisplay() {   
     hours = new NumberDisplay(24);   
     minutes = new NumberDisplay(60);   
     updateDisplay();   
   }    
   public ClockDisplay(int hour, int minute) {   
     hours = new NumberDisplay(24);   
     minutes = new NumberDisplay(60);   
     setTime(hour, minute);   
     }  
     public void timeTick() {  
     minutes.increment();   
     if(minutes.getValue() == 0) {   
       hours.increment();   
     }  
       updateDisplay(); }    
    public void setTime(int hour, int minute) {      
      hours.setValue(hour);      
      minutes.setValue(minute);      
      updateDisplay();    
     }    
    public String getTime() {   
      return displayString;   
     }    
    private void updateDisplay() {   
      displayString = hours.getDisplayValue() + ":" +   
      minutes.getDisplayValue();    
     }   
 }  

c. Source Code Class TestClockDisplay
/**   
  * Source Code TestClockDisplay  
  * @author (Atika Rizki Nurakhmah)   
  * @version (03/tugas5/29092018)   
  */   
  public class TestClockDisplay    
  {    
   public TestClockDisplay()    
   {    
   }    
   public void test()    
   {    
   ClockDisplay clock = new ClockDisplay();    
   clock.setTime(18,59);    
   System.out.println(clock.getTime());    
   clock.setTime(5,40);    
   System.out.println(clock.getTime());   
   clock.setTime(20,38);    
   System.out.println(clock.getTime());   
   clock.setTime(15,17);    
   System.out.println(clock.getTime());   
   }    
  }


TAMBAHAN

Saya juga diminta untuk mencoba membuat penghitung waktu dalam GUI. GUI ini display nya seperti stopwatch. Menghitung waktu yang berjalan, dengan display menit dan detik. Begini tampilannya.


Jika Tombol Start ditekan, maka waktu akan berjalan maju. 


Jika Tombol Stop diklik, maka waktu akan berhenti. 


Tombol step digunakan untuk memajukan waktu step by step, atau satu per satu.


 Berikut Source Code untuk GUI
/**   
  * Source Code GUI  
  * @author (Atika Rizki Nurakhmah)   
  * @version (04/tugas5/29092018)   
  */    
  import java.awt.*;    
  import java.awt.event.*;    
  import javax.swing.*;    
  import javax.swing.border.*;    
  public class ClockGUI    
  {    
   private JFrame frame;    
   private JLabel label;    
   private ClockDisplay clock;    
   private boolean clockOn = false;    
   private TimerThread timerThread;    
   public void Clock()    
   {    
   makeFrame();    
   clock = new ClockDisplay();    
   }    
   private void start()    
   {    
   clockOn = true;    
   timerThread = new TimerThread();    
   timerThread.start();    
   }    
   private void stop()    
   {    
   clockOn = false;    
   }    
   private void step()    
   {    
   clock.timeTick();    
   label.setText(clock.getTime());    
   }    
   private void showAbout()    
   {    
   JOptionPane.showMessageDialog (frame, "Clock Version 0.1\n" +    
   "Membuat jam digital simpel dengan Java.",    
   "About Clock",    
   JOptionPane.INFORMATION_MESSAGE);    
   }    
   private void quit()    
   {    
   System.exit(0);    
   }    
   private void makeFrame()    
   {    
   frame = new JFrame("Clock");    
   JPanel contentPane = (JPanel)frame.getContentPane();    
   contentPane.setBorder(new EmptyBorder(1,60,1,60));    
   makeMenuBar(frame);    
   contentPane.setLayout(new BorderLayout(12,12));    
   label = new JLabel("00:00", SwingConstants.CENTER);    
   Font displayFont = label.getFont().deriveFont(96.0f);    
   label.setFont(displayFont);    
   contentPane.add(label, BorderLayout.CENTER);    
   JPanel toolbar = new JPanel();    
   toolbar.setLayout(new GridLayout(1,0));    
   JButton startButton = new JButton("Start");    
   startButton.addActionListener(e->start());    
   toolbar.add(startButton);    
   JButton stopButton = new JButton("Stop");    
   stopButton.addActionListener(e->stop());    
   toolbar.add(stopButton);    
   JButton stepButton = new JButton("Step");    
   stepButton.addActionListener(e->step());    
   toolbar.add(stepButton);    
   JPanel flow = new JPanel();    
   flow.add(toolbar);    
   contentPane.add(flow, BorderLayout.SOUTH);    
   frame.pack();    
   Dimension d = Toolkit.getDefaultToolkit().getScreenSize();    
   frame.setLocation(d.width/2 - frame.getWidth()/2, d.height/2 - frame.getHeight()/2);    
   frame.setVisible(true);    
   }    
   private void makeMenuBar(JFrame frame)    
   {    
   final int SHORTCUT_MASK =    
   Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();    
   JMenuBar menubar = new JMenuBar();    
   frame.setJMenuBar(menubar);    
   JMenu menu;    
   JMenuItem item;    
   menu = new JMenu("File");    
   menubar.add(menu);    
   item = new JMenuItem("About Clock...");    
   item.addActionListener(e->showAbout());    
   menu.add(item);    
   menu.addSeparator();    
   item = new JMenuItem("Quit");    
   item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,SHORTCUT_MASK));    
   item.addActionListener(e->quit());    
   menu.add(item);    
   }    
   class TimerThread extends Thread    
   {    
   public void run()    
   {    
   while(clockOn)    
   {    
    step();    
    pause();    
   }    
   }    
   private void pause()    
   {    
   try    
   {    
    Thread.sleep(900);    
   }    
   catch(InterruptedException exc)    
   {    
   }    
   }    
   }    
  }    

Sekian tugas latihan saya, sampai bertemu di ulasan selanjutnya :))))

Kamis, 20 September 2018

TUGAS 4 PBO-A : MEMBUAT PROGRAM REMOTE AC


TUGAS 4 PEMROGRAMAN BERORIENTASI OBJEK


Nama   : Atika Rizki Nurakhmah
NRP     : 05111740000015
Kelas   : PBO -A
Departemen Informatika ITS


Hallo Good People!
Kali ini saya diberi tugas (lagi :D), untuk membuat program remote AC. Tentunya dengan versi sederhana. Saya menggunakan Blue J.
Untuk program ini saya membuat dua Class. Yaitu Class Main dan Class RemoteAC.
  1. Class RemoteAC
    Dalam class ini terdapat fungsi-fungsi layaknya fungsi peroperasian pada remote AC. Tidak semua fungsi remote AC saya buat, hanya beberapa saja, antara lain :

    • public int TempUp()
      Fungsi ini digunakan untuk meningkatkan temperatur. Suhu awal saat AC dinyalakan saya atur di angka 22. User bisa menaikkan suhu menggunakan fungsi ini. Batas maksimal suhu yang saya gunakan adalah 30 derajat celcius. Jika user menaikkan suhu melebihi batas maksimal, maka akan muncul peringatan.
    • public int TempDown()
      Fungsi ini digunakan untuk menurunkan suhu. Suhu minimum yang saya gunakan adalah 16 derajat celcius. Sama seperti fungsi TempUp, jika user menurunkan suhu melebihi batas minimum, maka akan mucul peringatan.
    • public String getMode(int mode)
      Fungsi ini dapat digunakan user untuk mengubah mode AC. Jika user memilih opsi ini, maka akan muncul beberapa pilihan mode yang bisa digunakan.
    • public String getSwing()
      Fungsi ini dapat digunakan user untuk mengaktifkan atau menonaktifkan mode swing (ayunan) pada AC.
    • public void print()
      Fungsi ini saya tambahkan untuk mengatur display pada remote AC. Setiap pengaturan yang dilakukan user akan ditampilkan melalui fungsi ini.
  2. Class Main
    Class ini digunakan untuk memanggil fungsi-fungsi yang diperlukan, sesuai dengan input dari user.

    Berikut adalah Source Code nya :

    • Class RemoteAC
 /**  
  * Fungsi-fungsi Remote AC dan display nya.  
  *  
  * @author (Atika Rizki Nurakhmah)  
  * @version (01.01/tugas4/2018)  
  */  
 public class RemoteAC  
 {  
   private int Temp;  
   private int nyala;  
   private int TempDef;  
   private int mode;  
   private String Mode, Swing;  
   private boolean isSwing;  
   /**  
    * Constructor for objects of class RemoteAC  
    */  
   public RemoteAC()  
   {  
     TempDef = 22;  
     Mode = new String("AUTO");  
     Swing = new String("OFF");  
     isSwing = false;  
   }  
   public int TempUp(){  
     if(TempDef==30){  
       System.out.println("!!!Suhu sudah mencapai batas maksimum!!!");  
       System.out.println("-----------------------------------------");}  
       else{  
     TempDef++;}  
     return TempDef;  
   }  
   public int TempDown(){  
     if(TempDef==16){  
       System.out.println("!!!Suhu sudah mencapai batas minimum!!!");  
       System.out.println("-----------------------------------------");}  
       else{  
     TempDef--;}  
     return TempDef;  
   }  
   public String getMode(int mode){  
     if(mode==1){  
       Mode = new String ("AUTO");  
     }  
     else if(mode==2){  
       Mode = new String ("FAN");  
     }  
     else if(mode==3){  
       Mode = new String ("DRY");  
     }  
     else if(mode==4){  
       Mode = new String ("COOL");  
     }  
     else if(mode ==5){  
       Mode = new String ("HEAT");  
     }  
     else{  
       Mode = new String ("Mode yang dimasukkan tidak tersedia");  
 }  
   return Mode;}  
   public String getSwing(){  
     if (isSwing==false){  
       isSwing=true;  
       Swing=new String("ON");}  
     else {  
       isSwing=false;  
       Swing=new String("OFF");}  
       return Swing;  
     }  
   public void print(){  
     System.out.println("##################");  
     System.out.println("#### SHARPP ####");  
     System.out.println("## 19-09-2018 ##");  
     System.out.println("## "+TempDef+" Celcius ##");  
     System.out.println("## MODE = "+Mode+" #");  
     System.out.println("## SWING = "+Swing+"  #");  
     System.out.println("#----- OPSI -----#");  
     System.out.println("#1.Temperature ^ #");  
     System.out.println("#2.Temperature v #");  
     System.out.println("#3.Ubah Mode   #");  
     System.out.println("#4.Swing Mode  #");  
     System.out.println("#0.Matikan AC  #");  
     System.out.println("#----------------#");  
     System.out.println("##################");  
     System.out.println();  
 }  
 }  
  •  Class Main

/**  
  * Pemanggilan fungsi sesuai dengan pilihan user.  
  *  
  * @author (Atika Rizki Nurakhmah)  
  * @version (01/tugas4/2018)  
  */  
 import java.util.Scanner;   
 public class Main  
 {  
   public static void main(String args[])  
   {  
     {  
       Scanner scan= new Scanner(System.in);   
       int nyala, pilihan, mode, swing;  
       String mod;  
       System.out.println();  
       System.out.println("Sharp Air Conditioner");  
       System.out.println("Masukkan 0 untuk menyalakan AC");  
       RemoteAC remote = new RemoteAC ();  
       nyala = scan.nextInt();  
       while(true){  
       if (nyala==0){  
         remote.print();  
       while (true){  
       pilihan = scan.nextInt();  
       switch (pilihan)  
       {  
        case 0:  
        System.out.println("AC dimatikan.\nSharpp Air Conditioner\n");  
        System.exit(0);  
        break;  
        case 1:  
        remote.TempUp();  
        remote.print();  
        break;  
        case 2:  
        remote.TempDown();  
        remote.print();  
        break;  
        case 3:  
        System.out.println("1. Auto");  
        System.out.println("2. Fan");  
        System.out.println("3. Dry");  
        System.out.println("4. Cool");  
        System.out.println("5. Heat");  
        mode=scan.nextInt();  
        if(mode<1 || mode>5){  
          System.out.println("Mode yang Anda masukkan salah. Coba lagi.\n");  
         }  
        else{  
        mod= remote.getMode(mode);  
        }  
        remote.print();  
        break;  
        case 4:  
        remote.getSwing();  
        remote.print();  
        break;  
       }  
     }  
   }  
     else {  
     System.out.println("AC tidak menyala, coba lagi.");  
     nyala = scan.nextInt();  
       }  
     }  
   }  
 }  
 }  

 Cara Kerja Program:
Pertama, program akan meminta input angka 0 untuk menjalankan perintah selanjutnya. Angka 0 seakan seperti tombol untuk menyalakan remote AC. Jika yang diinputkan user bukan angka 0, maka program akan menampilkan peringatan dan kembali meminta input sampai angka yang diinputkan benar (angka 0). Setelah itu akan muncul display remote AC beserta opsi yang bisa dipilih user. User tinggal memilih opsi yang diinginkan dan mengikuti perintah yang muncul. Untuk opsi swing, user cukup memilih opsi swing mode tanpa harus menginputkan apa-apa.

Berikut Screenshot program setelah dicompile:

 1. Tampilan awal


Fungsi TempUp






Fungsi TempDown


 Fungsi getMode


 Fungsi getSwing




Saat Remote dimatikan




Nah, sekian tugas saya kali ini. Terima kasih dan sampai bertemu di ulasan selanjutnya :))))))))) .




Minggu, 16 September 2018

Tugas 3 PBO : TICKET MACHINE SEDERHANA


TUGAS 3 PEMROGRAMAN BERORIENTASI OBJEK 

MEMBUAT TICKET MACHINE SEDERHANA



Nama : Atika Rizki Nurakhmah
NRP : 05111740000015
Kelas : PBO - A

Tugas kali ini, saya diminta untuk membuat program Mesin Tiket Otomatis versi sederhananya.
Saya menggunakan 2 Class.
  1. Class TicketMachine
    Dalam class ini terdapat beberapa method. Di awal terdapat deklarasi variable, beserta nilainya. Berikut method yang saya gunakan:
    • public int getPrice()
      Digunakan untuk menyimpan dan menampilkan harga tiket yang diinputkan user.
    • public void insertMoney(int amount) 
      Digunakan untuk mendapatkan jumlah uang yang dimasukkan user.
    • public int getBalance()
      Digunakan untuk menyimpan dan menampilakan jumlah uang yang sudah dimasukkan user.
    • public void printTicket()
      Digunakan untuk mencetak tiket.
    • public int refundBalance()
      Digunakan untuk menghitung, menyimpan, dan menampilkan uang kembalian user.
  2. Class Main
    Dalam Class ini terdapat opsi-opsi yang dapat dipilih user.


Berikut adalah Source Code nya:
  1. Class TicketMachine
/**  
  * Write a description of class TicketMachine here.  
  *  
  * @author (Atika Rizki Nurakhmah / 05111740000015)  
  * @version (01.01/tugas3/2018)  
  */  
 public class TicketMachine  
 {  
  // 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 total amount of money collected by this machine.   
  private int total;   
  // The amount of refund  
  private int refund;  
  /**   
  * 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 cost)   
  {   
  price = cost;   
  balance = 0;   
  total = 0;   
  refund =0;  
  }   
  /**   
  * Return the price of a ticket.   
  */   
  public int getPrice()   
  {   
  return price;   
  }   
  /**   
  * Return the amount of money already inserted for the   
  * next ticket.   
  */   
  public int getBalance()   
  {   
   return balance;   
  }   
  /**   
  * Receive an amount of money in cents from a customer.   
  */   
  public void insertMoney(int amount)   
  {   
    //System.out.println("Masukkan jumlah uang Anda");  
    if(amount>0){  
   balance = balance + amount;   
  }   
   else{  
     System.out.println("Masukkan Uang ke Mesin");  
   }  
 }  
  /**   
  * Print a ticket.   
  * Update the total collected and   
  * reduce the balance to zero.   
  */   
  public void printTicket()   
  {   
    System.out.println("Uang anda Rp. "+balance+",-");  
     if(balance>=price){  
   total = total + balance;  
   refund=refundBalance();  
   if (refund==0){  
     System.out.println("Uang anda pas. Tidak ada kembalian.");  
   }  
     else{  
       System.out.println("Kembalian Anda Rp. "+refund+",-");  
     }  
     balance =0;  
   System.out.println();     
   System.out.println("#############################");   
   System.out.println("****** The BlueJ Train ******");  
   System.out.println("* Tanggal : 17 September 2018");  
   System.out.println("* 1 Ticket       *****");   
   System.out.println("* Rp." + price + ",-       ****");   
   System.out.println("#############################");   
   System.out.println();   
   System.out.println("Terima Kasih, Semoga Perjalanan Anda Menyenangkan!");  
   System.out.println();  
   System.exit(0);  
   }  
   else {  
     System.out.println("Silahkan Masukan Rp."+(price-balance)+",-");  
 }  
 }  
 public int refundBalance() {   
   int amountToRefund;   
   amountToRefund = balance-price;   
   balance = 0;   
   return amountToRefund;   
 }  
 }  


     2.  Class Main

 /**  
  * Write a description of class Main here.  
  *  
  * @author (Atika Rizki Nurakhmah / 05111740000015)  
  * @version (01/tugas3/2018)  
  */  
 import java.util.Scanner;   
  public class Main   
  {   
  public static void main(String args[])   
  {   
  Scanner scan= new Scanner(System.in);   
  int cost,menu;   
  System.out.println("SELAMAT DATANG DI THE BLUEJ TRAIN");  
  System.out.println("Masukkan harga tiket yang akan anda beli \n");   
  cost=scan.nextInt();   
  TicketMachine ticket=new TicketMachine(cost);  
  while(true){  
  System.out.println();   
  System.out.println("Silahkan pilih opsi (Program akan berhenti ketika Anda berhasil mencetak tiket)");  
  System.out.println("1. Cetak Harga");   
  System.out.println("2. Masukkan Uang");   
  System.out.println("3. Jumlah Uang yang Sudah Dimasukkan");   
  System.out.println("4. Cetak Tiket");   
  menu=scan.nextInt();   
  switch(menu)   
  {   
   case 1:   
   cost=ticket.getPrice();   
   System.out.println("Harga Tiket yang Anda beli Rp. "+cost+",-");   
   break;   
   case 2:   
   System.out.println("Masukkan jumlah uang Anda");  
   int money=scan.nextInt();   
   ticket.insertMoney(money);   
   break;   
   case 3:  
   System.out.println("Anda telah memasukkan uang sejumlah Rp."+ticket.getBalance()+",00");  
   break;  
   case 4:   
   ticket.printTicket();   
   break;   
  }   
  }   
  }   
 }

 Berikut tampilan hasilnya


Setelah dimasukkan jumlah uangnya, nilai balance dan refundnya berubah



Jika Source Code dicompile dan dijalankan, hasilnya menjadi :


Jika uang yang dimasukkan user kurang, tampilannya seperti ini

Nah, demikian tugas pbo ketiga saya. Saya pamit undur diri, sampai bertemu di tugas selanjutnya. Sekian dan Terima kasih :)))))))

Gambar Sederhana dengan BlueJ


TUGAS 2 PEMROGRAMAN BERORIENTASI OBJEK


Nama    : Atika Rizki Nurakhmah
Nrp       : 05111740000015
Kelas    : PBO -A



Kali ini saya mendapatkan tugas untuk membuat gambar sederhana menggunakan BlueJ. Setelah membaca berbagai sumber dan melihat tutorial di Youtube, akhirnya saya berhasil membuat sebuah gambar. (Ayeeee!).

Untuk membuat gambar sederhana versi saya, saya membuat 6 Class, yaitu :
  1.  Pic
  2. Canvas
  3. Rectangular
  4. Circle
  5. Triangle
  6. Square 
Class Rectangular, Circle, Triangle, dan Square berisi source code yang menghasilkan gambar bentuk dua dimensi (2D). Sedangkan Class Canvas berisi fungsi-fungsi yang digunakan untuk merangkai bentuk dua dimensi yang tadi dihasilkan dari berbagai Class. Class Pic digunakan untuk menyusun bentuk-bentuk tadi menjadi sebuah gambar. Intinya di Pic inilah kita berkreasi sesuai keinginan kita.

Berikut adalah Source Code nya
  1. Class Pic
    /**  
      * Tempat menyusun semua Class menjadi sebuah gambar  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.01/tugas2/2018)  
      */  
     public class Pic  
     {  
       private Circle bulan;  
       private Circle bulan1;  
       private Circle bintang1;  
       private Circle bintang2;  
       private Circle bintang3;  
       private Circle bintang4;  
       private Circle bintang5;  
       private Circle bintang6;  
       private Circle bintang7;  
       private Circle bintang8;  
       private Square rumah1;  
       private Square rumah2;  
       private Rectangular pintu;  
       private Rectangular pintu1;  
       private Square jendela1;  
       private Square jendela2;  
       private Square jendela3;  
       private Square jendela4;  
       private Square jendela5;  
       private Square jendela6;  
       private Triangle atap1;  
       private Triangle atap2;  
       private Circle pohon1;  
       private Circle pohon2;  
       private Circle pohon3;  
       private Rectangular batang;  
       private Rectangular rumput;  
       private Rectangular tanah;  
       private Triangle rumput1;  
       private Triangle rumput2;  
       private Triangle rumput3;  
       private Triangle rumput4;  
       private Triangle rumput5;  
       private Triangle rumput6;  
       private Triangle rumput7;  
       private Triangle rumput8;  
       private Rectangular jalan;  
       private Circle PeganganPintu1;  
       private Circle PeganganPintu2;  
       public Pic ()  
       {  
       }  
       public void draw ()  
       {  
        bulan = new Circle();  
        bulan.moveVertical(-100);  
        bulan.moveHorizontal(-60);  
        bulan.changeSize (80);  
        bulan.makeVisible();  
        bulan1 = new Circle ();  
        bulan1.moveVertical(-100);  
        bulan1.changeSize (80);  
        bulan1.moveHorizontal(-30);  
        bulan1.changeColor("black");  
        bulan1.makeVisible();  
        bintang1 = new Circle ();  
        bintang1.moveVertical(-100);  
        bintang1.changeColor("yellow");  
        bintang1.changeSize (15);  
        bintang1.moveHorizontal(100);  
        bintang1.makeVisible();  
        bintang2 = new Circle ();  
        bintang2.moveVertical(-100);  
        bintang2.changeColor("yellow");  
        bintang2.changeSize (10);  
        bintang2.moveHorizontal(250);  
        bintang2.makeVisible();  
        bintang3 = new Circle ();  
        bintang3.moveVertical(-100);  
        bintang3.changeColor("yellow");  
        bintang3.changeSize (15);  
        bintang3.moveHorizontal(400);  
        bintang3.makeVisible();  
        bintang4 = new Circle ();  
        bintang4.moveVertical(-60);  
        bintang4.changeColor("yellow");  
        bintang4.changeSize (10);  
        bintang4.moveHorizontal(175);  
        bintang4.makeVisible();  
        bintang5 = new Circle ();  
        bintang5.moveVertical(-60);  
        bintang5.changeColor("yellow");  
        bintang5.changeSize (15);  
        bintang5.moveHorizontal(275);  
        bintang5.makeVisible();  
        bintang6 = new Circle ();  
        bintang6.moveVertical(-50);  
        bintang6.changeColor("yellow");  
        bintang6.changeSize (10);  
        bintang6.moveHorizontal(425);  
        bintang6.makeVisible();  
        bintang7 = new Circle ();  
        bintang7.moveVertical(-40);  
        bintang7.changeColor("yellow");  
        bintang7.changeSize (15);  
        bintang7.moveHorizontal(100);  
        bintang7.makeVisible();  
        bintang8 = new Circle ();  
        bintang8.moveVertical(-40);  
        bintang8.changeColor("yellow");  
        bintang8.changeSize (10);  
        bintang8.moveHorizontal(350);  
        bintang8.makeVisible();  
        rumput = new Rectangular ();  
        rumput.changeColor("green");  
        rumput.moveVertical(400);  
        rumput.moveHorizontal(-100);  
        rumput.changeSize(600,50);  
        rumput.makeVisible();  
        rumah1 = new Square();  
        rumah1.changeColor("blue");  
        rumah1.moveVertical(250);  
        rumah1.moveHorizontal (-20);  
        rumah1.changeSize(200);  
        rumah1.makeVisible();  
        rumah2 = new Square();  
        rumah2.changeSize(120);  
        rumah2.changeColor("blue");  
        rumah2.moveVertical(330);  
        rumah2.moveHorizontal(175);  
        rumah2.makeVisible();  
        atap1 = new Triangle ();  
        atap1.changeColor("red");  
        atap1.changeSize(100,202);  
        atap1.moveVertical(240);  
        atap1.moveHorizontal(80);  
        atap1.makeVisible();  
        atap2 = new Triangle ();  
        atap2.changeColor("red");  
        atap2.changeSize(68,120);  
        atap2.moveVertical(353);  
        atap2.moveHorizontal(239);  
        atap2.makeVisible();  
        jendela1 = new Square();  
        jendela1.changeSize(40);  
        jendela1.moveVertical(270);  
        jendela1.makeVisible();  
        jendela2 = new Square();  
        jendela2.changeSize(40);  
        jendela2.moveVertical(270);  
        jendela2.moveHorizontal(60);  
        jendela2.makeVisible();  
        jendela3 = new Square();  
        jendela3.changeSize(40);  
        jendela3.moveVertical(270);  
        jendela3.moveHorizontal(120);  
        jendela3.makeVisible();  
        jendela4 = new Square();  
        jendela4.changeSize(40);  
        jendela4.moveVertical(350);  
        jendela4.moveHorizontal(10);  
        jendela4.makeVisible();  
        jendela5 = new Square();  
        jendela5.changeSize(40);  
        jendela5.moveVertical(350);  
        jendela5.moveHorizontal(110);  
        jendela5.makeVisible();  
        jendela6 = new Square();  
        jendela6.changeSize(40);  
        jendela6.moveVertical(340);  
        jendela6.moveHorizontal(220);  
        jendela6.makeVisible();  
        pintu = new Rectangular ();  
        pintu.changeSize(40,60);  
        pintu.changeColor ("pink");  
        pintu.moveHorizontal(60);  
        pintu.moveVertical(390);  
        pintu.makeVisible();  
        pintu1 = new Rectangular ();  
        pintu1.changeSize(40,60);  
        pintu1.changeColor ("pink");  
        pintu1.moveHorizontal(245);  
        pintu1.moveVertical(390);  
        pintu1.makeVisible();  
        batang = new Rectangular();  
        batang.changeColor("red");  
        batang.changeSize(30,200);  
        batang.moveHorizontal(365);  
        batang.moveVertical(200);  
        batang.makeVisible();  
        pohon1 = new Circle();  
        pohon1.moveHorizontal(310);  
        pohon1.moveVertical(100);  
        pohon1.changeColor("green");  
        pohon1.changeSize(80);  
        pohon1.makeVisible();  
        pohon2 = new Circle();  
        pohon2.moveHorizontal(370);  
        pohon2.moveVertical(100);  
        pohon2.changeColor("green");  
        pohon2.changeSize(80);  
        pohon2.makeVisible();  
        pohon3 = new Circle();  
        pohon3.moveHorizontal(340);  
        pohon3.moveVertical(50);  
        pohon3.changeColor("green");  
        pohon3.changeSize(80);  
        pohon3.makeVisible();  
        jalan=new Rectangular();  
        jalan.moveVertical(450);  
        jalan.moveHorizontal(-100);  
        jalan.changeColor("gray");  
        jalan.changeSize(600,50);  
        jalan.makeVisible();  
         rumput1=new Triangle();  
        rumput1.changeColor("green");  
        rumput1.changeSize(20,30);  
        rumput1.moveHorizontal(-87);  
        rumput1.moveVertical(470);  
        rumput1.makeVisible();  
        rumput2=new Triangle();  
        rumput2.changeColor("green");  
        rumput2.changeSize(50,30);  
        rumput2.moveHorizontal(-60);  
        rumput2.moveVertical(440);  
        rumput2.makeVisible();  
        rumput3=new Triangle();  
        rumput3.changeColor("green");  
        rumput3.changeSize(30,30);  
        rumput3.moveHorizontal(-35);  
        rumput3.moveVertical(460);  
        rumput3.makeVisible();  
        rumput4=new Triangle();  
        rumput4.moveHorizontal(325);  
        rumput4.moveVertical(450);  
        rumput4.changeColor("green");  
        rumput4.changeSize(40,60);  
        rumput4.makeVisible();  
        rumput5=new Triangle();  
        rumput5.moveHorizontal(365);  
        rumput5.moveVertical(430);  
        rumput5.changeColor("green");  
        rumput5.changeSize(60,40);  
        rumput5.makeVisible();  
        rumput6=new Triangle();  
        rumput6.moveHorizontal(400);  
        rumput6.moveVertical(460);  
        rumput6.changeColor("green");  
        rumput6.changeSize(30,60);  
        rumput6.makeVisible();  
        rumput7=new Triangle();  
        rumput7.moveHorizontal(435);  
        rumput7.moveVertical(430);  
        rumput7.changeColor("green");  
        rumput7.changeSize(60,50);  
        rumput7.makeVisible();  
        rumput8=new Triangle();  
        rumput8.moveHorizontal(480);  
        rumput8.moveVertical(450);  
        rumput8.changeColor("green");  
        rumput8.changeSize(50,50);  
        rumput8.makeVisible();  
        PeganganPintu1 = new Circle();  
        PeganganPintu1.changeColor("black");  
        PeganganPintu1.changeSize(10);  
        PeganganPintu1.moveVertical(375);  
        PeganganPintu1.moveHorizontal(87);  
        PeganganPintu1.makeVisible();  
        PeganganPintu2 = new Circle();  
        PeganganPintu2.changeColor("black");  
        PeganganPintu2.changeSize(10);  
        PeganganPintu2.moveVertical(375);  
        PeganganPintu2.moveHorizontal(273);  
        PeganganPintu2.makeVisible();  
        }  
     }
     
  2. Class Canvas
     /**  
      * Berisi fungsi-fungsi umum untuk merangkai gambar  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.01/tugas2/2018)  
      */  
     import javax.swing.*;  
     import java.awt.*;  
     import java.util.List;  
     import java.util.*;  
     public class Canvas  
     {  
       private static Canvas canvasSingleton;  
       public static Canvas getCanvas()  
       {  
         if (canvasSingleton == null){  
           canvasSingleton = new Canvas("Make a Picture using BlueJ",  
           600, 600, Color.black);  
         }  
         canvasSingleton.setVisible(true);  
         return canvasSingleton;  
       }  
       private JFrame frame;  
       private CanvasPane canvas;  
       private Graphics2D graphic;  
       private Color backgroundColour;  
       private Image canvasImage;  
       private List<Object> objects;  
       private HashMap<Object, ShapeDescription> shapes;  
        private Canvas(String title, int width, int height, Color bgColour)   
       {   
        frame = new JFrame();   
        canvas = new CanvasPane();   
        frame.setContentPane(canvas);   
        frame.setTitle(title);   
        canvas.setPreferredSize(new Dimension(width, height));   
        backgroundColour = bgColour;   
        frame.pack();   
        objects = new ArrayList<Object>();   
        shapes = new HashMap<Object, ShapeDescription>();   
       }   
       public void setVisible(boolean visible)   
       {   
        if(graphic == null) {   
         // first time: instantiate the offscreen image and fill it with   
         // the background colour   
         Dimension size = canvas.getSize();   
         canvasImage = canvas.createImage(size.width, size.height);   
         graphic = (Graphics2D)canvasImage.getGraphics();   
         graphic.setColor(backgroundColour);   
         graphic.fillRect(0, 0, size.width, size.height);   
         graphic.setColor(Color.black);   
        }   
        frame.setVisible(visible);   
       }   
       public void draw(Object referenceObject, String color, Shape shape)   
       {   
        objects.remove(referenceObject); // just in case it was already there   
        objects.add(referenceObject);  // add at the end   
        shapes.put(referenceObject, new ShapeDescription(shape, color));   
        redraw();   
       }   
       public void erase(Object referenceObject)   
       {   
        objects.remove(referenceObject); // just in case it was already there   
        shapes.remove(referenceObject);   
        redraw();   
       }   
       public void setForegroundColor(String colorString)   
       {   
        if(colorString.equals("red"))   
         graphic.setColor(Color.red);   
        else if(colorString.equals("black"))   
         graphic.setColor(Color.black);   
        else if(colorString.equals("blue"))   
         graphic.setColor(Color.blue);   
        else if(colorString.equals("yellow"))   
         graphic.setColor(Color.yellow);   
        else if(colorString.equals("green"))   
         graphic.setColor(Color.green);   
        else if(colorString.equals("magenta"))   
         graphic.setColor(Color.magenta);   
        else if(colorString.equals("white"))   
         graphic.setColor(Color.white);   
        else if(colorString.equals("pink"))  
         graphic.setColor(Color.pink);  
        else if(colorString.equals("gray"))  
         graphic.setColor(Color.gray);  
        else   
         graphic.setColor(Color.black);   
       }   
       public void wait(int milliseconds)   
       {   
        try   
        {   
         Thread.sleep(milliseconds);   
        }    
        catch (Exception e)   
        {   
        }   
       }   
       private void redraw()   
       {   
        erase();   
        for(Iterator i=objects.iterator(); i.hasNext(); ) {   
         ((ShapeDescription)shapes.get(i.next())).draw(graphic);   
        }   
        canvas.repaint();   
       }   
       private void erase()   
       {   
        Color original = graphic.getColor();   
        graphic.setColor(backgroundColour);   
        Dimension size = canvas.getSize();   
        graphic.fill(new Rectangle(0, 0, size.width, size.height));   
        graphic.setColor(original);   
       }  
       private class CanvasPane extends JPanel   
       {   
        public void paint(Graphics g)   
        {   
         g.drawImage(canvasImage, 0, 0, null);   
        }   
       }   
       private class ShapeDescription   
       {   
        private Shape shape;   
        private String colorString;   
        public ShapeDescription(Shape shape, String color)   
        {   
         this.shape = shape;   
         colorString = color;   
        }   
        public void draw(Graphics2D graphic)   
        {   
         setForegroundColor(colorString);   
         graphic.fill(shape);   
        }   
       }   
     } 
     
  3. Class Rectangular
     /**  
      * Class untuk membuat bentuk Persegi Panjang beserta fungsi untuk menggeser, merubah warna dan ukuran  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.03/tugas2/2018)  
      */  
     import java.awt.*;  
     public class Rectangular  
     {  
       private int panjang;  
       private int lebar;  
       private int xPosition;  
       private int yPosition;  
       private String color;  
       private boolean isVisible;  
       /**  
        * Constructor for objects of class Rectangular  
        */  
       public Rectangular()  
       {  
         panjang = 300;  
         lebar = 150;  
         xPosition = 100;  
         yPosition = 100;  
         color = "yellow";  
         isVisible =false;  
       }  
       public void makeVisible()  
       {  
         isVisible = true;  
         draw();  
       }  
       public void makeInvisible(){  
         erase ();  
         isVisible = false;  
       }  
       public void moveRight ()  
       {  
         moveHorizontal(20);  
       }  
       public void moveLeft(){  
         moveHorizontal(-20);  
       }  
       public void moveUp()   
       {   
        moveVertical(-20);   
       }  
       public void moveDown()   
       {   
        moveVertical(20);   
       }   
       public void moveHorizontal(int distance)   
       {   
        erase();   
        xPosition += distance;   
        draw();   
       }  
       public void moveVertical(int distance)   
       {   
        erase();   
        yPosition += distance;   
        draw();   
       }   
       public void slowMoveHorizontal(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         xPosition += delta;   
         draw();   
        }   
       }  
       public void slowMoveVertical(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         yPosition += delta;   
         draw();   
        }   
       }  
        public void changeSize(int newPanjang, int newLebar)   
       {   
        erase();   
        panjang = newPanjang;  
        lebar=newLebar;  
        draw();   
       }   
       public void changeColor(String newColor)   
       {   
        color = newColor;   
        draw();   
       }   
       private void draw()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.draw(this, color, new Rectangle.Double(xPosition, yPosition,    
           panjang, lebar));   
         canvas.wait(10);   
        }   
       }   
       private void erase()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.erase(this);   
        }   
       }   
     } 
     
  4. Class Circle
     /**  
      * Class untuk membuat bentuk Lingkaran beserta fungsi untuk menggeser, merubah warna dan ukuran  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.04/tugas2/2018)  
      */  
     import java.awt.*;  
     import java.awt.geom.*;  
     public class Circle  
     {  
       private int diameter;  
       private int xPosition;  
       private int yPosition;  
       private String color;  
       private boolean isVisible;  
       /**  
        * Constructor for objects of class Circle  
        */  
       public Circle()  
       {  
         diameter = 50;  
         xPosition = 100;  
         yPosition = 140;  
         color = "red";  
         isVisible = false;  
       }  
       public void makeVisible()  
       {  
         isVisible = true;  
         draw();  
       }  
       public void makeInvisible(){  
         erase ();  
         isVisible = false;  
       }  
       public void moveRight ()  
       {  
         moveHorizontal(20);  
       }  
       public void moveLeft(){  
         moveHorizontal(-20);  
       }  
       public void moveUp()   
       {   
        moveVertical(-20);   
       }  
       public void moveDown()   
       {   
        moveVertical(20);   
       }   
       public void moveHorizontal(int distance)   
       {   
        erase();   
        xPosition += distance;   
        draw();   
       }  
       public void moveVertical(int distance)   
       {   
        erase();   
        yPosition += distance;   
        draw();   
       }   
       public void slowMoveHorizontal(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         xPosition += delta;   
         draw();   
        }   
       }  
       public void slowMoveVertical(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         yPosition += delta;   
         draw();   
        }   
       }  
        public void changeSize(int newDiameter)   
       {   
        erase();   
        diameter = newDiameter;   
        draw();   
       }   
       /**   
       * Change the color. Valid colors are "red", "yellow", "blue", "green",   
       * "magenta" and "black".   
       */   
       public void changeColor(String newColor)   
       {   
        color = newColor;   
        draw();   
       }   
       private void draw()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,    
           diameter, diameter));   
         canvas.wait(10);   
        }   
       }   
       private void erase()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.erase(this);   
        }   
       }   
     } 
     
  5. Class Triangle
    /**  
      * Class untuk membuat bentuk Segitiga beserta fungsi untuk menggeser, merubah warna dan ukuran  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.05/tugas2/2018)  
      */  
     import java.awt.*;   
      public class Triangle   
      {   
       private int height;   
       private int width;   
       private int xPosition;   
       private int yPosition;   
       private String color;   
       private boolean isVisible;   
       /**   
       * Create a new triangle at default position with default color.   
       */   
       public Triangle()   
       {   
        height = 100;   
        width = 200;   
        xPosition = 100;   
        yPosition = 10;   
        color = "blue";   
        isVisible = false;   
       }   
       /**   
       * Make this triangle visible. If it was already visible, do nothing.   
       */   
       public void makeVisible()   
       {   
        isVisible = true;   
        draw();   
       }   
       /**   
       * Make this triangle invisible. If it was already invisible, do nothing.   
       */   
       public void makeInvisible()   
       {   
        erase();   
        isVisible = false;   
       }   
       /**   
       * Move the triangle a few pixels to the right.   
       */   
       public void moveRight()   
       {   
        moveHorizontal(20);   
       }   
       /**   
       * Move the triangle a few pixels to the left.   
       */   
       public void moveLeft()   
       {   
        moveHorizontal(-20);   
       }   
       /**   
       * Move the triangle a few pixels up.   
       */   
       public void moveUp()   
       {   
        moveVertical(-20);   
       }   
       /**   
       * Move the triangle a few pixels down.   
       */   
       public void moveDown()   
       {   
        moveVertical(20);   
       }   
       /**   
       * Move the triangle horizontally by 'distance' pixels.   
       */   
       public void moveHorizontal(int distance)   
       {   
        erase();   
        xPosition += distance;   
        draw();   
       }   
       /**   
       * Move the triangle vertically by 'distance' pixels.   
       */   
       public void moveVertical(int distance)   
       {   
        erase();   
        yPosition += distance;   
        draw();   
       }   
       /**   
       * Slowly move the triangle horizontally by 'distance' pixels.   
       */   
       public void slowMoveHorizontal(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         xPosition += delta;   
         draw();   
        }   
       }   
       /**   
       * Slowly move the triangle vertically by 'distance' pixels.   
       */   
       public void slowMoveVertical(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         yPosition += delta;   
         draw();   
        }   
       }   
       /**   
       * Change the size to the new size (in pixels). Size must be >= 0.   
       */   
       public void changeSize(int newHeight, int newWidth)   
       {   
        erase();   
        height = newHeight;   
        width = newWidth;   
        draw();   
       }   
       /**   
       * Change the color. Valid colors are "red", "yellow", "blue", "green",   
       * "magenta" and "black".   
       */   
       public void changeColor(String newColor)   
       {   
        color = newColor;   
        draw();   
       }   
       /*   
       * Draw the triangle with current specifications on screen.   
       */   
       private void draw()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };   
         int[] ypoints = { yPosition, yPosition + height, yPosition + height };   
         canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));   
         canvas.wait(10);   
        }   
       }   
       /*   
       * Erase the triangle on screen.   
       */   
       private void erase()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.erase(this);   
        }   
       }   
      } 
     
  6. Class Rectangular
    /**  
      * Class untuk membuat bentuk Persegi beserta fungsi untuk menggeser, merubah warna dan ukuran  
      *  
      * @author (Atika Rizki Nurakhmah / 05111740000015)  
      * @version (02.06/tugas2/2018)  
      */  
     import java.awt.*;  
     public class Square  
     {  
       // instance variables - replace the example below with your own  
       private int size;  
       private int xPosition;  
       private int yPosition;  
       private String color;  
       private boolean isVisible;  
       /**  
        * Constructor for objects of class Square  
        */  
       public Square()  
       {  
         size = 100;  
         xPosition = 100;  
         yPosition = 100;  
         color = "yellow";  
         isVisible =false;  
       }  
       public void makeVisible()  
       {  
         isVisible = true;  
         draw();  
       }  
       public void makeInvisible(){  
         erase ();  
         isVisible = false;  
       }  
       public void moveRight ()  
       {  
         moveHorizontal(20);  
       }  
       public void moveLeft(){  
         moveHorizontal(-20);  
       }  
       public void moveUp()   
       {   
        moveVertical(-20);   
       }  
       public void moveDown()   
       {   
        moveVertical(20);   
       }   
       public void moveHorizontal(int distance)   
       {   
        erase();   
        xPosition += distance;   
        draw();   
       }  
       public void moveVertical(int distance)   
       {   
        erase();   
        yPosition += distance;   
        draw();   
       }   
       public void slowMoveHorizontal(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         xPosition += delta;   
         draw();   
        }   
       }  
       public void slowMoveVertical(int distance)   
       {   
        int delta;   
        if(distance < 0)    
        {   
         delta = -1;   
         distance = -distance;   
        }   
        else    
        {   
         delta = 1;   
        }   
        for(int i = 0; i < distance; i++)   
        {   
         yPosition += delta;   
         draw();   
        }   
       }  
        public void changeSize(int newSize)   
       {   
        erase();   
        size = newSize;   
        draw();   
       }   
       /**   
       * Change the color. Valid colors are "red", "yellow", "blue", "green",   
       * "magenta" and "black".   
       */   
       public void changeColor(String newColor)   
       {   
        color = newColor;   
        draw();   
       }   
       private void draw()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.draw(this, color, new Rectangle.Double(xPosition, yPosition,    
           size, size));   
         canvas.wait(10);   
        }   
       }   
       private void erase()   
       {   
        if(isVisible) {   
         Canvas canvas = Canvas.getCanvas();   
         canvas.erase(this);   
        }   
       }   
     }  
 Jika Source Code di atas dicompile dan dijalankan, maka hasilnya akan seperti ini :)



Nah, begitulah tugas saya. Sekian ulasan saya kali ini, saya pamit undur diri. Terima Kasih dan sampai bertemu di ulasan selanjutnya :)))))))))

    Senin, 10 September 2018

    TUGAS 2 Pemrograman Berorientasi Objek



    PROGRAM MENGHITUNG LUAS DAN KELILING BANGUN DUA DIMENSI


    Tugas 2 
    Mata Kuliah       : Pemrograman Berbasis Objek (PBO)
    Kelas                  : PBO A
    Nama                 : Atika Rizki Nurakhmah
    NRP                   : 05111740000015

    • Source Code Main 
    /**  
      *Program untuk menghitung Luas dan Keliling bangun 2D  
      *  
     * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/2018)  
      */  
     class MyMain  
     {  
       public static void main(String args[])  
       {  
         Circle aCircle;  
         aCircle = new Circle();  
         double area = aCircle.area();  
         double circumf = aCircle.circumference();  
         System.out.println("LUAS dan KELILING LINGKARAN");  
         System.out.println("Radius="+aCircle.r);  
         System.out.println("Luas="+area);  
         System.out.println("Keliling="+circumf);  
         System.out.println();  
         Square aSquare;  
         aSquare = new Square();  
         double luas=aSquare.luas();  
         double keliling=aSquare.keliling();  
         System.out.println("LUAS dan KELILING BUJURSANGKAR");  
         System.out.println("Sisi="+aSquare.x);  
         System.out.println("Luas="+luas);  
         System.out.println("Keliling="+keliling);  
         System.out.println();  
         Segitiga aSegitiga;  
         aSegitiga = new Segitiga();  
         double luassegi3=aSegitiga.luassegi3();  
         double kelilingsegi3=aSegitiga.kelilingsegi3();  
         System.out.println("LUAS dan KELILING SEGITIGA");  
         System.out.println("Sisi 1 (sebagai alas)="+aSegitiga.sisi1);  
         System.out.println("Sisi 2="+aSegitiga.sisi2);  
         System.out.println("Sisi 3="+aSegitiga.sisi3);  
         System.out.println("Tinggi="+aSegitiga.tinggi);  
         System.out.println("Luas="+luassegi3);  
         System.out.println("Keliling="+kelilingsegi3);  
         System.out.println();  
         PersegiPanjang aPersegiPanjang;  
         aPersegiPanjang = new PersegiPanjang();  
         double arearec=aPersegiPanjang.arearec();  
         double kelrec=aPersegiPanjang.kelrec();  
         System.out.println("LUAS dan KELILING PERSEGI PANJANG");  
         System.out.println("Panjang="+aPersegiPanjang.panjang);  
         System.out.println("Lebar="+aPersegiPanjang.lebar);  
         System.out.println("Luas="+arearec);  
         System.out.println("Keliling="+kelrec);  
         System.out.println();  
         BelahKetupat aBelahKetupat;  
         aBelahKetupat = new BelahKetupat();  
         double luasbk=aBelahKetupat.luasbk();  
         double kelbk=aBelahKetupat.kelbk();  
         System.out.println("LUAS dan KELILING BELAH KETUPAT");  
         System.out.println("Sisi="+aBelahKetupat.sisi);  
         System.out.println("Diagonal 1="+aBelahKetupat.diagonal1);  
         System.out.println("Diagonal 2="+aBelahKetupat.diagonal2);  
         System.out.println("Luas="+luasbk);  
         System.out.println("Keliling="+kelbk);  
         System.out.println();  
         JajaranGenjang aJajaranGenjang;  
         aJajaranGenjang = new JajaranGenjang();  
         double luasjar=aJajaranGenjang.areajar();  
         double keljar=aJajaranGenjang.keljar();  
         System.out.println("LUAS dan KELILING JAJARAN GENJANG");  
         System.out.println("Sisi 1 (sebagai alas)="+aJajaranGenjang.sisi1);  
         System.out.println("Sisi 2="+aJajaranGenjang.sisi2);  
         System.out.println("Tinggi="+aJajaranGenjang.tinggi);  
         System.out.println("Luas="+luasjar);  
         System.out.println("Keliling="+keljar);  
         System.out.println();  
       }  

    • Source Code Circle 
    /**  
      * Program untuk menghitung luas dan keliling lingkaran.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/01.2018)  
      */  
     public class Circle extends MyMain  
     {  
       public double x,y;  
       public double r;  
       public Circle (){  
         x = 10.0;  
         y = 20.0;  
         r= 5.0;  
       }  
       public double circumference()  
       {  
         return 2*3.14*r;  
       }  
       public double area(){  
         return 3.14*r*r;  
       }  
     }  

    • Source Code Square
     /**  
      * Program untuk menghitung luas dan keliling bujursangkar.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/02.2018)  
      */  
     public class Square extends MyMain  
     {  
       public double x;  
       public Square(){  
         x=10.0;  
       }  
       public double luas()  
       {  
         return x*x;  
       }  
       public double keliling()  
       {  
         return 4*x;  
     }  
     }  

    • Source Code Segitiga
     /**  
      * Program untuk menghitung luas dan keliling segitiga.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/03.2018)  
      */  
     public class Segitiga extends MyMain  
     {  
       public double sisi1;  
       public double sisi2;  
       public double sisi3;  
       public double tinggi;  
       public Segitiga(){  
         sisi1=10.0;  
         sisi2=15.0;  
         sisi3=20.0;  
         tinggi=25.0;  
       }  
       public double luassegi3()  
       {  
         return 0.5*sisi1*tinggi;  
       }  
       public double kelilingsegi3()  
       {  
         return sisi1+sisi2+sisi3;  
     }  
     }  

    • Source Code Persegi Panjang
     /**  
      * Program untuk menghitung keliling dan luas persegi panjang.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/04.2018)  
      */  
     public class PersegiPanjang extends MyMain  
     {  
       public double panjang;  
       public double lebar;  
       public PersegiPanjang()  
       {  
        panjang = 18.5;  
        lebar = 12.5;  
       }  
       public double arearec()  
       {  
         return panjang*lebar;  
       }  
       public double kelrec()  
       {  
         return 2*(panjang+lebar);  
     }  
     }  

    • Source Code Belah Ketupat
     /**  
      * Program untuk menghitung luas dan keliling belah ketupat.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/05.2018)  
      */  
     public class BelahKetupat extends MyMain  
     {  
       public double sisi;  
       public double diagonal1;  
       public double diagonal2;  
       public BelahKetupat ()  
       {  
         sisi= 10.0;  
         diagonal1= 6.0;  
         diagonal2= 8.0;  
       }  
       public double luasbk()  
       {  
         return 0.5*diagonal1*diagonal2;  
       }  
       public double kelbk()  
       {  
         return 4*sisi;  
       }  
     }  

    • Source Code Jajaran Genjang

     /**  
      * Program untuk menghitung luas dan keliling jajaran genjang.  
      *  
      * @author (Atika Rizki Nurakhmah)  
      * @version (0.2/06.2018)  
      */  
     public class JajaranGenjang extends MyMain  
     {  
       public double sisi1;  
       public double sisi2;  
       public double tinggi;  
       public JajaranGenjang()  
       {  
         sisi1=14.5;  
         sisi2=10.0;  
         tinggi=6.0;  
       }  
       public double areajar()  
       {  
         return sisi1*tinggi;  
       }  
       public double keljar()  
       {  
         return 2*(sisi1+sisi2);  
       }  
     }  



    Hasil jadi program :



    Minggu, 02 September 2018

    TUGAS 1 PBO Kelas A

    Tugas PBO 1

    Hari, tanggal  : Senin, 3 September 2018
    Nama             : Atika Rizki Nurakhmah
    NRP               : 05111740000015
    Kelas             : PBO A


    Source Code Program:

    /**  
      * Write a description of class hello here.  
      *  
      * @author (Atika Rizki)  
      * @version (0.1/2018)  
      */  
     public class hello  
     {  
       /**  
        * Constructor for objects of class hello  
        */  
       public hello()  
       {  
         System.out.println("Nama    : Atika Rizki Nurakhmah");  
         System.out.println("Kelas    : PBO A");  
         System.out.println("Alamat Rumah: Perumahan Bumi Madina Asri No 47");  
         System.out.println("Email    : atikarizki41@gmail.com");  
         System.out.println("Blog    : atikarizki99.blogspot.com");  
         System.out.println("No HP/WA  : 081286864922");  
         System.out.println("Twitter   : @atikarizki88");  
       }  
     } 
     


    Screenshot program :




    EAS PBO - Membuat Image Viewer

    Membuat Image Viewer (Versi update + editor)   Nama : Atika Rizki Nurakhmah Nrp    : 05111740000015 Kelas : PBO - A ...