Jumat, 28 September 2018

Membuat Jam Digital
Nama : Chaniyah Zulfa Mukhlishah
NRP   : 05111740000115
Kelas  : PBO-B
  
  Tugas rumah kali ini adalah membuat jam digital dengan bahasa java melalui BlueJ. Tampilan jam ini seperti stopwatch atau timer dimana kita dapat menghitung durasi kejadian yang kita inginkan. Awalnya, menit dan detik pada clock akan di set nol, seperti pada gambar :


Jika kita mengklik tombol 'start', maka timer akan berjalan menghitung kejadian yang diinginkan. Jika waktu timer berjalan dirasa cukup, kita bisa menghentikannya dengan mengklik tombol 'stop'. Lalu, tombol 'step' adalah jika kita ingin perhitungan manual. setiap kita menekan tombol 'step', maka terjadi penambahan '1' pada detik clock. Contoh ketika kita mengklik tombol 'start', lalu mengstopnya dengan klik 'stop', seperti gambar berikut :


Lalu, saya mencoba menampilkan(mendisplay) jam yang sudah saya set pada suatu class yang bernama Test Clock Display, seperti ini :


Nah, untuk menghasilkan semua itu, kita memerlukan 4 class, yaitu :
- Class Numb_Display = Memulai jam dari 0 dan memberi limit atau batasan maksimal jam bisa berjalan
- Class TestClockDisplay = Memberikan tes atau jam yang ingin ditampilkan
- Class Clock_Display = Menge.set time jam dan menit, juga mengatur agar bisa diincrement
- Class ClockGUI = Memberikan tampilan apik sehingga terdapat tombol-tombol untuk menjalankan perintah


Berikut, adalah hasil source code dari setiap class,
1.) Class Numb_Display

 /**  
  * Source Code Numb_Display  
  *  
  * @author (Chaniyah Zulfa)  
  * @version (7.0/180929)  
  */  
 public class Numb_Display    
  {    
   private int limit;    
   private int fix;    
   public Numb_Display(int Maksimal)    
   {    
   limit = Maksimal;    
   fix = 0;    
   }    
   public int Value_Now()    
   {    
   return fix;    
   }    
   public void increment()    
   {    
   fix = (fix + 1) % limit;    
   }    
   public String getDisplayValue()    
   {    
   if(fix < 10)    
   {    
    return "0" + fix;    
   }    
   else    
   {    
    return "" + fix;    
   }    
   }    
   public void setValue(int replacementValue)    
   {    
   if((replacementValue >= 0) && (replacementValue < limit))    
   {    
    fix = replacementValue;    
   }    
   }    
  }   

2.) Class TestClockDisplay


 /**  
  * Source Code TestClockDisplay  
  *  
  * @author (Chaniyah Zulfa)  
  * @version (7.0/180929)  
  */  
 public class TestClockDisplay    
  {    
   public TestClockDisplay()    
   {    
   }    
   public void test()    
   {    
   Clock_Display cl = new Clock_Display();    
   cl.setTime(22,37);    
   System.out.println(cl.getTime());    
   cl.setTime(5,59);    
   System.out.println(cl.getTime());  
   cl.setTime(14,00);    
   System.out.println(cl.getTime());  
   cl.setTime(00,17);    
   System.out.println(cl.getTime());  
   }    
  }    

3.) Class Clock_Display


 /**  
  * Source Code Clock_Display  
  *  
  * @author (Chaniyah Zulfa)  
  * @version (7.0/180929)  
  */  
 public class Clock_Display    
  {    
   private Numb_Display hour;    
   private Numb_Display minute;    
   private String displayString;   
   public Clock_Display()    
   {    
   hour = new Numb_Display(24);    
   minute = new Numb_Display(60);    
   updateDisplay();    
   }    
   public Clock_Display(int jam, int menit)    
   {    
   hour = new Numb_Display(24);    
   minute = new Numb_Display(60);    
   setTime(jam,menit);    
   }    
   public void timeTick()    
   {    
   minute.increment();    
   if(minute.Value_Now() == 0)    
   {    
    hour.increment();    
   }    
   updateDisplay();    
   }    
   public void setTime(int jam, int menit)    
   {    
   hour.setValue(jam);    
   minute.setValue(menit);    
   updateDisplay();    
   }    
   public String getTime()    
   {    
   return displayString;    
   }    
   private void updateDisplay()    
   {    
   displayString = hour.getDisplayValue() + ":" + minute.getDisplayValue();    
   }    
  }    

