/** * Input dan output dari program. * Memasukkan besar panjang dan lebar dari persegi panjang. * Output berupa luas dan keliling dari persegi panjang. * * Benito Dannes */ import java.util.Scanner; public class Main { public static void main (String[] args) { String l,w; String color = ""; int length, width; Scanner s = new Scanner (System.in); System.out.print ("Enter rectangle's color: "); color = s.nextLine(); System.out.print ("Enter rectangle's length: "); l = s.nextLine(); System.out.print ("Enter rectangle's width: "); w = s.nextLine(); if (color.isEmpty()) { if (l.isEmpty() && w.isEmpty()) { Rectangle r = new Rectangle(); System.out.println (r.toString()); System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference()); } else { if (l.isEmpty() || w.isEmpty()) { System.out.println ("Both length and width must be filled!"); } else { length = Integer.parseInt(l); width = Integer.parseInt(w); Rectangle r = new Rectangle (length, width); System.out.println (r.toString()); System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference()); } } } else { if (l.isEmpty() || w.isEmpty()) { System.out.println ("Make sure you fill both length and width if you fill the color!"); } else { length = Integer.parseInt(l); width = Integer.parseInt(w); Rectangle r = new Rectangle (color, length, width); System.out.println (r.toString()); System.out.printf ("The rectangle's area is %.2f and the circumference is %.2f", r.getArea(), r.getCircumference()); } } } }