Minggu, 30 September 2018

Jam Digital

Jam

Nama   : Timothyus Tanner
NRP     : 05111740000103
Kelas    : PBO - A
Pada minggu ke 5 ini, saya berlatih untuk membuat sebuah jam digital dengan menggunakan java, berikut merupakan source code dan screenshoot dari program saya.

Source Code

1.  Executor

 /*  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 public class Executor {  
      public static void main(String[]args) {  
           new Executor();  
      }  
      public Executor() {  
           new clock();  
      }  
 }  

2. Clock

 /*  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 import javax.swing.*;  
 import java.awt.*;  
 import java.awt.event.*;  
 import java.util.Calendar;  
 public class clock extends JFrame{  
   private static final long serialVersionUID = 1L;  
   JTextField timeF;  
   JPanel panel;  
   public clock() {  
     super("Java Clock by Timothyus Tanner");  
     setSize(225,200);  
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
     setVisible(true);  
     setResizable(true);  
     setLocationRelativeTo(null);  
     panel = new JPanel();  
     panel.setLayout(new FlowLayout());  
     timeF = new JTextField(0);  
     timeF.setBackground(Color.BLACK);  
     timeF.setForeground(Color.GREEN);  
     timeF.setEditable(false);  
     timeF.setFont(new Font("Arial", Font.PLAIN, 72));  
     panel.add(timeF);  
     add(panel);  
     Timer t = new Timer(1000, new Listener());  
     t.start();  
   }  
   class Listener implements ActionListener{  
     public void actionPerformed(ActionEvent e){  
       Calendar rightNow = Calendar.getInstance();  
       int hour = rightNow.get(Calendar.HOUR_OF_DAY);  
       int min = rightNow.get(Calendar.MINUTE);  
       int sec = rightNow.get(Calendar.SECOND);  
       String h1 = String.format("%02d", hour);  
       String m1 = String.format("%02d", min);  
       String s1 = String.format("%02d", sec);  
       timeF.setText(h1 + ":" + m1 +":"+ s1);  
     }  
   }  
 }  

Screenshoot


Minggu, 23 September 2018

Remote AC

Remote AC

Nama   : Timothyus Tanner
NRP     : 05111740000103
Kelas   : PBO - A

Source Code :
1. Main

 /**  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *   
  */  
 import java.util.Scanner;   
 public class main  
 {  
   public main()  
   {  
     Scanner scan = new Scanner(System.in);  
     int menu;  
     awal AC = new awal();  
     AC.printSekarang();  
     while(true){  
       System.out.println("1. Nyalakan / Matikan");  
       System.out.println("2. Naikkan suhu");  
       System.out.println("3. Turunkan suhu");  
       System.out.println("4. Lihat kondisi sekarang");  
       System.out.println("5. Exit");  
       menu = scan.nextInt();  
       if(menu == 1){  
         AC.togle();  
       }  
       else if(menu == 2){  
         AC.suhunaik();  
       }  
       else if(menu == 3){  
         AC.suhuturun();  
       }  
       else if(menu == 4){  
         AC.printSekarang();  
       }  
       else if(menu == 5){  
         break;  
       }  
     }  
   }  
 }  

2. Awal

 /*  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO A  
  *   
  */  
 public class awal  
 {  
   private boolean kondisi;  
   private int suhu;  
   public awal()  
   {  
     suhu = 24;  
     kondisi = false;  
   }  
   public void suhunaik(){  
     if(kondisi == true){  
       if(suhu < 24){  
         suhu += 1;  
         System.out.println("Suhu berubah dari " + (suhu - 1) + " menjadi " + suhu);  
       }  
       else{  
         System.out.println("Suhu sudah maksimal");  
       }  
     }  
     else{  
       System.out.println("Tidak dapat menaikkan suhu dikarenakan AC masih dalam keadaan mati");  
     }  
   }  
   public void suhuturun(){  
     if(kondisi == true){  
       if(suhu > 16){  
         suhu -= 1;  
         System.out.println("Suhu berubah dari " + (suhu + 1) + " menjadi " + suhu);  
       }  
       else{  
         System.out.println("Suhu sudah minimum");  
       }  
     }  
     else{  
       System.out.println("Tidak dapat menurunkan suhu dikarenakan AC masih dalam keadaan mati");;  
     }  
   }  
   public void togle(){  
     if(kondisi == false){  
       kondisi = true;  
     }  
     else{  
       kondisi = false;  
     }  
   }  
   public void printSekarang(){  
     System.out.println("---------- Remote AC ----------");  
     if(kondisi == false){  
       System.out.println("| AC dalam keadaan mati");  
     }  
     else{  
       System.out.println("| AC dalam keadaan menyala");  
       System.out.println("| Dengan suhu " + (suhu));  
     }  
     System.out.println("-------------------------------");  
   }  
 }  