4.) Class ClockGUI


 /**  
  * Source Code ClockGUI   
  *  
  * @author (Chaniyah Zulfa)  
  * @version (7.0/180929)  
  */  
  import java.awt.*;    
  import java.awt.event.*;    
  import javax.swing.*;    
  import javax.swing.border.*;    
  public class ClockGUI    
  {    
   private JFrame frame;    
   private JLabel label;    
   private Clock_Display clock;    
   private boolean clockOn = false;    
   private TimerThread timerThread;    
   public void Clock()    
   {    
   makeFrame();    
   clock = new Clock_Display();    
   }    
   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)    
    {    
    }    
   }    
   }    
  }   

Thanks all :)

Kamis, 20 September 2018

Nama = Chaniyah Zulfa Mukhlishah
NRP  = 05111740000115
Kelas = PBO-B

Tugas rumah kali ini adalah membuat remote televisi dengan bahasa java melalui Blue J diawali dengan membuat 2 class seperti berikut:

Lalu, dilanjut membuat kodingan source code nya :
1.) Class Remot

 /**  
  * Membuat remote tv yang bisa mengatur channel dan volume  
  *  
  * @author (Chaniyah Zulfa Mukhlishah)  
  * @version (4.0/20180920)  
  */  
 //import java.util.Scanner;  
 public class Remot  
 {  
   private int channel, vol;  
   public Remot(int TotChannel, int TotVol)  
   {  
     channel = TotChannel;  
     vol = TotVol;  
   }  
   public int Channel_Now()  
   {  
     return channel;  
   }  
   public int Vol_Now()  
   {  
     return vol;  
   }  
   public int Plus_Channel()  
   {  
     if(channel>10 && channel<1) System.out.println("Maaf, channel tidak tersedia");  
     else channel++;  
     return channel;  
   }  
   public int Min_Channel()  
   {  
     if(channel>10 && channel<1) System.out.println("Maaf, channel tidak tersedia");  
     else channel--;  
     return channel;  
   }  
   public void Plus_Vol()  
   {  
      if(vol <21 && vol>0)   
     {  
       vol++;  
       System.out.println("volume telah bertambah, volume sekarang adalah = "+vol+"");  
     }  
     else if(vol<0) System.out.println("Volume tidak bisa kurang dari 0");  
     else //vol >20  
     System.out.println("awas kuping anda bisa pecah");  
   }  
   public void Min_Vol()  
   {  
     if(vol <21 && vol >0)  
     {  
       vol--;  
       System.out.println("volume telah dikecilkan, volume sekarang adalah = "+vol+" ");  
     }  
     else if(vol<0) System.out.println("Volume tidak bisa kurang dari 0");  
     else System.out.println("Suaranya sudah paling kecil ! Anda ga denger nanti "); //vol==0  
   }  
 }  

