Advertisement
Ramdan51-062

CicleTest

Oct 12th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.21 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class CircleTest
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         Scanner scan = new Scanner(System.in);
  7.         boolean exit = false;
  8.         int menu, command;
  9.         double rad;
  10.         Circle circ = new Circle();
  11.         String col = new String();
  12.         System.out.print("Choose your circle:\n");
  13.         System.out.print("1. Default\n");
  14.         System.out.print("2. Custom radius\n");
  15.         System.out.print("3. Custom radius and color\n");
  16.         menu = scan.nextInt();
  17.         switch(menu)
  18.         {
  19.             case 1:
  20.             Circle circle = new Circle();
  21.             System.out.print("Circle created!\n");
  22.             System.out.print("Your circle:\n");
  23.             System.out.print("Radius: "+ circle.getRadius() + "\n");
  24.             System.out.println("Color: "+circle.getColor());
  25.             circ = circle;
  26.             break;
  27.             case 2:
  28.             System.out.print("Enter your radius: ");
  29.             rad = scan.nextDouble();
  30.             Circle circle2 = new Circle(rad);
  31.             System.out.print("Circle created!\n");
  32.             System.out.print("Your circle:\n");
  33.             System.out.print("Radius: "+ circle2.getRadius() + "\n");
  34.             System.out.println("Color: "+circle2.getColor());
  35.             circ = circle2;
  36.             break;
  37.             case 3:
  38.             System.out.print("Enter your color: ");
  39.             col = scan.nextLine();
  40.             System.out.print("Enter your radius: ");            
  41.             rad = scan.nextDouble();
  42.             Circle circle3 = new Circle(rad, col);
  43.             System.out.print("Circle created!\n");
  44.             System.out.print("Your circle:\n");
  45.             System.out.print("Radius: "+ circle3.getRadius() + "\n");
  46.             System.out.println("Color: "+circle3.getColor());
  47.             circ = circle3;
  48.             break;
  49.         }
  50.        
  51.         while(!exit)
  52.         {
  53.             System.out.print("Choose your command:\n");
  54.             System.out.print("1. Show circle area.\n");
  55.             System.out.print("2. Change radius.\n");
  56.             System.out.print("3. Change color.\n");
  57.             System.out.println("4. Exit.");
  58.             command = scan.nextInt();
  59.             switch(command)
  60.             {
  61.                 case 1:
  62.                 System.out.println("Area : " + circ.getArea());
  63.                 break;
  64.                 case 2:
  65.                 System.out.print("New radius : ");
  66.                 rad = scan.nextDouble();
  67.                 circ.setRadius(rad);
  68.                 System.out.print("Your circle:\n");
  69.                 System.out.print("Radius: "+ circ.getRadius() + "\n");
  70.                 System.out.println("Color: "+circ.getColor());
  71.                 break;
  72.                 case 3:
  73.                 System.out.print("New color : ");
  74.                 col = scan.nextLine();
  75.                 circ.setColor(col);
  76.                 System.out.print("Your circle:\n");
  77.                 System.out.print("Radius: "+ circ.getRadius() + "\n");
  78.                 System.out.println("Color: "+circ.getColor());
  79.                 break;
  80.                 case 4:
  81.                 exit = true;
  82.                 break;
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement