Sabtu, 22 September 2018

Tugas 4 PBO A - Remote AC

Nama : Nadia Hasna Luthfianita
NRP   : 05111740000077




1. Main


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

2. RemoteAC

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

Gambar awal remote


Fungsi Menurunkan suhu


Fungsi Menaikkan Suhu


Fungsi Mengubah Mode


Fungsi Mengubah Swing (On/Off)



Minggu, 16 September 2018

Tugas 4 PBO A

Nama : Nadia Hasna Luthfianita
NRP   : 05111740000077
Kelas  : PBO A

Ticket Machine

 /**  
 * TicketMachine models a ticket machine that issues  
 * flat-fare tickets.  
 * The price of a ticket is specified via the constructor.  
 * Instances will check to ensure that a user only enters  
 * sensible amounts of money, and will only print a ticket  
 * if enough money has been input.  
 */  
 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.  
   */  
     public TicketMachine(int cost)  
     {  
       price = cost;  
       balance = 20;  
       total = 20;  
     }  
    /**  
    * 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.  
    * Check that the amount is sensible.  
    */  
     public void insertMoney(int amount)  
     {  
       if(amount > 0) {  
         balance = balance + amount;  
       }  
       else {  
         System.out.println("Use a positive amount rather than: " + amount);  
       }  
     }  
    /**  
    * Print a ticket if enough money has been inserted, and  
    * reduce the current balance by the ticket price. Print  
    * an error message if more money is required.  
    */  
     public void printTicket()  
     {  
       if(balance >= price) {  
         // Simulate the printing of a ticket.  
         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 price.  
         total = total + price;  
         // Reduce the balance by the price.  
         balance = balance - price;  
       }  
       else {  
         System.out.println("You must insert at least: " + (price - balance) + " cents.");  
       }  
     }  
     /**  
     * Return the money in the balance.  
     * The balance is cleared.  
     */  
      public int refundBalance()  
      {  
        int amountToRefund;  
        amountToRefund = balance;  
        balance = 0;  
        return amountToRefund;  
       }  
 }  

input 1

output 1

input 2

output 2

input 3

output 3




Tugas 3 PBO A

Nama: Nadia Hasna Luthfianita
NRP: 05111740000077
Kelas: PBO A


1. Picture

  
 public class Picture  
 {  
   private Square wall;  
   private Square window;  
   private Triangle roof;  
   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()  
   {  
     wall = new Square();  
     wall.moveVertical(80);  
     wall.changeSize(100);  
     wall.makeVisible();  
     window = new Square();  
     window.changeColor("black");  
     window.moveHorizontal(20);  
     window.moveVertical(100);  
     window.makeVisible();  
     roof = new Triangle();  
     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("green");  
       sun.changeColor("yellow");  
     }  
   }  
 }  

2. Triangle

 
 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 = "blue";  
     isVisible = false;  
   }  
   /**  
    * Make this triangle visible. If it was already visible, do nothing.  
    */  
   public void makeVisible()  
   {  
     isVisible = true;  
     draw();  
   }  
   /**  
    * Make this triangle invisible. If it was already invisible, do nothing.  
    */  
   public void makeInvisible()  
   {  
     erase();  
     isVisible = false;  
   }  
   /**  
    * Move the triangle a few pixels to the right.  
    */  
   public void moveRight()  
   {  
     moveHorizontal(20);  
   }  
   /**  
    * Move the triangle a few pixels to the left.  
    */  
   public void moveLeft()  
   {  
     moveHorizontal(-20);  
   }  
   /**  
    * Move the triangle a few pixels up.  
    */  
   public void moveUp()  
   {  
     moveVertical(-20);  
   }  
   /**  
    * Move the triangle a few pixels down.  
    */  
   public void moveDown()  
   {  
     moveVertical(20);  
   }  
   /**  
    * Move the triangle horizontally by 'distance' pixels.  
    */  
   public void moveHorizontal(int distance)  
   {  
     erase();  
     xPosition += distance;  
     draw();  
   }  
   /**  
    * Move the triangle vertically by 'distance' pixels.  
    */  
   public void moveVertical(int distance)  
   {  
     erase();  
     yPosition += distance;  
     draw();  
   }  
   /**  
    * Slowly move the triangle horizontally by 'distance' pixels.  
    */  
   public void slowMoveHorizontal(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       xPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Slowly move the triangle vertically by 'distance' pixels.  
    */  
   public void slowMoveVertical(int distance)  
   {  
     int delta;  
     if(distance < 0)   
     {  
       delta = -1;  
       distance = -distance;  
     }  
     else   
     {  
       delta = 1;  
     }  
     for(int i = 0; i < distance; i++)  
     {  
       yPosition += delta;  
       draw();  
     }  
   }  
   /**  
    * Change the size to the new size (in pixels). Size must be >= 0.  
    */  
   public void changeSize(int newHeight, int newWidth)  
   {  
     erase();  
     height = newHeight;  
     width = newWidth;  
     draw();  
   }  
   /**  
    * Change the color. Valid colors are "red", "yellow", "blue", "green",  
    * "magenta" and "black".  
    */  
   public void changeColor(String newColor)  
   {  
     color = newColor;  
     draw();  
   }  
   /*  
    * Draw the triangle with current specifications on screen.  
    */  
   private void draw()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       int[] xpoints = { xPosition, xPosition + (width/2), xPosition - (width/2) };  
       int[] ypoints = { yPosition, yPosition + height, yPosition + height };  
       canvas.draw(this, color, new Polygon(xpoints, ypoints, 3));  
       canvas.wait(10);  
     }  
   }  
   /*  
    * Erase the triangle on screen.  
    */  
   private void erase()  
   {  
     if(isVisible) {  
       Canvas canvas = Canvas.getCanvas();  
       canvas.erase(this);  
     }  
   }  
 }  

3. Square

 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);  
     }  
   }  
 }  

4. Circle

 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 = 70;  
     xPosition = 20;  
     yPosition = 60;  
     color = "green";  
     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);  
     }  
   }  
 }  

5. Canvas

 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);  
     }  
   }  
 }  



Hasil

Senin, 10 September 2018

Tugas 2 PBO A

Nama : Nadia Hasna Luthfianita
NRP   : 05111740000077



1. Main

 /**  
  * @author Nadia Hasna  
  * @version 10/09/2018  
  */  
 class MyMain  
 {   
   public static void main(String args[])   
   {   
    Persegi aPersegi;   
    aPersegi = new Persegi();   
    aPersegi.x = 10;   
    double areaPersegi = aPersegi.area();   
    double circumfPersegi = aPersegi.circumference();   
    System.out.println("Persegi");   
    System.out.println("Sisi="+aPersegi.x);   
    System.out.println("Luas="+areaPersegi);   
    System.out.println("Keliling="+circumfPersegi+ "\n");    
    Segitiga aSegitiga;   
    aSegitiga = new Segitiga();   
    aSegitiga.a = 10;   
    aSegitiga.t = 8;   
    double areaSegitiga = aSegitiga.area();   
    double circumfSegitiga = aSegitiga.circumference();   
    System.out.println("Segitiga Sama Sisi");   
    System.out.println("Alas="+aSegitiga.a+ " Tinggi="+aSegitiga.t);   
    System.out.println("Luas="+areaSegitiga);   
    System.out.println("Keliling="+circumfSegitiga+ "\n");    
    Persegipanjang aPersegipanjang;   
    aPersegipanjang = new Persegipanjang();   
    aPersegipanjang.x = 10;   
    aPersegipanjang.y = 15;   
    double areaPersegipanjang = aPersegipanjang.area();   
    double circumfPersegipanjang = aPersegipanjang.circumference();   
    System.out.println("Persegi Panjang");   
    System.out.println("Sisi x="+aPersegipanjang.x+ " Sisi y="+aPersegipanjang.y);   
    System.out.println("Luas="+areaPersegipanjang);   
    System.out.println("Keliling="+circumfPersegipanjang+ "\n");   
    Belahketupat aBelahketupat;   
    aBelahketupat = new Belahketupat();   
    aBelahketupat.d1 = 6;   
    aBelahketupat.d2 = 8;   
    aBelahketupat.s = 5;   
    double areaBelahketupat = aBelahketupat.area();   
    double circumfBelahketupat = aBelahketupat.circumference();   
    System.out.println("Belah Ketupat");   
    System.out.println("Diagonal 1="+aBelahketupat.d1+ " Diagonal 2="+aBelahketupat.d2+ " Sisi="+aBelahketupat.s);   
    System.out.println("Luas="+areaBelahketupat);   
    System.out.println("Keliling="+circumfBelahketupat+ "\n");    
    Jajargenjang aJajargenjang;   
    aJajargenjang = new Jajargenjang();   
    aJajargenjang.a = 16;   
    aJajargenjang.b = 28;   
    aJajargenjang.t = 8.14;   
    double areaJajargenjang = aJajargenjang.area();   
    double circumfJajargenjang = aJajargenjang.circumference();   
    System.out.println("Jajar Genjang");   
    System.out.println("Alas="+aJajargenjang.a+ " Sisi miring="+aJajargenjang.b+ " Tinggi="+aJajargenjang.t);   
    System.out.println("Luas="+areaJajargenjang);   
    System.out.println("Keliling="+circumfJajargenjang+ "\n");   
   }   
  }   