2.)Class Main

 /**  
  * membuat main remote tv  
  *  
  * @author (Chaniyah Zulfa Mukhlishah)  
  * @version (4.0/20180920)  
  */  
 import java.util.Scanner;  
 public class main  
 {  
   public static void main(String args[])  
   {  
     Scanner scan = new Scanner(System.in);  
     boolean yes;  
     int TotChannel,TotVol,choose;  
     System.out.println("--------------------------------------");  
     System.out.println("--------------------------------------");  
     System.out.println("**TELEVISION REMOTE MADE BY NENG CHAN**");  
     System.out.println("--------------------------------------");  
     System.out.println("--------------------------------------");  
     System.out.println("Pilih channel yang ingin ditonton sekarang!(max. channel)=10");  
     TotChannel = scan.nextInt();  
     System.out.println("OK kamu sudah memilih Channel!!");  
     System.out.println("Input volume yang diinginkan saat ini(max. volume =20)");  
     TotVol = scan.nextInt();  
     System.out.println();  
     System.out.println("******************************************************");  
     System.out.println("******************************************************");  
     Remot rem = new Remot(TotChannel,TotVol);  
     yes = true;  
     while(yes)  
     {  
       System.out.println("--Pilih menu yang diinginkan--");  
       System.out.println("1. Lihat Channel Sekarang");    
       System.out.println("2. Lihat Volume Sekarang");    
       System.out.println("3. Majukan Channel");    
       System.out.println("4. Mundurkan Channel");    
       System.out.println("5. Tambah Volume");   
       System.out.println("6. Kurangi Volume");   
       System.out.println("7. Turn off television !");  
       choose = scan.nextInt();  
       switch(choose)  
       {  
         case 1:  
         TotChannel = rem.Channel_Now();  
         if(TotChannel >0 && TotChannel <11)  
         {  
           if(TotChannel%2==0) System.out.println("WELCOME! Acara ini tentang ANIME");  
           else System.out.println("WELCOME! Acara kali ini adalah GOSIP ARTIS");  
           System.out.println("Anda berada pada channel : "+TotChannel);  
         }  
         else System.out.println("Channel cuma tersedia dari no 1 sampai no 10 aja :))");  
         System.out.println("---------------------------------------------------------");  
         break;  
         case 2:  
         TotVol = rem.Vol_Now();  
         if(TotVol >=0 && TotVol <21) System.out.println("Volume sekarang adalah = "+TotVol);  
         else System.out.println("Volume hanya tersedia 0-20");  
         System.out.println("---------------------------------------------------------");  
         break;  
         case 3:  
         TotChannel = rem.Plus_Channel();  
         if(TotChannel >0 && TotChannel <11)  
         {  
           System.out.println("------Setelah maju cannel, Anda berada pada channel : 
           "+TotChannel+"----");  
           if(TotChannel%2==0) System.out.println("WELCOME! Acara ini tentang ANIME");  
           else System.out.println("WELCOME! Acara kali ini adalah GOSIP ARTIS");  
         }  
         else System.out.println("Channel cuma tersedia dari no 1 sampai no 10 aja :))");  
         System.out.println("---------------------------------------------------------");  
         break;  
         case 4:  
         TotChannel = rem.Min_Channel();  
         if(TotChannel >0 && TotChannel <11)  
         {  
           System.out.println("------Setelah mundur channel, Anda berada pada channel : 
           "+TotChannel+"---");  
           if(TotChannel%2==0) System.out.println("WELCOME! Acara ini tentang ANIME");  
           else System.out.println("WELCOME! Acara kali ini adalah GOSIP ARTIS");  
         }  
         else System.out.println("Channel cuma tersedia dari no 1 sampai no 10 aja :))");  
         System.out.println("---------------------------------------------------------");  
         break;  
         case 5:  
         rem.Plus_Vol();  
         System.out.println("---------------------------------------------------------");  
         break;  
         case 6:  
         rem.Min_Vol();  
         System.out.println("---------------------------------------------------------");  
         break;  
         default:  
         System.out.println("TV telah mati, waktunya belajar!! Jangan nonton tv terus!");   
         System.out.println("---------------------------------------------------------");   
         yes = false;    
       }  
     }  
   }  
 }  

Lalu, saat kita run, hasilnya =
(Gambar diatas adalah awal kita mengatur berada di channel dan volume berapa)
--------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 1, menampilkan posisi chanel kita sekarang)
--------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 2, menampilkan volume kita sekarang)
--------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 3, memajukan channel dan untuk memberitahu channel apa pada nomor channel tsb. Untuk no channel ganjil berisi acara tentang GOSIP ARTIS,, untuk no channel genap berisi acara tentang ANIME,, channel hanya tersedia no 1-10)
--------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 4, memundurkan channel dan untuk memberitahu channel apa pada nomor channel tsb. Untuk no channel ganjil berisi acara tentang GOSIP ARTIS,, untuk no channel genap berisi acara tentang ANIME,, channel hanya tersedia no 1-10)
--------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 5, yaitu menambahkan volume. Volume hanya tersedia 1-20)
--------------------------------------------------------------------------------------------------------------------------


(Gambar diatas adalah saat kita memilih no 6, yaitu mengecilkan volume. Volume hanya tersedia 1-20)
-------------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih no 7, yaitu mematikan televisi)
-------------------------------------------------------------------------------------------------------------------------

Minggu, 16 September 2018

Nama = Chaniyah Zulfa Mukhlishah
NRP   = 05111740000115
Kelas  = PBO-B

Tugas kali ini adalah membuat ticket machine dengan bahasa java melalui BlueJ.
dengan diawali membuat 2 class seperi berikut =


Lalu, dilanjutkan membuat kodingan source code nya =

Terdapat 2 class =

    1.) Class TicketMachine

 /**  
  * Memesan tiket mesin dengan BlueJ  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (2018/09/17)  
  */  
 public class TicketMachine  
 {  
   public int saldo,harga,total;  
   public TicketMachine(int ticketCost)  
   {  
     harga = ticketCost;  
     saldo = 0;  
     total = 0;  
   }  
   public int HargaTicket()  
   {  
     System.out.println("Harga ticket = "+harga+" $");  
     System.out.println("------------------------------------");  
     return harga;  
   }  
   public int SaldoNow()  
   {  
     System.out.println("Saldo anda sekarang "+saldo+" $");  
     System.out.println("Kamu butuh "+(harga-saldo)+" $ lagi");  
     System.out.println("------------------------------------");  
     return saldo;  
   }  
   public void TopUpMoney(int inputan)  
   {  
     saldo+=inputan;  
     System.out.println(+inputan+ "$ telah ditambahkan");  
     System.out.println("------------------------------------");  
   }  
   public void FixTicket()  
   {  
     if(harga<=saldo)  
     {  
      System.out.println("The Plane Ticket go to Australia");  
      System.out.println(+harga+ "$");  
      System.out.println("Trimakasih telah memesan tiket!");  
      total+=saldo; //update total  
      saldo=0; //reset saldo  
     }  
     else  
     {  
       System.out.println("Maaf, anda tidak bisa memesan tiket");  
       System.out.println("Tambahkan saldo sebanyak "+(harga-saldo)+" $");  
       System.out.println("------------------------------------");  
     }  
   }  
 }  

2.) Class main

 /**  
  * Write a description of class TicketMachine here.  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (2018/09/17)  
  */  
 import java.util.Scanner;  
 public class main  
 {  
   public static void main(String args[])  
   {  
    Scanner scan= new Scanner(System.in);  
    int choose,saldo,harga;  
    System.out.print("Harga tiket yang dibeli=");  
    harga = scan.nextInt();  
    TicketMachine ticket = new TicketMachine(harga);  
    saldo = ticket.saldo;  
    boolean yes = true;  
    while(yes)  
    {  
      System.out.println("Pilih menu dibawah ini");   
      System.out.print("1.HargaTicket \n");  
      System.out.print("2.Jumlah Saldo tersedia \n");  
      System.out.print("3.Inputkan Uang / Top up \n");  
      System.out.print("4.Print ticket \n");  
      System.out.print("5.Exit \n");  
      choose = scan.nextInt();  
      switch(choose)  
      {  
        case 1:  
         harga = ticket.HargaTicket();  
         break;  
        case 2:  
         ticket.SaldoNow();  
         break;  
        case 3:  
         System.out.print("Saldo yang ingin di tambah sebesar = ");  
         int input = scan.nextInt();  
         ticket.TopUpMoney (input);  
         break;  
        case 4:  
         ticket.FixTicket();  
         break;  
        case 5:  
         yes = false;  
         break;  
      }  
    }  
   }  
 }  

Setelah itu, kita run , maka hasilnya sebagai berikut =

(Gambar diatas adalah saat kita memilih menu no.1) yaitu menampilkan harga tiket yang ingin dibeli.
------------------------------------------------------------------------------------------------------------------------
                                  

(Gambar diatas adalah saat kita memilih menu no 3)yaitu uang yang akan kita inputkan(top up).
-----------------------------------------------------------------------------------------------------------------------



(Gambar diatas adalah saat kita memilih menu no.2)yaitu menampilkan sisa saldo saat ini dan saldo yang dibutuhkan untuk memenuhi harga pembelian tiket.
-----------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih menu no.4) jika saldo belum mencukupi, maka tiket tidak bisa dipesan.
-----------------------------------------------------------------------------------------------------------------------

(Gambar diatas adalah saat kita memilih menu no.4 dan 5) yaitu ketika saldo memenuhi, maka tiket berhasil dipesan, lalu 5 adalah untuk exit dari menu.
Nama : Chaniyah Zulfa M.
NRP : 05111740000115
Kelas: PBO-B

PR kali ini adalah menggambar pemandangan menggunakan BlueJ dengan melibatkan bangun 2 dimensi didalamnya seperti persegi, lingkaran, dan segitiga.

awalnya saya membuat kelas-kelas sebagai berikut


berikut adalah ulasan setiap class :


1.ini adalah class canvas

Canvas sebagai kertas atau media untuk menggambar

 import javax.swing.*;    
  import java.awt.*;    
  import java.util.List;    
  import java.util.*;    
  /**    
  * Membuat canvas   
  *    
  * @author (Chaniyah Zulfa Mukhlishah)    
  *    
  * @version (3.1/20180916)    
  */    
  public class Canvas    
  {    
   // Note: The implementation of this class (specifically the handling of    
   // shape identity and colors) is slightly more complex than necessary. This    
   // is done on purpose to keep the interface and instance fields of the    
   // shape objects in this project clean and simple for educational purposes.    
   private static Canvas canvasSingleton;    
   /**    
   * Factory method to get the canvas singleton object.    
   */    
   public static Canvas getCanvas()    
   {    
   if(canvasSingleton == null) {    
    canvasSingleton = new Canvas("BlueJ Shapes Demo", 1000, 800, Color.white);    
   }    
   canvasSingleton.setVisible(true);    
   return canvasSingleton;    
   }    
   // ----- instance part -----    
   private JFrame frame;    
   private CanvasPane canvas;    
   private Graphics2D graphic;    
   private Color backgroundColour;    
   private Image canvasImage;    
   private List objects;    
   private HashMap shapes;    
   /**    
   * Create a Canvas.    
   * @param title title to appear in Canvas Frame    
   * @param width the desired width for the canvas    
   * @param height the desired height for the canvas    
   * @param bgClour the desired background colour of the canvas    
   */    
   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();    
   shapes = new HashMap();    
   }    
   /**    
   * Set the canvas visibility and brings canvas to the front of screen    
   * when made visible. This method can also be used to bring an already    
   * visible canvas to the front of other windows.    
   * @param visible boolean value representing the desired visibility of    
   * the canvas (true or false)    
   */    
   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);    
   }    
   /**    
   * Draw a given shape onto the canvas.    
   * @param referenceObject an object to define identity for this shape    
   * @param color  the color of the shape    
   * @param shape  the shape object to be drawn on the canvas    
   */    
   // Note: this is a slightly backwards way of maintaining the shape    
   // objects. It is carefully designed to keep the visible shape interfaces    
   // in this project clean and simple for educational purposes.    
   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();    
   }    
   /**    
   * Erase a given shape's from the screen.    
   * @param referenceObject the shape object to be erased    
   */    
   public void erase(Object referenceObject)    
   {    
   objects.remove(referenceObject); // just in case it was already there    
   shapes.remove(referenceObject);    
   redraw();    
   }    
   /**    
   * Set the foreground colour of the Canvas.    
   * @param newColour the new colour for the foreground of the Canvas    
   */    
   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("light brown"))    
    graphic.setColor(new Color(153,102,0));    
   else if(colorString.equals("brown"))    
    graphic.setColor(new Color(102,51,0));    
   else if(colorString.equals("brown"))    
    graphic.setColor(new Color(190,190,190));    
   else if(colorString.equals("light blue"))    
    graphic.setColor(new Color(0,191,255));    
   else    
    graphic.setColor(Color.black);    
   }    
   /**    
   * Wait for a specified number of milliseconds before finishing.    
   * This provides an easy way to specify a small delay which can be    
   * used when producing animations.    
   * @param milliseconds the number    
   */    
   public void wait(int milliseconds)    
   {    
   try    
   {    
    Thread.sleep(milliseconds);    
   }    
   catch (Exception e)    
   {    
    // ignoring exception at the moment    
   }    
   }    
   /**    
   * Redraw ell shapes currently on the Canvas.    
   */    
   private void redraw()    
   {    
   erase();    
   for(Iterator i=objects.iterator(); i.hasNext(); ) {    
    ((ShapeDescription)shapes.get(i.next())).draw(graphic);    
   }    
   canvas.repaint();    
   }    
   /**    
   * Erase the whole canvas. (Does not 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);    
   }    
   /************************************************************************    
   * Inner class CanvasPane - the actual canvas component contained in the    
   * Canvas frame. This is essentially a JPanel with added capability to    
   * refresh the image drawn on it.    
   */    
   private class CanvasPane extends JPanel    
   {    
   public void paint(Graphics g)    
   {    
    g.drawImage(canvasImage, 0, 0, null);    
   }    
   }    
   /************************************************************************    
   * Inner class CanvasPane - the actual canvas component contained in the    
   * Canvas frame. This is essentially a JPanel with added capability to    
   * refresh the image drawn on it.    
   */    
   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);    
   }    
   }    
  }   
2.ini adalah class Circle

 import java.awt.*;   
 import java.awt.geom.*;   
  /**   
  * A circle that can be manipulated and that draws itself on a canvas.   
  *  
  * @author (Chaniyah Zulfa Mukhlishah)    
  * @version (3.1/20180916)   
  */  
  public class Circle   
  {   
   private int diameter;   
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   /**   
   * Create a new circle at default position with default color.   
   */   
   public Circle()   
   {   
    diameter = 30;   
    xPosition = 0;   
    yPosition = 0;   
    color = "blue";   
    isVisible = false;   
   }   
   /**   
   * Make this circle visible. If it was already visible, do nothing.   
   */   
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   /**   
   * Make this circle invisible. If it was already invisible, do nothing.   
   */   
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   /**   
   * Move the circle a few pixels to the right.   
   */   
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   /**   
   * Move the circle a few pixels to the left.   
   */   
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   /**   
   * Move the circle a few pixels up.   
   */   
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   /**   
   * Move the circle a few pixels down.   
   */   
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   /**   
   * Move the circle horizontally by 'distance' pixels.   
   */   
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   /**   
   * Move the circle vertically by 'distance' pixels.   
   */   
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }   
   /**   
   * Slowly move the circle 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 circle 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 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();   
   }   
   /**   
   * Draw the circle with current specifications on screen.   
   */   
   private void draw()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition,    
                diameter, diameter));   
     canvas.wait(10);   
    }   
   }   
   /**   
   * Erase the circle on screen.   
   */   
   private void erase()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.erase(this);   
    }   
   }   
  }   
3.ini adalah class Triangle

 import java.awt.*;   
  /**   
  * A triangle that can be manipulated and that draws itself on a canvas.   
  *    
  * @author (Chaniyah Zulfa)   
  * @version (3.1/20180916)   
  */   
  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 = 30;   
    width = 40;   
    xPosition = 0;   
    yPosition = 0;   
    color = "green";   
    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);   
    }   
   }   
  }   
4.ini adalah class Square

 import java.awt.*;   
  /**   
  * A square that can be manipulated and that draws itself on a canvas.   
  *    
  * @author (Chaniyah Zulfa Mukhlishah)    
  * @version (3.1/20180916)  
  */   
  public class Square   
  {   
   private int size;   
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   /**   
   * Create a new square at default position with default color.   
   */   
   public Square()   
   {   
    size = 30;   
    xPosition = 0;   
    yPosition = 0;   
    color = "red";   
    isVisible = false;   
   }   
   /**   
   * Make this square visible. If it was already visible, do nothing.   
   */   
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   /**   
   * Make this square invisible. If it was already invisible, do nothing.   
   */   
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   /**   
   * Move the square a few pixels to the right.   
   */   
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   /**   
   * Move the square a few pixels to the left.   
   */   
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   /**   
   * Move the square a few pixels up.   
   */   
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   /**   
   * Move the square a few pixels down.   
   */   
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   /**   
   * Move the square horizontally by 'distance' pixels.   
   */   
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   /**   
   * Move the square vertically by 'distance' pixels.   
   */   
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }   
   /**   
   * Slowly move the square 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 square 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 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();   
   }   
   /**   
   * Draw the square with current specifications on screen.   
   */   
   private void draw()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.draw(this, color,   
        new Rectangle(xPosition, yPosition, size, size));   
     canvas.wait(10);   
    }   
   }   
   /**   
   * Erase the square on screen.   
   */   
   private void erase()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.erase(this);   
    }   
   }   
  }   
5.ini adalah class Rectangles

 import java.awt.*;  
 /**  
  * A rectangle that can be manipulated and that draws itself on a canvas.   
  *    
  * @author (Chaniyah Zulfa Mukhlishah)    
  * @version (3.1/20180916)  
  */  
 public class Rectangles  
 {  
   private int aside;  
   private int bside;  
   private int centerx;  
   private int centery;  
   private boolean isVisible;  
   private String color;  
   public Rectangles()  
   {  
     aside = 100;  
     bside = 50;  
     centerx = 200;  
     centery = 200;  
     isVisible = true;  
     color = "magenta";  
     draw();  
   }  
   public void SetSide(int l, int s)  
   {  
     aside = l;  
     bside = s;  
   }  
   public void SetCenter(int x, int y)  
   {  
     centerx = x;  
     centery = y;  
   }  
   public double Circumference()  
   {  
     return 2*aside + 2*bside;  
   }  
   public double Area()  
   {  
     return aside * bside;  
   }  
   public void moveTo(int x, int y)  
   {  
     erase();  
     centerx = x;  
     centery = y;  
     draw();  
   }  
   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();  
     centerx += distance;  
     draw();  
   }  
   public void moveVertical(int distance)  
   {  
     erase();  
     centery += 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++)  
     {  
       centerx += 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++)  
     {  
       centery += delta;  
       draw();  
     }  
   }  
   public void changeSize(int newASide, int newBSide)  
   {  
     erase();  
     aside = newASide;  
     bside = newBSide;  
     draw();  
   }  
   public void changeColor(String newColor)  
   {  
     color = newColor;  
     draw();  
   }  
   private void draw()  
   {  
     if(isVisible)  
     {  
       Canvas canvasobj = Canvas.getCanvas();  
       canvasobj.draw(this, color, new Rectangle(centerx, centery, aside, bside));  
       canvasobj.wait(10);  
     }  
   }  
   private void erase()  
   {  
     if(isVisible)  
     {  
       Canvas canvasobj = Canvas.getCanvas();  
       canvasobj.erase(this);  
     }  
   }  
 }  
6.ini adalah class picture

picture untuk menampilkan seluruh gambar yang teah kita buat

  /**   
  * I draw my picture here.  
  *   
  * @author (Chaniyah Zulfa Mukhlishah)    
  * @version (3.1/20180916)  
  */   
 public class picture  
 {  
  private Circle sun,rock1,rock2,rock3,c1,c2,c3;  
  private Triangle mountain1,mountain2,tree1,tree2,tree3,street;  
  private Square s1,s2,s3;  
  private Rectangles stem,background,street1,street2,street3;  
  public picture()  
  {  
  }  
  public void draw()  
  {  
    sun = new Circle();  
    sun.changeSize(100);   
    sun.moveHorizontal(240);   
    sun.moveVertical(100);   
    sun.changeColor("yellow");   
    sun.makeVisible();   
    rock1 = new Circle();  
    rock1.changeSize(300);   
    rock1.moveHorizontal(380);   
    rock1.moveVertical(360);   
    rock1.changeColor("black");   
    rock1.makeVisible();  
    rock2 = new Circle();  
    rock2.changeSize(300);   
    rock2.moveHorizontal(460);   
    rock2.moveVertical(260);   
    rock2.changeColor("black");   
    rock2.makeVisible();  
    rock3 = new Circle();  
    rock3.changeSize(100);   
    rock3.moveHorizontal(540);   
    rock3.moveVertical(220);   
    rock3.changeColor("black");   
    rock3.makeVisible();  
    c1 = new Circle();  
    c1.changeSize(20);   
    c1.moveHorizontal(7);   
    c1.moveVertical(28);   
    c1.changeColor("black");   
    c1.makeVisible();  
    c2 = new Circle();  
    c2.changeSize(20);   
    c2.moveHorizontal(222);   
    c2.moveVertical(60);   
    c2.changeColor("black");   
    c2.makeVisible();  
    c3 = new Circle();  
    c3.changeSize(20);   
    c3.moveHorizontal(480);   
    c3.moveVertical(45);   
    c3.changeColor("black");   
    c3.makeVisible();  
    mountain1 = new Triangle();   
    mountain1.changeSize(200, 400);   
    mountain1.moveHorizontal(140);   
    mountain1.moveVertical(30);   
    mountain1.changeColor("red");   
    mountain1.makeVisible();  
    mountain2 = new Triangle();   
    mountain2.changeSize(200,400);   
    mountain2.moveHorizontal(420);   
    mountain2.moveVertical(30);   
    mountain2.changeColor("red");   
    mountain2.makeVisible();  
    tree1 = new Triangle();   
    tree1.changeSize(100, 100);   
    tree1.moveHorizontal(60);   
    tree1.moveVertical(280);   
    tree1.changeColor("brown");   
    tree1.makeVisible();  
    tree2 = new Triangle();   
    tree2.changeSize(100, 100);   
    tree2.moveHorizontal(60);   
    tree2.moveVertical(240);   
    tree2.changeColor("brown");   
    tree2.makeVisible();  
    tree3 = new Triangle();   
    tree3.changeSize(100, 100);   
    tree3.moveHorizontal(60);   
    tree3.moveVertical(200);   
    tree3.changeColor("brown");   
    tree3.makeVisible();  
    street = new Triangle();   
    street.changeSize(330, 300);   
    street.moveHorizontal(280);   
    street.moveVertical(220);   
    street.changeColor("black");   
    street.makeVisible();  
    s1 = new Square();   
    s1.changeSize(20);   
    s1.moveHorizontal(20);   
    s1.moveVertical(20);   
    s1.changeColor("black");   
    s1.makeVisible();  
    s2 = new Square();   
    s2.changeSize(20);   
    s2.moveHorizontal(230);   
    s2.moveVertical(50);   
    s2.changeColor("black");   
    s2.makeVisible();  
    s3 = new Square();   
    s3.changeSize(20);   
    s3.moveHorizontal(490);   
    s3.moveVertical(40);   
    s3.changeColor("black");   
    s3.makeVisible();  
    stem= new Rectangles();   
    stem.changeSize(40,150);   
    stem.moveHorizontal(100);   
    stem.moveVertical(600);   
    stem.changeColor("brown");   
    stem.makeVisible();  
    background = new Rectangles();   
    background.changeSize(400,300);   
    background.moveHorizontal(20);   
    background.moveVertical(20);   
    background.changeColor("magenta");   
    background.makeVisible();  
    street1 = new Rectangles();   
    street1.changeSize(20,20);   
    street1.moveHorizontal(300);   
    street1.moveVertical(250);   
    street1.changeColor("white");   
    street1.makeVisible();  
    street2 = new Rectangles();   
    street2.changeSize(20,20);   
    street2.moveHorizontal(300);   
    street2.moveVertical(260);   
    street2.changeColor("white");   
    street2.makeVisible();  
    street3 = new Rectangles();   
    street3.changeSize(20,20);   
    street3.moveHorizontal(300);   
    street3.moveVertical(270);   
    street3.changeColor("white");   
    street3.makeVisible();  
 }  
 }  
hasil gambaran saya adalah sebagai berikut :

Minggu, 09 September 2018

Nama : Chaniyah Zulfa Mukhlishah

NRP : 05111740000115

Kelas : PBO-B

Menghitung Luas Permukaan dan Volume Kubus, Balok, Tabung, dan Bola


Main
 /**  
  * Latihan implementasi bangun 3D Kubus,Balok,Tbaung,Bola  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (1.0/100918)  
  */  
 class Main  
 {  
   public static void main(String args[])  
   {  
     Kubus Kub;  
     Kub = new Kubus();  
     Kub.s = 9.0;  
     double l_permK = Kub.lp_Kubus();  
     double volK = Kub.vol_Kubus();  
     System.out.println("------------------------------");  
     System.out.println("Luas Permukaan dan Volume KUBUS");  
     System.out.println("Sisi = "+Kub.s);  
     System.out.println("Luas Permukaan kubus = "+l_permK);  
     System.out.println("Volume kubus = "+volK);  
     System.out.println( );  
     Balok Bal;  
     Bal = new Balok();  
     Bal.p = 10.0;  
     Bal.l = 7.5;  
     Bal.t = 4.0;  
     double l_permB = Bal.lp_Balok();  
     double volB = Bal.vol_Balok();  
     System.out.println("------------------------------");  
     System.out.println("Luas Permukaan dan Volume BALOK");  
     System.out.println("Panjang = "+Bal.p);  
     System.out.println("Lebar = "+Bal.l);  
     System.out.println("Tinggi = "+Bal.t);  
     System.out.println("Luas Permukaan balok = "+l_permB);  
     System.out.println("Volume balok = "+volB);  
     System.out.println( );  
     Tabung Tab;  
     Tab = new Tabung();  
     Tab.r = 6.0;  
     Tab.t = 8.5;  
     double l_permT = Tab.lp_Tabung();  
     double volT = Tab.vol_Tabung();  
     System.out.println("------------------------------");  
     System.out.println("Luas Permukaan dan Volume TABUNG");  
     System.out.println("Jari-jari = "+Tab.r);  
     System.out.println("Tinggi = "+Tab.t);  
     System.out.println("Luas Permukaan tabung = "+l_permT);  
     System.out.println("Volume tabung = "+volT);  
     System.out.println( );  
     Bola Bol;  
     Bol = new Bola();  
     Bol.r = 14.0;  
     double l_permBo = Bol.lp_Bola();  
     double volBo = Bol.vol_Bola();  
     System.out.println("------------------------------");  
     System.out.println("Luas Permukaan dan Volume BOLA");  
     System.out.println("Jari-jari = "+Bol.r);  
     System.out.println("Luas Permukaan bola = "+l_permBo);  
     System.out.println("Volume bola = "+volBo);  
     System.out.println( );  
   }  
 }  
Source Code Luas Permukaan Kubus
 /**  
  * Latihan implementasi kubus dengan field sisi ,  
   method luas permukaan dan volume kubus  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (1.0/100918)  
  */  
 public class Kubus  
 {  
   public double s; //s adalah sisi  
   public double lp_Kubus()  
   {  
     return 6*s*s;  
   }  
   public double vol_Kubus()  
   {  
     return s*s*s;  
   }  
 }  
Source Code Luas Permukaan Tabung
 /**  
  * Latihan implementasi tabung dengan field jari-jari dan tinggi ,  
   method luas permukaan dan volume tabung  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (1.0/100918)  
  */  
 public class Tabung  
 {  
   public double r,t;  
   public double lp_Tabung()  
   {  
     return 2*3.14*r*(r+t);  
   }  
   public double vol_Tabung()  
   {  
     return 3.14*r*r*t;  
   }  
 }  
Source Code Luas Permukaan Balok
 /**  
  * Latihan implementasi balok dengan field panjang,lebar dan tinggi ,  
   method luas permukaan dan volume Balok  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (1.0/100918)  
  */  
 public class Balok  
 {  
   public double p,l,t;  
   public double lp_Balok()  
   {  
     return 2*((p*l)+(p*t)+(l*t));  
   }  
   public double vol_Balok()  
   {  
     return p*l*t;  
   }  
 }  
Source Code Luas Permukaan Bola
 /**  
  Latihan implementasi Bola dengan field jari-jari ,  
   method luas permukaan dan volume Bola  
  *  
  * @author (Chaniyah Zulfa M)  
  * @version (1.0/100918)  
  */  
 public class Bola  
 {  
   public double r; //r adalah jarijari  
   public double lp_Bola()  
   {  
     return 4*3.14*r*r;  
   }  
   public double vol_Bola()  
   {  
     return (4*3.14*r*r*r)/3;  
   }  
 }  

Minggu, 02 September 2018

Tugas 01 PBO B

Belajar awal BlueJ
Chaniyah Zulfa M.
05111740000115
Kelas PBO-B

1.) Class =



2.) Output =



3.) Source Code =


 /**  
  * - Tugas #PBOB - Tugas 01 -  
  *  
  * @author (Chaniyah Zulfa Mukhlishah)  
  * @version (03.1/20180903)  
  */  
 public class Tugas1  
 {  
   public Tugas1()  
   {  
     System.out.print("Nama   : Chaniyah Zulfa Mukhlishah\n");  
     System.out.print("Kelas   : PBO-B\n");  
     System.out.print("Email   : chaniyahzm@gmail.com\n");  
     System.out.print("Blog   : http://nengchan.blogspot.com/\n");  
     System.out.print("No HP/WA : 081217659954\n");  
     System.out.print("Twitter  : @chaniyahzulfa2\n");  
   }  
 }