Minggu, 30 September 2018

Tugas PBO B Digital Clock

Nama: Chrisnady Anggaiswara
NRP:  5111640000153
Kelas: PBO B

Disini ada 2 class yang digunakan, yaitu class DigitalClock untuk menjalankan programnya, dan class ClockLabel untuk menampilkan waktunya. Berikut source codenya:


1. Digital Clock


 /**  
  * Executioner program  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (1)  
  */  
 import java.awt.Font;  
 import java.awt.Color;  
 import java.awt.GridLayout;  
 import java.awt.event.ActionEvent;  
 import java.awt.event.ActionListener;  
 import javax.swing.JFrame;  
 import javax.swing.JLabel;  
 import javax.swing.Timer;  
 import javax.swing.SwingConstants;  
 import java.util.*;  
 import java.text.*;  
 public class DigitalClock {  
  public static void main(String[] arguments) {  
   ClockLabel dateLable = new ClockLabel("date");  
   ClockLabel timeLable = new ClockLabel("time");  
   ClockLabel dayLable = new ClockLabel("day");  
   JFrame.setDefaultLookAndFeelDecorated(true);  
   JFrame f = new JFrame("Digital Clock");  
   f.setSize(300,150);  
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
   f.setLayout(new GridLayout(3, 1));  
   f.add(timeLable);  
   f.getContentPane().setBackground(Color.black);  
   f.setVisible(true);  
  }  
 }  

2. ClockLabel


 /**  
  * LabelClock/CLock program  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (1)  
  */  
 import java.awt.Font;  
 import java.awt.Color;  
 import java.awt.GridLayout;  
 import java.awt.event.ActionEvent;  
 import java.awt.event.ActionListener;  
 import javax.swing.JFrame;  
 import javax.swing.JLabel;  
 import javax.swing.Timer;  
 import javax.swing.SwingConstants;  
 import java.util.*;  
 import java.text.*;  
 class ClockLabel extends JLabel implements ActionListener {  
  String type;  
  SimpleDateFormat sdf;  
  public ClockLabel(String type) {  
   this.type = type;  
   setForeground(Color.green);  
   switch (type) {  
    case "time" : sdf = new SimpleDateFormat("hh:mm:ss a");  
           setFont(new Font("sans-serif", Font.PLAIN, 40));  
           setHorizontalAlignment(SwingConstants.CENTER);  
           break;  
    default   : sdf = new SimpleDateFormat();  
           break;  
   }  
   Timer t = new Timer(1000, this);  
   t.start();  
  }  
  public void actionPerformed(ActionEvent ae) {  
   Date d = new Date();  
   setText(sdf.format(d));  
  }  
 }  

3.Hasil Jam
















Minggu, 23 September 2018

Tugas Membuat Remote TV

Hari ini membuat post tentang tugas remote TV,remote TV yang saya buat hanya sederhana seperti tugas sebelumnya,semoga dapat dipahami.

Chrisnady Anggaiswara
5111640000153
PBO-B

     1.Screenshot Hasil dan Class

































     2.Main


 import java.util.Scanner;    
  /**   
  * Menjalankan Remot TV   
  *   
  * @author (Chrisnady Anggaiswara)   
  * @version (8.2/23092018)   
  */   
  public class Main   
  {   
   public static void main(String args[]){    
   Scanner scan= new Scanner(System.in);    
   int jumlahvolume,jumlahchannel, menu;    
   boolean entry;    
   System.out.println("|=============================|");   
   System.out.println("|      Welcome To    |");   
   System.out.println("|    Chris Angga TV    |");   
   System.out.println("|=============================|");   
   System.out.println("Masukkan Volume Saat Ini : ");    
   jumlahvolume = scan.nextInt();    
   System.out.println("|=============================|");   
   System.out.println("Masukkan Channel Saat Ini : ");    
   jumlahchannel = scan.nextInt();    
   System.out.println("|=============================|");   
   Remote KS = new Remote(jumlahvolume,jumlahchannel);    
   entry = true;    
   while(entry) {    
    System.out.println("Daftar Menu :");    
    System.out.println("1. Volume Saat Ini");    
    System.out.println("2. Channel Saat Ini");    
    System.out.println("3. Naikkan Volume");    
    System.out.println("4. Turunkan Volume");    
    System.out.println("5. Naikkan Channel");   
    System.out.println("6. Turunkan Channel");   
    System.out.println("7. Exit");    
    System.out.println("Menu Yang Dipilih : ");   
    menu=scan.nextInt();    
    System.out.println("|=============================|");   
    switch(menu){    
    case 1:    
     jumlahvolume=KS.GetVolume();    
     System.out.println("Volume Saat Ini : "+jumlahvolume);    
     System.out.println("|=============================|");   
     break;    
    case 2:    
     jumlahchannel = KS.GetChannel();   
     if(jumlahchannel == 1){   
      System.out.println("|=============================|");   
      System.out.println("|      FFFTV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
     }   
     else if(jumlahchannel == 2){   
      System.out.println("|=============================|");   
      System.out.println("|      RRTI       |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");  
      System.out.println("");   
     }   
     else if(jumlahchannel == 3){   
      System.out.println("|=============================|");   
      System.out.println("|      SOMY TV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    } else{   
      System.out.println("|=============================|");   
      System.out.println("|      NotFound     |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    }   
     System.out.println("|=============================|");  
     break;    
    case 3:    
     KS.TambahVolume();   
     System.out.println("|=============================|");   
     break;    
    case 4:    
     KS.KurangVolume();    
     System.out.println("|=============================|");   
     break;    
    case 5:    
     jumlahchannel = KS.TambahChannel();    
     if(jumlahchannel == 1){   
      System.out.println("|=============================|");   
      System.out.println("|      FFFTV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
     }   
     else if(jumlahchannel == 2){   
      System.out.println("|=============================|");   
      System.out.println("|      RRTI       |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");  
      System.out.println("");   
     }   
     else if(jumlahchannel == 3){   
      System.out.println("|=============================|");   
      System.out.println("|      SOMY TV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    } else{   
      System.out.println("|=============================|");   
      System.out.println("|      NotFound     |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    }   
     System.out.println("|=============================|");  
     break;    
    case 6:    
     jumlahchannel = KS.KurangChannel();    
     if(jumlahchannel == 1){   
      System.out.println("|=============================|");   
      System.out.println("|      FFFTV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
     }   
     else if(jumlahchannel == 2){   
      System.out.println("|=============================|");   
      System.out.println("|      RRTI       |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");  
      System.out.println("");   
     }   
     else if(jumlahchannel == 3){   
      System.out.println("|=============================|");   
      System.out.println("|      SOMY TV      |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    } else{   
      System.out.println("|=============================|");   
      System.out.println("|      NotFound     |");   
      System.out.println("|  Channel Saat ini : "+jumlahchannel+"   |");    
      System.out.println("|=============================|");   
    }   
     System.out.println("|=============================|");  
     break;    
    case 7:    
     System.out.println("|   TV Telah Dimatikan   |");   
     System.out.println("|=============================|");   
     entry = false;    
     break;    
    }    
   }    
   }    
  }   

     3.Remote


 import java.util.Scanner;    
  /**   
  * Remot TV   
  *   
  * @author (Chrisnady Anggaiswara)   
  * @version (8.1/20092018)   
  */   
  public class Remote   
  {   
   private int volume;   
   private int channel;   
   public Remote(int jumlahvolume,int jumlahchannel){   
    volume = jumlahvolume;   
    channel = jumlahchannel;   
   }   
   public int GetVolume(){   
    return volume;   
   }   
   public int GetChannel(){   
    return channel;  
   }   
   public void TambahVolume()   
   {   
    if(volume == 15){   
     System.out.println("Volumenya Sudah Full Kak :(");   
    }   
    else{   
    volume= volume+1;   
    System.out.println("Volumenya Saat ini : "+volume);   
   }   
   }   
   public void KurangVolume()   
   {   
    if(volume == 0){   
     System.out.println("Volumenya Sudah 0 Kak :(");   
    }   
    else{   
    volume= volume-1;   
    System.out.println("Volumenya Saat ini : "+volume);   
   }   
   }   
   public int TambahChannel()   
   {   
    channel = channel+1;   
    return channel;   
   }   
   public int KurangChannel()   
   {   
    channel = channel-1;   
    return channel;   
   }   
  }   

Thank You

Senin, 17 September 2018

Tugas Ticket Machine

Simple program ticket machine PBO kelas B.

     1. Class Window













     2. Ticket Machine


  /**  
  * Ticket Machine  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (17 September 2018)  
  */  
  public class TicketMachine   
   {   
     // The price of a ticket from this machine.   
     private int price;   
     // The amount of money entered by a customer so far.   
     private int balance;   
     // The total amount of money collected by this machine.   
     private int total;   
     //buy ticket  
     private int Buy;  
     //sell ticket  
     private int Sell;  
     /**   
       * 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()   
     {   
       System.out.println(+ balance + " cents.");  
       return balance;  
     }   
     /**   
     * Receive an amount of money in cents from a customer.   
      */   
     public void insertMoney(int amount)   
     {    
       if(amount > 0){   
         balance = balance + amount;  
       }  
       else{  
       System.out.println("Use a Positive amounts:" + amount);  
       }  
     }  
     public void Buy()   
     {   
      if(balance>=price){  
        balance = balance - price;  
      System.out.println(+ balance + " cents.");  
       }  
       else {  
       System.out.println("Insufficient Money");  
       }  
     }   
      public void Sell()   
     {   
        balance = balance + price;  
        System.out.println(+ balance + " cents.");  
     }   
     /**   
     * Print a ticket.   
     * Update the total collected and   
     * reduce the balance to zero.   
      */   
     public void printTicket()   
     {   
      // Simulate the printing of a ticket.   
     if(balance>=price){  
     System.out.println("##################");   
     System.out.println("# The BlueJ Line");   
     System.out.println("# Ticket");   
     System.out.println("# " + price + " cents.");   
     System.out.println("##################");   
     System.out.println();   
     // Update the total collected with the balance.   
     total = total + balance;  
     balance = balance -price;  
     }  
     else{  
     System.out.println("You must insert at least:" +(price-balance)+  
     " more cents.");  
     }  
     // Clear the balance.   
     }   
  }   

     3. Main


   import java.util.Scanner;  
 /**  
  * Main untuk program Ticket Machine  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (17 September 2018)  
  */  
 public class intMain  
 {   
  public static void main(String args[])   
  {   
  Scanner scan= new Scanner(System.in);   
  int cost,menu;  
  menu = 0;  
  System.out.println("Masukkan harga tiket \n");   
  cost=scan.nextInt();   
  TicketMachine ticket= new TicketMachine(cost);  
  while (menu!=7){  
   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. Buy Ticket");  
  System.out.println("6. Sell Ticket");  
  System.out.println("7. Exit");  
  menu=scan.nextInt();   
  switch(menu)   
  {   
   case 1:   
   cost=ticket.getPrice();   
   System.out.println(cost);    
   break;  
   case 2:   
   ticket.getBalance();    
   break;  
   case 3:   
   int money=scan.nextInt();   
   ticket.insertMoney(money);    
   break;  
   case 4:   
   ticket.printTicket();   
   break;  
   case 5:  
   ticket.Buy();  
   break;  
   case 6:  
   ticket.Sell();  
   break;  
   case 7:  
   break;  
  }   
   }  
  }    
 }  

     4. Hasil Screenshot Program



Minggu, 16 September 2018

PBO B Tugas Pemandangan

Komponen kelas yang dibutuhkan :

  1. Picture (Untuk menampilkan keseluruhan gambar)
  2. Canvas (Sebagai media untuk menggambar)
  3. Circle (Bentuk gambar lingkaran)
  4. Square (Bentuk gambar persegi)
  5. Triangle (Bentuk gambar segitiga)

Source code untuk masing-masing kelas


     1.Picture


 /**  
  * This class represents a simple picture. You can draw the picture using  
  * the draw method. But wait, there's more: being an electronic picture, it  
  * can be changed. You can set it to black-and-white display and back to  
  * colors (only after it's been drawn, of course).  
  *  
  * This class was written as an early example for teaching Java with BlueJ.  
  *   
  * @author Chrisnady Anggaiswara  
  * @version 1.1 (16 September 2018)  
  */  
 public class Picture  
 {  
   private Square wall;  
   private Square road;  
   private Square road1;  
   private Square window;  
   private Square window1;  
   private Triangle roof;  
   private Triangle land;  
   private Triangle mountain;  
   private Triangle mountain1;  
   private Triangle mountain2;  
   private Circle sun;  
   /**  
    * Constructor for objects of class Picture  
    */  
   public Picture()  
   {  
     // nothing to do... instance variables are automatically set to null  
   }  
   /**  
    * Draw this picture.  
    */  
   public void draw()  
   {  
     mountain = new Triangle();  
     mountain.changeColor("green");  
     mountain.changeSize(70,200);  
     mountain.moveHorizontal(10);  
     mountain.moveVertical (100);  
     mountain.makeVisible();  
     mountain1 = new Triangle();  
     mountain1.changeColor("green");  
     mountain1.changeSize(70,200);  
     mountain1.moveHorizontal(100);  
     mountain1.moveVertical (100);  
     mountain1.makeVisible();  
     mountain2 = new Triangle();  
     mountain2.changeColor("green");  
     mountain2.changeSize(70,200);  
     mountain2.moveHorizontal(190);  
     mountain2.moveVertical (100);  
     mountain2.makeVisible();  
     land = new Triangle();  
     land.changeColor("green");  
     land.changeSize(30,600);  
     land.moveHorizontal(40);  
     land.moveVertical (210);  
     land.makeVisible();  
     road = new Square();  
     road.changeColor("black");  
     road.moveVertical(150);  
     road.moveHorizontal(30);  
     road.changeSize(50);  
     road.makeVisible();  
     road1 = new Square();  
     road1.changeColor("black");  
     road1.moveVertical(200);  
     road1.moveHorizontal(30);  
     road1.changeSize(50);  
     road1.makeVisible();  
     wall = new Square();  
     wall.moveVertical(80);  
     wall.changeSize(100);  
     wall.makeVisible();  
     window = new Square();  
     window.changeColor("black");  
     window.moveHorizontal(10);  
     window.moveVertical(100);  
     window.makeVisible();  
     window1 = new Square();  
     window1.changeColor("black");  
     window1.moveHorizontal(60);  
     window1.moveVertical(100);  
     window1.makeVisible();          
     roof = new Triangle();  
     roof.changeColor("blue");  
     roof.changeSize(50, 140);  
     roof.moveHorizontal(60);  
     roof.moveVertical(70);  
     roof.makeVisible();             
     sun = new Circle();  
     sun.changeColor("yellow");  
     sun.moveHorizontal(180);  
     sun.moveVertical(-10);  
     sun.changeSize(60);  
     sun.makeVisible();  
   }  
   /**  
    * Change this picture to black/white display  
    */  
   public void setBlackAndWhite()  
   {  
     if(wall != null)  // only if it's painted already...  
     {  
       wall.changeColor("black");  
       window.changeColor("white");  
       roof.changeColor("black");  
       sun.changeColor("black");  
     }  
   }  
   /**  
    * Change this picture to use color display  
    */  
   public void setColor()  
   {  
     if(wall != null)  // only if it's painted already...  
     {  
       wall.changeColor("red");  
       window.changeColor("black");  
       roof.changeColor("blue");  
       sun.changeColor("yellow");  
     }  
   }  
 }  

     2.Canvas


 import javax.swing.*;  
 import java.awt.*;  
 import java.util.List;  
 import java.util.*;  
 /**  
  * Canvas is a class to allow for simple graphical drawing on a canvas.  
  * This is a modification of the general purpose Canvas, specially made for  
  * the BlueJ "shapes" example.   
  *  
  * @author: Chrisnady Anggaiswara  
  *  
  * @version: 1.6 (16 September 2018)  
  */  
 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", 300, 300,   
           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<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 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<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 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  
       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);  
     }  
   }  
 }  

     3.Triangle


 import java.awt.*;  
 /**  
  * A triangle that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Chrisnady Anggaiswara  
  * @version 1.0 (16 September 2018)  
  */  
 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 = 50;  
     yPosition = 15;  
     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.Square


 import java.awt.*;  
 /**  
  * A square that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Chrisnady Anggaiswara  
  * @version 1.0 (16 September 2018)  
  */  
 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 = 60;  
     yPosition = 50;  
     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.Circle


 import java.awt.*;  
 import java.awt.geom.*;  
 /**  
  * A circle that can be manipulated and that draws itself on a canvas.  
  *   
  * @author Chrisnady Anggaiswara  
  * @version 1.0 (16 September 2018)  
  */  
 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 = 20;  
     yPosition = 60;  
     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);  
     }  
   }  
 }  

Hasil Screenshot Code








Senin, 10 September 2018

PBO B-TUGAS 2

Nama; Chrisnady Anggaiswara
NRP: 05111640000153
Kelas: PBO-B

Ini adalah tugas 2 PBO saya dengan mencari luas dan keliling dari bidang 3D(Kubus,Balok,Tabung,Bola) dengan membuat source code menggunakan bahasa Java. Dikelas telah belajar lingkaran dan mendapatkan tugas untuk bangun datar yang lain.

Berikut merupakan formatted source code saya:

  • Main

 /**  
  * Write a description of class myMain here.  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (1)  
  */  
 public class myMain  
 {  
   public static void main(String args[])   
   {   
     //kubus  
     Kubus aKubus;   
    aKubus = new Kubus();   
    aKubus.x = 5.0;   
    double LP = aKubus.LuasPermukaan();   
    double V = aKubus.Volume();   
    System.out.println("KUBUS");   
    System.out.println("Sisi = "+aKubus.x);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //balok  
    Balok aBalok;   
    aBalok = new Balok();   
    aBalok.x = 15.0;   
    aBalok.y = 5.0;   
    aBalok.z = 10.0;   
    LP = aBalok.LuasPermukaan();   
    V = aBalok.Volume();   
    System.out.println("BALOK");   
    System.out.println("Panjang = "+aBalok.x);   
    System.out.println("Lebar = "+aBalok.y);   
    System.out.println("Tinggi = "+aBalok.z);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //tabung  
    Tabung aTabung;   
    aTabung = new Tabung();   
    aTabung.r = 10.0;   
    aTabung.x = 20.0;   
    LP = aTabung.LuasPermukaan();   
    V = aTabung.Volume();   
    System.out.println("TABUNG");   
    System.out.println("Radius = "+aTabung.r);   
    System.out.println("Tinggi = "+aTabung.x);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
    System.out.println("==================================");   
    //bola  
    Bola aBola;   
    aBola = new Bola();   
    aBola.r = 10.0;   
    LP = aBola.LuasPermukaan();   
    V = aBola.Volume();   
    System.out.println("BOLA");   
    System.out.println("Radius = "+aBola.r);   
    System.out.println("Luas Permukaan = "+LP);   
    System.out.println("Volume = "+V);   
   }   
 }  

  • Kubus

 /**  

  * Write a description of class Kubus here.  

  *  

  * @author (Chrisnady Anggaiswara)  

  * @version (1)  

  */  

 public class Kubus   

  {   

   public double x;   

   public double LuasPermukaan()   

   {   

    return 6*x*x;   

   }   

   public double Volume()   

   {   

    return x*x*x;   

   }   

  }   


  • Balok

 /**  

  * Write a description of class Balok here.  

  *  

  * @author (Chrisnady A)  

  * @version (1)  

  */  

 public class Balok   

  {   

   public double x,y,z;    

   public double LuasPermukaan()   

   {   

    return 2*(x*y)+2*(y*z)+2*(x*z);   

   }   

   public double Volume()   

   {   

    return x*y*z;   

   }   

  }   
  • Tabung
 /**  

  * Write a description of class Tabung here.  

  *  

  * @author (Chrisnady A)  

  * @version (1)  

  */  

 public class Tabung   

  {   

   public double r;   

   public double x;   

   public double LuasPermukaan()   

   {   

    return 2*3.14*r*(r+x);   

   }   

   public double Volume()   

   {   

    return 3.14*r*r*x;   

   }   

  }  


  • Bola

 /**  

  * Write a description of class Bola here.  

  *  

  * @author (Chrisnady Anggaiswara)  

  * @version (1)  

  */  

  public class Bola   

  {   

   public double r;   

   public double LuasPermukaan()   

   {   

    return 4*3.14*r*r;   

   }   

   public double Volume()   

   {   

    // put your code here   

    return (4*3.14*r*r*r)/3;   

   }   

  }   




Gambar Denah Class dan Hasil :






















Minggu, 02 September 2018

Tugas 1 PBO-B
 /**  
  * Write a description of class Tugas1 here.  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (0.1)  
  */  
 public class Tugas1  
 {  
   // instance variables - replace the example below with your own  
   private int x;  
   /**  
    * Constructor for objects of class Tugas1  
    */  
   public Tugas1()  
   {  
     // initialise instance variables  
    x =0;  
    System.out.println("Nama          : Chrisnady Anggaiswara");   
    System.out.println("Kelas         : PBO B");   
    System.out.println("Alamat Rumah  : JL. Tuban 2 no 5,Kelurahan Jepara,Kecamatan Bubutan,Surabaya");   
    System.out.println("Email         : chrisnady99@gmail.com");   
    System.out.println("Blog          : chrisanggaif.blogspot.com");   
    System.out.println("No HP/WA      : 081938040557");   
    System.out.println("Twitter       : @KiraMorishita");   
   }  
   /**  
    * 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 sampleMethod(int y)  
   {  
     // put your code here  
     return x + y;  
   }  
 }  
Berikut Adalah Hasil Screenshot Melalui BlueJ:
PBO B hari ini membahas tentang cara mengetik 10 jari dengan benar,dengan belajar di Typing Club
tetapi terasa aneh awalmulanya,mungkin karena belum terbiasa dengan 10 jari yang sebenarnya,sejauh ini mengetik sudah bisa tanpa melihat keyboard tetapi belum 10 jari yang sesuai aturan,sudah terbiassa dengan cara ini dan bisa lebih cepat dengan cara ini daripada cara biasanya.

Dikelas juga belajar java,sejauh ini java hanya belajar sedikit lebih fokus ke C dan yang lain,mungkin memakan waktu untuk terbiasa dengan java dan perlu latihan dengan rutin.
Google