BenitoDannes

PBO-4.2-2 RectangleMain

Mar 20th, 2017
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. /**
  2.  * Input dan output dari program.
  3.  * Memasukkan besar panjang dan lebar dari persegi panjang.
  4.  * Output berupa luas dan keliling dari persegi panjang.
  5.  *
  6.  * Benito Dannes
  7.  */
  8.  
  9. import java.util.Scanner;
  10.  
  11. public class Main
  12. {
  13.     public static void main (String[] args)
  14.     {
  15.         String l,w;
  16.         String color = "";
  17.         int length, width;
  18.        
  19.         Scanner s = new Scanner (System.in);
  20.        
  21.         System.out.print ("Enter rectangle's color: ");
  22.         color = s.nextLine();
  23.         System.out.print ("Enter rectangle's length: ");
  24.         l = s.nextLine();
  25.         System.out.print ("Enter rectangle's width: ");
  26.         w = s.nextLine();
  27.        
  28.         if (color.isEmpty())
  29.         {
  30.             if (l.isEmpty() && w.isEmpty())
  31.             {
  32.                 Rectangle r = new Rectangle();
  33.                 System.out.println (r.toString());
  34.                 System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference());
  35.             }
  36.             else
  37.             {
  38.                 if (l.isEmpty() || w.isEmpty())
  39.                 {
  40.                     System.out.println ("Both length and width must be filled!");
  41.                 }
  42.                 else
  43.                 {
  44.                     length = Integer.parseInt(l);
  45.                     width = Integer.parseInt(w);
  46.                     Rectangle r = new Rectangle (length, width);
  47.                     System.out.println (r.toString());
  48.                     System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference());
  49.                 }
  50.             }
  51.         }
  52.         else
  53.         {
  54.             if (l.isEmpty() || w.isEmpty())
  55.             {
  56.                 System.out.println ("Make sure you fill both length and width if you fill the color!");
  57.             }
  58.             else
  59.             {
  60.                 length = Integer.parseInt(l);
  61.                 width = Integer.parseInt(w);
  62.                 Rectangle r = new Rectangle (color, length, width);
  63.                 System.out.println (r.toString());
  64.                 System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference());
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment