Advertisement
Guest User

Untitled

a guest
May 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.27 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class factoryPatternDemo{
  5.     public static void main(String[] args) throws FileNotFoundException{
  6.         ShapeFactory shapeFactory = new ShapeFactory();
  7.         Shape sh = null;
  8.         Scanner sc = new Scanner(new FileInputStream("in.txt"));
  9.  
  10.         while(true) {
  11.             String choice;
  12.             choice = sc.nextLine();
  13.             System.out.println(choice);
  14.  
  15.             if (choice.equalsIgnoreCase("CIRCLE")) {
  16.                 System.out.println("Please enter the radius");
  17.                 int op = sc.nextInt();
  18.                 sh = shapeFactory.getShape("Circle", op, 0, 0);
  19.                 /*sh.display();
  20.                 sh.draw();
  21.                 sh.surface_area();
  22.                 sh.perimeter();*/
  23.             }
  24.             else if (choice.equalsIgnoreCase("SQUARE")) {
  25.                 System.out.println("Please enter the arm");
  26.                 int op = sc.nextInt();
  27.                 sh = shapeFactory.getShape("Square", op, 0, 0);
  28.                 /*sh.display();
  29.                 sh.draw();
  30.                 sh.surface_area();
  31.                 sh.perimeter();*/
  32.  
  33.             }
  34.             else if (choice.equalsIgnoreCase("RECTANGLE")) {
  35.                 System.out.println("Please enter the length and width");
  36.                 int op = sc.nextInt();
  37.                 int op2 = sc.nextInt();
  38.                 sh = shapeFactory.getShape("Rectangle", op, op2, 0);
  39.                 /*sh.display();
  40.                 sh.draw();
  41.                 sh.surface_area();
  42.                 sh.perimeter();*/
  43.  
  44.             }
  45.             else if (choice.equalsIgnoreCase("TRIANGLE")) {
  46.                 System.out.println("Please enter three arms");
  47.                 int op = sc.nextInt();
  48.                 int op2 = sc.nextInt();
  49.                 int op3 = sc.nextInt();
  50.                 sh = shapeFactory.getShape("Triangle", op, op2, op3);
  51.                 /*sh.display();
  52.                 sh.draw();
  53.                 sh.surface_area();
  54.                 sh.perimeter();*/
  55.  
  56.             }
  57.             else if(choice.equalsIgnoreCase("BREAK"))
  58.             {
  59.                 break;
  60.             }
  61.             sh.display();
  62.             sh.draw();
  63.             sh.surface_area();
  64.             sh.perimeter();
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement