BenitoDannes

PBO-4.1-2 Circle-Main

Mar 20th, 2017
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1.  
  2. /**
  3. * Input dan output dari program.
  4. * Menginput besar jari-jari dan warna lingkaran.
  5. * Output berupa kalimat yang berisi luas dan warna lingkaran.
  6. *
  7. * Benito Dannes
  8. */
  9.  
  10. import java.util.Scanner;
  11.  
  12. public class Main
  13. {
  14. public static void main (String[] args)
  15. {
  16. String r;
  17. String color = "";
  18. int radius;
  19.  
  20. Scanner s = new Scanner (System.in);
  21. System.out.print ("Enter circle's color : ");
  22. color = s.nextLine();
  23. System.out.print ("Enter radius of circle: ");
  24. r = s.nextLine();
  25.  
  26. if (color.isEmpty())
  27. {
  28. if (r.isEmpty())
  29. {
  30. Circle c = new Circle();
  31. System.out.println (c.toString());
  32. System.out.printf ("The circle's area is %.2f and the circumference is %.2f", c.getArea(), c.getCircumference());
  33. }
  34. else
  35. {
  36. radius = Integer.parseInt(r);
  37. Circle c = new Circle(radius);
  38. System.out.println (c.toString());
  39. System.out.printf ("The circle's area is %.2f and the circumference is %.2f", c.getArea(), c.getCircumference());
  40. }
  41. }
  42. else
  43. {
  44. if (r.isEmpty())
  45. {
  46. System.out.println ("Jika warna diisi, panjang jari-jari lingkaran juga harus terisi");
  47. }
  48. else
  49. {
  50. radius = Integer.parseInt(r);
  51. Circle c = new Circle(radius, color);
  52. System.out.println (c.toString());
  53. System.out.printf ("The circle's area is %.2f and the circumference is %.2f", c.getArea(), c.getCircumference());
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment