SHARE
TWEET

Untitled

a guest May 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                 sc.nextLine();
  25.             }
  26.             else if (choice.equalsIgnoreCase("SQUARE")) {
  27.                 System.out.println("Please enter the arm");
  28.                 int op = sc.nextInt();
  29.                 sh = shapeFactory.getShape("Square", op, 0, 0);
  30.                 /*sh.display();
  31.                 sh.draw();
  32.                 sh.surface_area();
  33.                 sh.perimeter();*/
  34.  
  35.                 sc.nextLine();
  36.             }
  37.             else if (choice.equalsIgnoreCase("RECTANGLE")) {
  38.                 System.out.println("Please enter the length and width");
  39.                 int op = sc.nextInt();
  40.                 int op2 = sc.nextInt();
  41.                 sh = shapeFactory.getShape("Rectangle", op, op2, 0);
  42.                 /*sh.display();
  43.                 sh.draw();
  44.                 sh.surface_area();
  45.                 sh.perimeter();*/
  46.  
  47.                 sc.nextLine();
  48.             }
  49.             else if (choice.equalsIgnoreCase("TRIANGLE")) {
  50.                 System.out.println("Please enter three arms");
  51.                 int op = sc.nextInt();
  52.                 int op2 = sc.nextInt();
  53.                 int op3 = sc.nextInt();
  54.                 sh = shapeFactory.getShape("Triangle", op, op2, op3);
  55.                 /*sh.display();
  56.                 sh.draw();
  57.                 sh.surface_area();
  58.                 sh.perimeter();*/
  59.  
  60.                 sc.nextLine();
  61.             }
  62.             else if(choice.equalsIgnoreCase("BREAK"))
  63.             {
  64.                 break;
  65.             }
  66.             sh.display();
  67.             sh.draw();
  68.             sh.surface_area();
  69.             sh.perimeter();
  70.         }
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top