2. Persegi

 /**  
  *  
  * @author Nadia Hasna  
  * @version 10/09/2018  
  */  
 public class Persegi  
 {  
   public double x;  
   public double circumference()  
   {  
     return 4*x;  
   }  
   public double area()  
   {  
     return x*x;  
   }  
 }  



3. Segitiga

 /**  
  *  
  * @author Nadia Hasna  
  * @version 10/09/2018  
  */  
 public class Segitiga  
 {  
   public double a, t;  
   public double circumference()  
   {  
     return a*3;  
   }  
   public double area()  
   {  
     return 1/2*(a*t);  
   }  
 }  



4. Persegi Panjang

 /**  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 public class Persegipanjang  
 {  
   public double x, y;  
   public double circumference()  
   {  
     return (2*x)*2;  
   }  
   public double area()  
   {  
     return x*y;  
   }  
 }  



5. Belah Ketupat

 /**  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 public class Belahketupat  
 {  
   public double d1, d2, s;  
   public double circumference()  
   {  
     return 4*s;  
   }  
   public double area()  
   {  
     return 1/2*(d1*d2);  
   }  
 }  



6. Jajar Genjang

 /**  
  *  
  * @author (your name)  
  * @version (a version number or a date)  
  */  
 public class Jajargenjang  
 {  
   public double a, b, t;  
   public double circumference()  
   {  
     return 2*(a+b);  
   }  
   public double area()  
   {  
     return a*t;  
   }  
 }  

Hasil:


Senin, 03 September 2018

Tugas 1 Pemograman Web



 <!DOCTYPE html>  
 <html>  
 <head>  
 <title>TUGAS PEWEB</title>  
 </head>  
 <body background = "gambar1.jpg">  
 <body>  
 <h1 align="center"> Homepage Saya </h1>  
 <marquee>FAKULTAS TEKNOLOGI INFORMASI DAN KOMUNIKASI INSTITUT TEKNOLOGI SEPULUH NOPEMBER SURABAYA</marquee>  
 <br>  
 <hr align="nilai">  
 <br>  
 <h1 align="center">BIODATA DIRI</h1>  
 <table width="745" border="1" cellspacing="0" cellpadding="5" align="center">  
 <tr align="center" bgcolor="brown">  
 <td width="174">DATA DIRI</td>  
 <td width="353">KETERANGAN</td>  
 <td width+"232">FOTO</td>  
 </tr>  
 <tr>  
 <td><b>Nama</b></td>  
 <td>Nadia Hasna Luthfianita</td>  
 <td rowspan="10" align="center"><img src="gambar2.jpg" width="210" height="313"  
 </tr>  
 <tr>  
 <td><b>Jurusan</b></td>  
 <td>Informatika</td>  
 </tr>  
 <tr>  
 <td><b>Semester</b></td>  
 <td>3(tiga)</td>  
 </tr>  
 <tr>  
 <td><b>NRP</b></td>  
 <td>05111740000077</td>  
 </tr>  
 <tr>  
 <td><b>Asal Sekolah</b></td>  
 <td>SMA Al-Izzah Batu</td>  
 </tr>  
 <tr>  
 <td><b>Jenis Kelamin</b></td>  
 <td>Perempuan</td>  
 </tr>  
 <tr>  
 <td><b>TTL</b></td>  
 <td>Pekalongan, 3 April 1999</td>  
 </tr>  
 <tr>  
 <td><b>Alamat</b></td>  
 <td>Perum Wikarsa Baru no. 13A Mojokerto</td>  
 </tr>  
 <tr>  
 <td><b>Status</b></td>  
 <td>Pelajar/Mahasiswa</td>  
 </tr>  
 <tr>  
 <td><b>Hobi</b></td>  
 <td>Membaca buku, Trevelling</td>  
 </tr>  
 </table>  
 </body>  
 </html>  

nn

Tugas 1 PBO A



Selamat datang.

 /**  
  * Write a description of class helloword1 here.  
  *  
  * @author (Nadia Hasna L)  
  * @version (20180903)  
  */  
 public class helloword1  
 {  
   // instance variables - replace the example below with your own  
   private int x;  
   /**  
    * Constructor for objects of class helloword1  
    */  
   public helloword1()  
   {  
     // initialise instance variables  
     x = 0;  
     System.out.println("Nama : Nadia Hasna Luthfianita");  
     System.out.println("Kelas: PBO A");  
     System.out.println("Alamat: Perumdos Blok U");  
     System.out.println("Email : nadiahasna34@gmail.com");  
     System.out.println("Blog : Kumpulan Tugas Kuliah");  
     System.out.println("No HP/WA : 081136116131");  
     System.out.println("Twitter : @NadiaHasna15");  
   }  
   /**  
    * 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;  
   }  
 }  




Terima kasih.