Jumat, 28 September 2018

Tugas 4 - PBO A

Hari ini Saya mempublish tampilan jam sederhana dengan BlueJ. class yang digunakan adalah:
  1. Number_Display
  2. Clock_Display
  3. TestClockDisplay
Dan ini adalah source codenya:
  • Number_Display
  • Clock_Display
  • TestClockDisplay
Terakhi, inilah hasilnya :)


Sabtu, 22 September 2018

Tugas 3 - PBO A (Membuat remot AC)

Membuat Program Remot AC

 Hari ini saya akan membuat program Remot AC, dan Class yang dibutuhkan adalah:
  1. Main
  2. Remot_AC
Untuk source codenya ada di bawah ini:

Main 
Dalam class main ini adalah perintah perintah yang digunakan untuk menyetting AC seperti menaikan/menurunkan suhu, mode, dll
 

Remote_AC
Dalam class ini adalah fitur fitur yang ada di Remot AC itu

Dan ini hasil compilenya:

  1. Awal ketika AC mati


  2. Ketika AC menyala
  3. Tombol menurunkan suhu (awal 24 ke 23)
  4. Ketika suhu mencapai minimal (18 derajat Celcius)
  5. Tombol menaikkan suhu (awal 24 ke 25)
  6. Ketika suhu mencapai maksimal (30 derajat Celcius)



  7. Tombol ganti mode ke COOL
  8. Tombol swing
Sekian dari Tugas saya, tunggu postingan selanjutnya :)

Minggu, 16 September 2018

Tugas 3 - PBO A

Tugas ketiga hari ini saya membuat ticket machine dengan 2 class yaitu:
  1. Ticket_Machine
  2. IntMain
 Dibawah ini merupakan source codenya:
  1. Ticket_Machine
  2.  /**  
      * ini merupakan class ticket machinenya  
      *  
      * @author (Gede)  
      * @version (17-09-2018)  
      */  
     public class Ticket_Machine  
     {  
       // instance variables - replace the example below with your own  
       private int price;  
       private int balance;  
       private int total;  
       private int kembali;  
       private int orang;  
       private int count;  
       /**  
        * Constructor for objects of class Ticket_Machine  
        */  
       public Ticket_Machine(int ticketcost)  
       {  
         // initialise instance variables  
         price=ticketcost;  
         balance=0;  
         total=0;  
         kembali=0;  
         orang=0;  
         count=0;  
       }  
       /**  
        * An example of a method - replace this comment with your own  
        *  
        * @param y a sample parameter for a method  
        * @return  the sum of x and y  
        */  
       public int getPrice()  
       {  
         return price;  
       }  
       public int getBalance()  
       {  
         return balance;  
       }  
       public void insertJumlahTiket(int jmlh)  
       {  
         orang=jmlh;  
       }  
       public void insertMoney(int amount)  
       {  
         balance=balance+amount;  
       }  
       public void printTicket()  
       {  
         if(balance>=price*orang)  
         {  
           int orang2=orang
           while(orang2>0)  
           {  
             System.out.println("##################");  
             System.out.println("# The BlueJ Line");  
             System.out.println("# Ticket");  
             System.out.println("# "+ price+ " Rupiah.");  
             System.out.println();  
             orang2--;  
             count=1;  
           }  
           kembali=balance-price*orang;  
           if(kembali>0)  
           {  
            System.out.println("Uang Kembalian: Rp "+kembali );   
           }  
           // Update the total collected with the balance.   
           total = total + balance-kembali;   
           // Clear the balance.   
           balance = 0;  
         }  
         else  
         {  
           System.out.println("Uang tidak cukup");   
         }  
       }  
       public int looping()  
       {  
         return count;  
       }  
     }  
    
  3. IntMain
  4.  /**  
      * ini merupakan class mainnya  
      *  
      * @author (Gede)  
      * @version (17-09-2018)  
      */  
     import java.util.Scanner;  
     public class IntMain  
     {  
       // instance variables - replace the example below with your own  
       public static void main(String args[])  
       {  
         Scanner scan=new Scanner(System.in);  
         int cost, menu, balance, money, kembali, jumlah, count1;  
         System.out.println("Masukkan harga tiket ");  
         cost=scan.nextInt();  
         Ticket_Machine ticket=new Ticket_Machine(cost);  
         System.out.println("Masukkan jumlah tiket ");  
         jumlah=scan.nextInt();  
         ticket.insertJumlahTiket(jumlah);  
         System.out.println("1. Get Price");   
         System.out.println("2. Get Balance");   
         System.out.println("3. Insert Money");   
         System.out.println("4. Print Ticket");  
         while(true)  
         {  
           menu=scan.nextInt();   
           switch(menu)   
           {   
             case 1:   
             cost=ticket.getPrice();   
             System.out.println("Harga Tiket: Rp "+cost);   
             break;   
             case 2:   
             balance=ticket.getBalance();   
             System.out.println("Uang yang ditampung: Rp "+balance);  
             break;   
             case 3:  
             System.out.println("Masukkan jumlah uang");  
             money=scan.nextInt();   
             ticket.insertMoney(money);  
             break;   
             case 4:   
             ticket.printTicket();  
             break;   
           }  
           count1=ticket.looping();  
           if(count1==1)  
           {  
             break;  
           }  
         }  
       }  
     }  
    
Dan di bawah ini merupakan hasil dari kode diatas




Sabtu, 15 September 2018

Tugas 2 - PBO A (Menggambar Rumah)

Class yang dibutuhkan:
  1. Picture (untuk menampilkan gambar rumahnya)
  2. Canvas (media untuk menggambar)
  3. Circle (bentuk gambar lingkaran)
  4. Square (bentuk gambar persegi)
  5. Triangle (untuk gambar segitiga)
Lalu ini adalah source code yang telah dibuat:
  1. Picture
  2.  public class Picture  
     {  
       private Square wall;  
       private Square grass;  
       private Circle grass2;  
       private Square window;  
       private Square door;  
       private Triangle roof;  
       private Circle sun;  
       private Square tree;  
       private Circle tree2;  
       /**  
        * Constructor for objects of class Picture  
        */  
       public Picture()  
       {  
         // nothing to do... instance variables are automatically set to null  
       }  
       /**  
        * Draw this picture.  
        */  
       public void draw()  
       {  
         wall = new Square();  
         wall.moveHorizontal(-250);  
         wall.moveVertical(120);  
         wall.changeSize(200);  
         wall.makeVisible();  
         tree = new Square();  
         tree.changeColor("black");  
         tree.moveHorizontal(25);  
         tree.moveVertical(220);  
         tree.changeSize(60);  
         tree.makeVisible();  
         tree = new Square();  
         tree.changeColor("black");  
         tree.moveHorizontal(25);  
         tree.moveVertical(160);  
         tree.changeSize(60);  
         tree.makeVisible();  
         tree2 = new Circle();  
         tree2.changeColor("green");  
         tree2.moveHorizontal(62);  
         tree2.moveVertical(76);  
         tree2.changeSize(150);  
         tree2.makeVisible();  
         door = new Square();  
         door.changeColor("green");  
         door.moveHorizontal(-175);  
         door.moveVertical(270);  
         door.changeSize(50);  
         door.makeVisible();  
         door = new Square();  
         door.changeColor("green");  
         door.moveHorizontal(-175);  
         door.moveVertical(250);  
         door.changeSize(50);  
         door.makeVisible();  
         grass = new Square();  
         grass.changeColor("green");  
         grass.moveHorizontal(-50);  
         grass.moveVertical(270);  
         grass.changeSize(50);  
         grass.makeVisible();  
         grass = new Square();  
         grass.changeColor("green");  
         grass.moveHorizontal(0);  
         grass.moveVertical(270);  
         grass.changeSize(50);  
         grass.makeVisible();  
         grass = new Square();  
         grass.changeColor("green");  
         grass.moveHorizontal(50);  
         grass.moveVertical(270);  
         grass.changeSize(50);  
         grass.makeVisible();  
         grass = new Square();  
         grass.changeColor("green");  
         grass.moveHorizontal(100);  
         grass.moveVertical(270);  
         grass.changeSize(50);  
         grass.makeVisible();  
         grass = new Square();  
         grass.changeColor("green");  
         grass.moveHorizontal(150);  
         grass.moveVertical(270);  
         grass.changeSize(50);  
         grass.makeVisible();  
         grass2 = new Circle();  
         grass2.changeColor("green");  
         grass2.moveHorizontal(29);  
         grass2.moveVertical(279);  
         grass2.changeSize(50);  
         grass2.makeVisible();  
         grass2 = new Circle();  
         grass2.changeColor("green");  
         grass2.moveHorizontal(79);  
         grass2.moveVertical(279);  
         grass2.changeSize(50);  
         grass2.makeVisible();  
         grass2 = new Circle();  
         grass2.changeColor("green");  
         grass2.moveHorizontal(129);  
         grass2.moveVertical(279);  
         grass2.changeSize(50);  
         grass2.makeVisible();  
         grass2 = new Circle();  
         grass2.changeColor("green");  
         grass2.moveHorizontal(179);  
         grass2.moveVertical(279);  
         grass2.changeSize(50);  
         grass2.makeVisible();  
         grass2 = new Circle();  
         grass2.changeColor("green");  
         grass2.moveHorizontal(229);  
         grass2.moveVertical(279);  
         grass2.changeSize(50);  
         grass2.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-225);  
         window.moveVertical(150);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-199);  
         window.moveVertical(150);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-199);  
         window.moveVertical(178);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-225);  
         window.moveVertical(178);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-125);  
         window.moveVertical(150);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-99);  
         window.moveVertical(178);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-99);  
         window.moveVertical(150);  
         window.changeSize(25);  
         window.makeVisible();  
         window = new Square();  
         window.changeColor("black");  
         window.moveHorizontal(-125);  
         window.moveVertical(178);  
         window.changeSize(25);  
         window.makeVisible();  
         roof = new Triangle();   
         roof.changeColor("blue");  
         roof.changeSize(80, 220);  
         roof.moveHorizontal(-50);  
         roof.moveVertical(20);  
         roof.makeVisible();  
         sun = new Circle();  
         sun.changeColor("yellow");  
         sun.moveHorizontal(10);  
         sun.moveVertical(-40);  
         sun.changeSize(80);  
         sun.makeVisible();  
       }  
     }  
    
  3. Canvas
  4.  import javax.swing.*;  
     import java.awt.*;  
     import java.util.List;  
     import java.util.*;  
     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 Picture Demo", 500, 500,   
                          Color.white);  
         }  
         canvasSingleton.setVisible(true);  
         return canvasSingleton;  
       }  
       // ----- instance part -----  
       private JFrame frame;  
       private CanvasPane canvas;  
       private Graphics2D graphic;  
       private Color backgroundColor;  
       private Image canvasImage;  
       private List<Object> objects;  
       private HashMap<Object, ShapeDescription> 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 bgColor the desired background color of the canvas  
        */  
       private Canvas(String title, int width, int height, Color bgColor)  
       {  
         frame = new JFrame();  
         canvas = new CanvasPane();  
         frame.setContentPane(canvas);  
         frame.setTitle(title);  
         frame.setLocation(30, 30);  
         canvas.setPreferredSize(new Dimension(width, height));  
         backgroundColor = bgColor;  
         frame.pack();  
         objects = new ArrayList<Object>();  
         shapes = new HashMap<Object, ShapeDescription>();  
       }  
       /**  
        * 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 color  
           Dimension size = canvas.getSize();  
           canvasImage = canvas.createImage(size.width, size.height);  
           graphic = (Graphics2D)canvasImage.getGraphics();  
           graphic.setColor(backgroundColor);  
           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 color of the Canvas.  
        * @param newColor  the new color for the foreground of the Canvas   
        */  
       public void setForegroundColor(String colorString)  
       {  
         if(colorString.equals("red")) {  
           graphic.setColor(new Color(235, 25, 25));  
         }  
         else if(colorString.equals("black")) {  
           graphic.setColor(Color.black);  
         }  
         else if(colorString.equals("blue")) {  
           graphic.setColor(new Color(30, 75, 220));  
         }  
         else if(colorString.equals("yellow")) {  
           graphic.setColor(new Color(255, 230, 0));  
         }  
         else if(colorString.equals("green")) {  
           graphic.setColor(new Color(80, 160, 60));  
         }  
         else if(colorString.equals("magenta")) {  
           graphic.setColor(Color.magenta);  
         }  
         else if(colorString.equals("white")) {  
           graphic.setColor(Color.white);  
         }  
         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(Object shape : objects) {  
           shapes.get(shape).draw(graphic);  
         }  
         canvas.repaint();  
       }  
       /**  
        * Erase the whole canvas. (Does not repaint.)  
        */  
       private void erase()  
       {  
         Color original = graphic.getColor();  
         graphic.setColor(backgroundColor);  
         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);  
         }  
       }  
     }  
    
  5. Circle
  6.  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;  
       /**  
        * Create a new circle at default position with default color.  
        */  
       public Circle()  
       {  
         diameter = 68;  
         xPosition = 230;  
         yPosition = 90;  
         color = "blue";  
       }  
       /**  
        * 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 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();  
       }  
       /**  
        * 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);  
         }  
       }  
     }  
    
  7. Square
  8.  import java.awt.*;  
     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 = 60;  
         xPosition = 310;  
         yPosition = 120;  
         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 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();  
       }  
       /**  
        * 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);  
         }  
       }  
     }  
    
  9. Triangle 
  10.  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 = 60;  
         width = 70;  
         xPosition = 210;  
         yPosition = 140;  
         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 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();  
       }  
       /**  
        * 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);  
         }  
       }  
     }  
Dan hasilnya adalah seperti dibawah ini:

Minggu, 09 September 2018

Tugas 2 - PBO A

Ini adalah tugas PBO kelas A kedua saya, tugasnya dengan membuat fungsi luas dan keliling bangun 2D yaitu:
  • persegi
  • circle
  • segitiga
  • belah ketupat
  • jajar genjang
  • persegi panjang
Berikut ini adalah source codenya:
1. Persegi
 
 /**  
  * Write a description of class Persegi here.  
  * Ini adalah class buat mencari luas dan keliling Persegi  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Persegi extends MyMain  
 {  
   // instance variables - replace the example below with your own  
   public double sisi;  
   public Persegi()  
   {  
     System.out.print("Masukkan sisi");  
     Scanner sis = new Scanner (System.in);  
     sisi = sis.nextFloat();  
   }  
   public double Luasp()  
   {  
     // put your code here  
     return sisi*sisi;  
   }  
     public double kelilingp()  
   {  
     // put your code here  
     return 4*sisi;  
   }  
 }  

2. Circle
 /**  
  * Write a description of class Circle here.  
  * Ini adalah class buat mencari luas dan keliling Circle  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Circle extends MyMain  
 {  
   // instance variables - replace the example below with your own  
   public double x, y; //titik pusat  
   public double r; // jari jari  
   public Circle()  
   {  
     System.out.print("Masukkan jari-jari");  
     Scanner jari2 = new Scanner (System.in);  
     r = jari2.nextFloat();  
     System.out.print("Masukkan titik pusat x");  
     Scanner ex = new Scanner (System.in);  
     x = ex.nextFloat();  
     System.out.print("Masukkan titik pusat y");  
     Scanner ye = new Scanner (System.in);  
     y = ye.nextFloat();  
   }  
   public double Luas()  
   {  
     return 3.14*r*r;  
   }  
   public double Keliling()  
   {  
     return 2*3.14*r;  
   }  
 }  

3. Segitiga
 /**  
  * Write a description of class Segitiga here.  
  * Ini adalah class buat mencari luas dan keliling Segitiga  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Segitiga extends MyMain  
 {  
   // instance variables - replace the example below with your own  
   public double alas;  
   public double tinggi;  
   public Segitiga()  
   {  
     System.out.print("Masukkan alas");  
     Scanner als = new Scanner (System.in);  
     alas = als.nextFloat();  
     System.out.print("Masukkan tinggi");  
     Scanner tng = new Scanner (System.in);  
     tinggi = tng.nextFloat();  
   }  
   public double Luass()  
   {  
     return alas*tinggi/2;  
   }  
   public double Kelilings()  
   {  
     return alas+tinggi+Math.sqrt((alas*alas)+(tinggi*tinggi));  
   }  
 }  

4. Belah Ketupat
 /**  
  * Write a description of class Belah_Ketupat here.  
  * Ini adalah class buat mencari luas dan keliling Belah_Ketupat  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Belah_Ketupat extends MyMain  
 {  
   // instance variables - replace the example below with your own  
   public double d1;  
   public double d2;  
   public Belah_Ketupat()  
   {  
     System.out.print("Masukkan Diagonal 1");  
     Scanner dg1 = new Scanner (System.in);  
     d1 = dg1.nextFloat();  
     System.out.print("Masukkan Diagonal 2");  
     Scanner dg2 = new Scanner (System.in);  
     d2 = dg2.nextFloat();  
   }  
   public double luasbk()  
   {  
     return d1*d2/2;  
   }  
   public double kelilingbk()  
   {  
     return 4*(Math.sqrt((d1*d1)/4+(d2*d2)/4));  
   }  
 }  

5. Jajar Genjang
 /**  
  * Write a description of class Jajar_Genjang here.  
  * Ini adalah class buat mencari luas dan keliling Jajar_Genjang  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Jajar_Genjang  
 {  
   // instance variables - replace the example below with your own  
   public double alasj;  
   public double tinggij;  
   public double miring;  
   /**  
    * Constructor for objects of class Jajar_Genjang  
    */  
   public Jajar_Genjang()  
   {  
     System.out.print("Masukkan alas");  
     Scanner alj = new Scanner (System.in);  
     alasj = alj.nextFloat();  
     System.out.print("Masukkan tinggi");  
     Scanner tgj = new Scanner (System.in);  
     tinggij = tgj.nextFloat();  
     System.out.print("Masukkan titik sisi miringnya");  
     Scanner mrj = new Scanner (System.in);  
     miring = mrj.nextFloat();  
   }  
   /**  
    * An example of a method - replace this comment with your own  
    *  
    * @param y a sample parameter for a method  
    * @return  the sum of x and y  
    */  
   public double luasjg()  
   {  
     return alasj*tinggij;  
   }  
   public double kelilingjg()  
   {  
     return 2*(alasj+miring);  
   }  
 }  

6. Persegi Panjang
 /**  
  * Write a description of class Persegi_Panjang here.  
  * Ini adalah class buat mencari luas dan keliling Persegi_Panjang  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 import java.util.Scanner;  
 public class Persegi_Panjang extends MyMain  
 {  
   // instance variables - replace the example below with your own  
   public double panjangpp;  
   public double lebarpp;  
   /**  
    * Constructor for objects of class Persegi_Panjang  
    */  
   public Persegi_Panjang()  
   {  
     System.out.print("Masukkan panjang");  
     Scanner pnjp = new Scanner (System.in);  
     panjangpp = pnjp.nextFloat();  
     System.out.print("Masukkan lebar");  
     Scanner lbrp = new Scanner (System.in);  
     lebarpp = lbrp.nextFloat();  
   }  
   /**  
    * An example of a method - replace this comment with your own  
    *  
    * @param y a sample parameter for a method  
    * @return  the sum of x and y  
    */  
   public double luaspp()  
   {  
     return panjangpp*lebarpp;  
   }  
     public double kelilingpp()  
   {  
     return 2*(panjangpp+lebarpp);  
   }  
 }  

7. Main
 /**  
  * Write a description of class Main here.  
  * ini adalah fungsi utamanya  
  * @author (Gede)  
  * @version (10/09/2018)  
  */  
 class MyMain  
 {  
   public static void main(String args[])  
   {  
     System.out.println("Lingkaran: ");  
     Circle aCircle;  
     aCircle= new Circle();  
     double aLuas = aCircle.Luas();  
     double aKeliling = aCircle.Keliling();  
     System.out.println("Luasnya = " +aLuas);  
     System.out.println("Kelilingnya = " +aKeliling);   
     System.out.println("Persegi: ");  
     Persegi apersegi;  
     apersegi= new Persegi();  
     double aluasp= apersegi.Luasp();  
     double akelilingp= apersegi.kelilingp();      
     System.out.println("Luasnya = " +aluasp);  
     System.out.println("Kelilingnya = " +akelilingp);  
     System.out.println("Segitiga (siku-siku): ");  
     Segitiga asegitiga;  
     asegitiga= new Segitiga();  
     double aluass= asegitiga.Luass();  
     double akelilings= asegitiga.Kelilings();      
     System.out.println("Luasnya = " +aluass);  
     System.out.println("Kelilingnya = " +akelilings);  
     System.out.println("Belah Ketupat: ");  
     Belah_Ketupat abelah_ketupat;  
     abelah_ketupat= new Belah_Ketupat();  
     double aluasbk= abelah_ketupat.luasbk();  
     double akelilingbk= abelah_ketupat.kelilingbk();      
     System.out.println("Luasnya = " +aluasbk);  
     System.out.println("Kelilingnya = " +akelilingbk);  
     System.out.println("Jajar Genjang: ");  
     Jajar_Genjang ajajar_genjang;  
     ajajar_genjang= new Jajar_Genjang();  
     double aluasjg= ajajar_genjang.luasjg();  
     double akelilingjg= ajajar_genjang.kelilingjg();      
     System.out.println("Luasnya = " +aluasjg);  
     System.out.println("Kelilingnya = " +akelilingjg);  
     System.out.println("Persegi Panjang: ");  
     Persegi_Panjang apersegi_panjang;  
     apersegi_panjang= new Persegi_Panjang();  
     double aluaspp= apersegi_panjang.luaspp();  
     double akelilingpp= apersegi_panjang.kelilingpp();      
     System.out.println("Luasnya = " +aluaspp);  
     System.out.println("Kelilingnya = " +akelilingpp);  
   }  
 }  

Dan terakhir ini hasilnya

Minggu, 02 September 2018

Tugas 1 - PBO A

Ini adalah tugas PBO kelas A pertama saya, tugasnya membuat biodata dan di bawah ini adalah tampilan hasil dan source codenya:


 /** 
  * Write a description of class Biodata here. 
  * ini adalah biodata 
  * @author (I Gede Agung Krisna Pamungkas) 
  * @version (0.1/3 september 2018) 
  */ 
 public class Biodata 
 { 
   // instance variables - replace the example below with your own 
   private int x; 
   /** 
    * Constructor for objects of class Biodata 
    */ 
   public Biodata() 
   { 
     System.out.print("Nama\t\t: I Gede Agung Krisna Pamungkas\n"); 
     System.out.print("Kelas\t\t: PBO A\n"); 
     System.out.print("Alamat Rumah\t: Jl Aquamarin 1 B32 KBD Gresik\n"); 
     System.out.print("Email\t\t: igedeagung25@gmail.com\n"); 
     System.out.print("Blog\t\t: igedeagung25.blogspot.com\n"); 
     System.out.print("No HP/WA\t: 085854737161\n"); 
     System.out.print("Twitter\t\t: @igedeagung25 \n"); 
   } 
 }