Dokumentasi Output :

1. Tampilan Awal


2. Menyalakan / mematikan AC & Lihat kondisi sekarang


3. Menaikkan suhu



4. Menurunkan Suhu



Minggu, 16 September 2018

Tugas 3 PBO-A

Tugas 3 PBO-A --> Ticket Machine

Hari ini, 7 September 2018, kelas PBO-A diberi penugasan untuk membuat program ticket machine

Source Code

1. Main
 import java.util.Scanner;   
  public class IntMain   
  {   
    public static void main(String args[])   
    {   
    Scanner scan= new Scanner(System.in);   
    int cost,menu;   
    System.out.println("Masukkan harga tiket \n");   
    cost=scan.nextInt();   
    TicketMachine ticket=new TicketMachine(cost);  
    while(true)  
    {  
      System.out.println("1. Get Price");   
      System.out.println("2. Get Balance");   
      System.out.println("3. Insert Money");   
      System.out.println("4. Print Ticket");   
      System.out.println("5. New Price (Don't forget to insert money again)");  
      System.out.println("6. Exit");  
      menu=scan.nextInt();   
      if(menu == 1){  
        cost = ticket.getPrice();  
        System.out.println(cost);  
      }  
      else if(menu == 2){  
        int uang = ticket.getBalance();  
        System.out.println(uang);  
      }  
      else if(menu == 3){  
        int money = scan.nextInt();  
        ticket.insertMoney(money);  
      }  
      else if(menu == 4){  
        ticket.printTicket();  
      }  
      else if(menu == 5){  
        cost = scan.nextInt();  
        ticket=new TicketMachine(cost);  
      }  
      else{  
        break;  
      }  
    }   
  }  
  }   

2. Ticket Machine
 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;   
  /**   
  * Create a machine that issues tickets of the given price.   
  * Note that the price must be greater than zero, and there   
  * are no checks to ensure this.   
  */   
  public TicketMachine(int ticketCost)   
  {   
  price = ticketCost;   
  balance = 0;   
  total = 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)   
  {   
   balance = balance + amount;   
  }   
  /**   
  * Print a ticket.   
  * Update the total collected and   
  * reduce the balance to zero.   
  */   
  public void printTicket()   
  {   
   // Simulate the printing of a ticket.   
   System.out.println("##################");   
   System.out.println("# The BlueJ Line");   
   System.out.println("# " + (balance/price) + " Ticket");   
   System.out.println("# " + price + " cents.");   
   System.out.println("##################");   
   System.out.println();   
   // Update the total collected with the balance.   
   total = total + balance;   
   // Clear the balance.   
   balance = 0;   
  }   
  }   

Output


PBO Rumah

RUMAH

Nama  : Timothyus Tanner
NRP    : 05111740000103
Kelas   : PBO A

Tugas membuat rumah.

1. Canvas

 /* Author : TIMOTHYUS TANNER  
  * Kelas : PBO A  
  */   
  import javax.swing.*;   
  import java.awt.*;   
  import java.util.List;   
  import java.util.*;   
  public class Canvas   
  {    
   private static Canvas canvasSingleton;   
   public static final Color Brown = new Color(102,51,0);  
   public static final Color lightblue = new Color(51,204,255);  
   public static Canvas getCanvas()   
   {   
    if(canvasSingleton == null) {   
     canvasSingleton = new Canvas("Ini Rumahku", 600, 400,    
       Color.white);   
    }   
    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);   
    objects.add(referenceObject);  
    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("brown"))   
     graphic.setColor(Brown);   
    else if(colorString.equals("white"))   
     graphic.setColor(Color.white);   
    else if(colorString.equals("orange"))  
     graphic.setColor(Color.orange);  
    else if(colorString.equals("lightblue"))  
     graphic.setColor(lightblue);  
    else if(colorString.equals("gray"))  
     graphic.setColor(Color.gray);  
    else if(colorString.equals("darkgreen"))  
     graphic.setColor(new Color(0,102, 0));  
    else  
     graphic.setColor(Color.black);  
   }    
   public void wait(int milliseconds)   
   {   
    try   
    {   
     Thread.sleep(milliseconds);   
    }    
    catch (Exception e)   
    {   
     // ignoring exception at the moment   
    }   
   }   
   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);   
    }   
   }   
  }   

2. Triangle

 /* Author : TIMOTHYUS TANNER  
  * Kelas : PBO A  
  */  
 import java.awt.*;   
 public class Triangle   
  {   
   private int height;   
   private int width;   
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   // New Triangle  
   public Triangle()   
   {   
    height = 30;   
    width = 40;   
    xPosition = 50;   
    yPosition = 15;   
    color = "blue";   
    isVisible = false;   
   }   
   // Make Shape Visible  
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   // Make Shape Invisible  
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   // Geser Kanan  
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   // Geser Kiri   
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   // Geser Atas  
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   // Geser Bawah  
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   // Geser Horizontal dengan banyak pixel  
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   // Geser Vertikal dengan banyak pixel  
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }   
   // Ganti Ukuran Shape >=0  
   public void changeSize(int newHeight, int newWidth)   
   {   
    erase();   
    height = newHeight;   
    width = newWidth;   
    draw();   
   }   
   // "red", "yellow", "blue", "green", "pink" and "black"   
   public void changeColor(String newColor)   
   {   
    color = newColor;   
    draw();   
   }   
   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);   
    }   
   }  
   private void erase()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.erase(this);   
    }   
   }   
  }   

3. Rectangle

 import java.awt.*;   
  public class Recta   
  {   
   private int P;   
   private int L;  
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   // New Square  
   public Recta()   
   {   
    P = 100;   
    L = 50;  
    xPosition = 260;   
    yPosition = 200;   
    color = "red";   
    isVisible = false;   
   }   
   // Make Shape Visible  
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   // Make Shape Invisible  
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   // Geser Kanan  
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   // Geser Kiri  
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   // Geser Atas  
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   // Geser Bawah  
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   // Geser Horizontal dengan banyak pixel  
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   // Geser Vertikal dengan banyak pixel  
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }   
   // Ganti Ukuran Shape >=0  
   public void changeSize(int newP,int newL)   
   {   
    erase();   
    P = newP;   
    L = newL;  
    draw();   
   }   
   // "red", "yellow", "blue", "green", "pink" 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(xPosition, yPosition, P, L));   
     canvas.wait(10);   
    }   
   }   
   private void erase()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.erase(this);   
    }   
   }   
  }   

4. Square

 import java.awt.*;   
  public class Square   
  {   
   private int size;   
   private int xPosition;   
   private int yPosition;   
   private String color;   
   private boolean isVisible;   
   // New Square  
   public Square()   
   {   
    size = 100;   
    xPosition = 260;   
    yPosition = 200;   
    color = "red";   
    isVisible = false;   
   }   
   // Make Shape Visible  
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   // Make Shape Invisible  
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   // Geser Kanan  
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   // Geser Kiri  
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   // Geser Atas  
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   // Geser Bawah  
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   // Geser Horizontal dengan banyak pixel  
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   // Geser Vertikal dengan banyak pixel  
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }   
   // Ganti Ukuran Shape >=0  
   public void changeSize(int newSize)   
   {   
    erase();   
    size = newSize;   
    draw();   
   }   
   // "red", "yellow", "blue", "green", "pink" 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(xPosition, yPosition, size, size));   
     canvas.wait(10);   
    }   
   }   
   private void erase()   
   {   
    if(isVisible) {   
     Canvas canvas = Canvas.getCanvas();   
     canvas.erase(this);   
    }   
   }   
  }   

5. Circle

 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;   
   // New Circle  
   public Circle()  
   {   
    diameter = 30;   
    xPosition = 20;   
    yPosition = 60;   
    color = "blue";   
    isVisible = false;   
   }   
   // Make Shape Visible  
   public void makeVisible()   
   {   
    isVisible = true;   
    draw();   
   }   
   // Make Shape Invisible  
   public void makeInvisible()   
   {   
    erase();   
    isVisible = false;   
   }   
   // Geser Kanan  
   public void moveRight()   
   {   
    moveHorizontal(20);   
   }   
   // Geser Kiri  
   public void moveLeft()   
   {   
    moveHorizontal(-20);   
   }   
   // Geser Atas  
   public void moveUp()   
   {   
    moveVertical(-20);   
   }   
   // Geser Bawah  
   public void moveDown()   
   {   
    moveVertical(20);   
   }   
   // Geser Horizontal dengan banyak pixel  
   public void moveHorizontal(int distance)   
   {   
    erase();   
    xPosition += distance;   
    draw();   
   }   
   // Geser Vertikal dengan banyak pixel  
   public void moveVertical(int distance)   
   {   
    erase();   
    yPosition += distance;   
    draw();   
   }    
   // Ganti Ukuran Shape >=0  
   public void changeSize(int newDiameter)   
   {   
    erase();   
    diameter = newDiameter;   
    draw();   
   }   
   // "red", "yellow", "blue", "green", "pink" 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);   
    }   
   }   
  }   

6. Picture

 /* Author : TIMOTHYUS TANNER  
  * Kelas : PBO A  
  */  
 public class Picture   
  {   
   private Triangle roof, grass1, grass2, grass3, grass4, grass5;   
   private Recta wall,door1,door2,tree,window4,window5,window3,window6;  
   private Square window1,window2;  
   private Circle knob1,knob2,sun;  
   private Circle leaf1,leaf2,leaf3;  
   private Circle cl1,cl2,cl3,cl4,cl5,cl6;  
   public Picture()   
   {   
    drawRoof();  
    drawWall();  
    drawWindow();  
    drawDoor();  
    drawKnob();  
    drawTree();  
    drawSky();  
   }   
   public void drawRoof()  
   {  
   roof = new Triangle();  
   roof.moveHorizontal(160);  
   roof.moveVertical(95);  
   roof.makeVisible();  
   roof.changeSize(90, 200);  
   }   
   public void drawWall()  
   {  
   wall = new Recta();  
   wall.moveHorizontal(-142);  
   wall.makeVisible();  
   wall.changeSize(180, 190);  
   }  
   public void drawWindow()  
   {  
   window1= new Square();  
   window1.moveHorizontal(-125);  
   window1.moveVertical(10);  
   window1.makeVisible();  
   window1.changeSize(60);  
   window1.changeColor("yellow");  
   window4= new Recta();  
   window4.moveHorizontal(-125);  
   window4.moveVertical(37);  
   window4.makeVisible();  
   window4.changeSize(60,3);  
   window4.changeColor("black");  
   window5= new Recta();  
   window5.moveHorizontal(-97);  
   window5.moveVertical(10);  
   window5.makeVisible();  
   window5.changeSize(3,60);  
   window5.changeColor("black");  
   window2= new Square();  
   window2.moveHorizontal(-40);  
   window2.moveVertical(10);  
   window2.makeVisible();  
   window2.changeSize(60);  
   window2.changeColor("yellow");  
   window3= new Recta();  
   window3.moveHorizontal(-40);  
   window3.moveVertical(37);  
   window3.makeVisible();  
   window3.changeSize(60,3);  
   window3.changeColor("black");  
   window6= new Recta();  
   window6.moveHorizontal(-12);  
   window6.moveVertical(10);  
   window6.makeVisible();  
   window6.changeSize(3,60);  
   window6.changeColor("black");  
   }    
   public void drawDoor()  
   {  
   door1 = new Recta();  
   door1.moveHorizontal(-107);  
   door1.moveVertical(95);  
   door1.makeVisible();  
   door1.changeSize(120, 95);  
   door1.changeColor("yellow");  
   door2 = new Recta();  
   door2.moveHorizontal(-48);  
   door2.moveVertical(95);  
   door2.makeVisible();  
   door2.changeSize(3, 95);  
   door2.changeColor("black");  
   }  
   public void drawKnob()  
   {  
   knob1 = new Circle();  
   knob1.makeVisible();  
   knob1.changeSize(17);  
   knob1.moveVertical(270);  
   knob1.moveHorizontal(170);  
   knob2 = new Circle();  
   knob2.makeVisible();  
   knob2.changeSize(17);  
   knob2.moveVertical(270);  
   knob2.moveHorizontal(199);  
   }  
   public void drawTree()  
   {  
   tree = new Recta();  
   tree.moveHorizontal(220);  
   tree.moveVertical(70);  
   tree.makeVisible();  
   tree.changeSize(20, 120);  
   tree.changeColor("brown");  
   leaf1 = new Circle();  
   leaf1.makeVisible();  
   leaf1.changeSize(80);  
   leaf1.changeColor("green");  
   leaf1.moveHorizontal(400);  
   leaf1.moveVertical(160);  
   leaf2 = new Circle();  
   leaf2.makeVisible();  
   leaf2.changeSize(80);  
   leaf2.changeColor("green");  
   leaf2.moveHorizontal(459);  
   leaf2.moveVertical(160);  
   leaf3 = new Circle();  
   leaf3.makeVisible();  
   leaf3.changeSize(80);  
   leaf3.changeColor("green");  
   leaf3.moveHorizontal(430);  
   leaf3.moveVertical(105);  
   grass1 = new Triangle();  
   grass1.makeVisible();  
   grass1.changeColor("darkgreen");  
   grass1.moveHorizontal(430);  
   grass1.moveVertical(348);  
   grass1.changeSize(30,30);  
   grass2 = new Triangle();  
   grass2.makeVisible();  
   grass2.changeColor("darkgreen");  
   grass2.moveHorizontal(450);  
   grass2.moveVertical(348);  
   grass2.changeSize(30,30);  
   grass2 = new Triangle();  
   grass2.makeVisible();  
   grass2.changeColor("darkgreen");  
   grass2.moveHorizontal(470);  
   grass2.moveVertical(348);  
   grass2.changeSize(30,30);  
   grass2 = new Triangle();  
   grass2.makeVisible();  
   grass2.changeColor("darkgreen");  
   grass2.moveHorizontal(410);  
   grass2.moveVertical(348);  
   grass2.changeSize(30,30);  
   }  
   public void drawSky()  
   {  
   sun = new Circle();  
   sun.changeColor("yellow");  
   sun.makeVisible();  
   sun.changeSize(160);  
   sun.moveHorizontal(-50);  
   sun.moveVertical(-100);  
   cl3 = new Circle();  
   cl3.changeColor("gray");  
cl3.makeVisible(); cl3.moveHorizontal(410); cl3.moveVertical(-20); cl3.changeSize(50); cl1 = new Circle(); cl1.changeColor("gray"); cl1.makeVisible(); cl1.moveHorizontal(395); cl2 = new Circle(); cl2.changeColor("gray"); cl2.makeVisible(); cl2.moveHorizontal(445); } }

Hasil





Senin, 10 September 2018

TUGAS 2 PBO A - CLASS AND OBJECT

Nama : Timothyus Tanner
NRP   : 05111740000103

Tugas 2 PBO A tentang membuat rumus bangun 2D dengan Class and Object

Source Code
1. Main

 public class Main  
 {  
   public static void kotak()  
   {  
     Persegi kotaks;  
     kotaks = new Persegi();  
     kotaks.s = 5;  
     int luas = kotaks.luas();  
     int keliling = kotaks.kel();  
     System.out.println("Persegi");  
     System.out.println("Sisi\t\t= " + kotaks.s);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + keliling);  
   }  
   public static void segitiga()  
   {  
     Segitiga segitigas;  
     segitigas = new Segitiga();  
     segitigas.a = 10;  
     segitigas.t = 4;  
     double l = segitigas.luas();  
     double k = segitigas.keliling();  
     System.out.println("Segitiga Sama Sisi");  
     System.out.println("Alas\t\t= " + segitigas.a);  
     System.out.println("Tinggi\t\t= " + segitigas.t);  
     System.out.println("Luas\t\t= " + l);  
     System.out.println("Keliling\t= " + k);  
   }  
   public static void pp()  
   {  
     Persegi_Panjang PP;  
     PP = new Persegi_Panjang();  
     PP.p = 5;  
     PP.l = 2;  
     int luas = PP.luas();  
     int keliling = PP.kel();  
     System.out.println("Persegi Panjang");  
     System.out.println("Panjang\t\t= " + PP.p);  
     System.out.println("Lebar\t\t= " + PP.l);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + keliling);  
   }  
   public static void jg()  
   {  
     Jajar_Genjang jgs;  
     jgs = new Jajar_Genjang();  
     jgs.a = 10;  
     jgs.t = 2;  
     jgs.b = 4;  
     double luas = jgs.luas();  
     double kel = jgs.keliling();  
     System.out.println("Jajar Genjang");  
     System.out.println("Alas\t\t= " + jgs.a);  
     System.out.println("Tinggi\t\t= " + jgs.t);  
     System.out.println("Sisi Miring\t= " + jgs.b);  
     System.out.println("Luas\t\t= " + luas);  
     System.out.println("Keliling\t= " + kel);  
   }  
   public static void bk()  
   {  
     Belah_Ketupat bks;  
     bks = new Belah_Ketupat();  
     bks.d1 = 6;  
     bks.d2 = 8;  
     bks.s = 5;  
     double luas = bks.luas();  
     double kel = bks.kel();  
     System.out.println("Belah Ketupat");  
     System.out.println("Diagonal 1\t= " +bks.d1);  
     System.out.println("Diagonal 2\t= " +bks.d2);  
     System.out.println("Sisi\t\t= " +bks.s);  
     System.out.println("Luas\t\t= " +luas);  
     System.out.println("Keliling\t= " +kel);  
   }  
   public static void lingk()  
   {  
     Lingkaran bunder;  
     bunder = new Lingkaran();  
     bunder.r = 10;  
     double luas = bunder.luas();  
     double kel = bunder.kel();  
     System.out.println("Lingkaran");  
     System.out.println("Jari-jari\t= " +bunder.r);  
     System.out.println("Luas\t\t= " +luas);  
     System.out.println("Keliling\t= " +kel);  
   }  
 }  

2. Segitiga

 public class Segitiga  
 {  
   public double a, t;  
   public double luas()  
   {  
     return a * t / 2.0;  
   }  
   public double keliling()  
   {  
     return 3 * a;  
   }  
 }  

3. Persegi

 public class Persegi  
 {  
   public int s;  
   public int luas()  
   {  
     return s * s;  
   }  
   public int kel()  
   {  
     return 4 * s;  
   }  
 }  

4. Jajar Genjang

 public class Jajar_Genjang  
 {  
   public double a,t,b;  
   public double luas()  
   {  
     return a * t;  
   }  
   public double keliling()  
   {  
     return 2 * (a + b);  
   }  
 }  

5. Belah Ketupat

 public class Belah_Ketupat  
 {  
   public double d1, d2, s;  
   public double luas()  
   {  
     return (d1 * d2) / 2.0;  
   }  
   public double kel()  
   {  
     return 4 * s;  
   }  
 }  

6. Persegi Panjang

 public class Persegi_Panjang  
 {  
   public int p,l;  
   public int luas()  
   {  
     return p * l;  
   }  
   public int kel()  
   {  
     return 2 * (p + l);  
   }  
 }  

7. Lingkaran

 public class Lingkaran  
 {  
   public double r;  
   public double luas()  
   {  
     return 3.14159 * r * r;  
   }  
   public double kel()  
   {  
     return 2 * 3.14159 * r;  
   }  
 }  


Output :



Minggu, 02 September 2018

Kuliah minggu ke-2 PBO hari ini, kelas kami mempelajari tentang bagaimana cara membuat program menggunakan java. Disini aplikasi yang kami gunakan adalah BlueJ, kami juga mempelajari cara menuliskan code tentang identitas diri saya. Berikut adalah source code dan juga output program saya

 /**  
  * Write a description of class PBOATugas1 here.  
  * PBO A Tugas 1  
  * @author Timothyus Tanner  
  * @version (a version number or a date)  
  */  
 public class PBOATugas1  
 {  
   // instance variables - replace the example below with your own  
   private int x;  
   /**  
    * Constructor for objects of class PBOATugas1  
    */  
   public PBOATugas1()  
   {  
     // initialise instance variables  
     System.out.println("Tugas #PBOA-Tugas1");  
     System.out.println("==================");  
     System.out.println("Nama\t\t: Timothyus Tanner");  
     System.out.println("Kelas\t\t: PBO A");  
     System.out.println("Alamat Rumah\t: Jl. Pandan Raya 19, Wates, Mojokerto");  
     System.out.println("Email\t\t: timothyustanner66@gmail.com");  
     System.out.println("Blog\t\t: http://timtim66.blogspot.com/");  
     System.out.println("No HP/ WA\t: 081559930107");  
     System.out.println("Twitter\t\t: @TimothyusTanner");  
   }  
 }