SHARE
TWEET

Untitled

a guest May 25th, 2019 73 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.                 System.out.println("HI");
  20.                 sh.display();
  21.                 sh.draw();
  22.                 sh.surface_area();
  23.                 sh.perimeter();
  24.             }
  25.             else if (choice.equalsIgnoreCase("SQUARE")) {
  26.                 System.out.println("Please enter the arm");
  27.                 int op = sc.nextInt();
  28.                 sh = shapeFactory.getShape("Square", op, 0, 0);
  29.                 sh.display();
  30.                 sh.draw();
  31.                 sh.surface_area();
  32.                 sh.perimeter();
  33.  
  34.             }
  35.             else if (choice.equalsIgnoreCase("RECTANGLE")) {
  36.                 System.out.println("Please enter the length and width");
  37.                 int op = sc.nextInt();
  38.                 int op2 = sc.nextInt();
  39.                 sh = shapeFactory.getShape("Rectangle", op, op2, 0);
  40.                 /*sh.display();
  41.                 sh.draw();
  42.                 sh.surface_area();
  43.                 sh.perimeter();*/
  44.  
  45.             }
  46.             else if (choice.equalsIgnoreCase("TRIANGLE")) {
  47.                 System.out.println("Please enter three arms");
  48.                 int op = sc.nextInt();
  49.                 int op2 = sc.nextInt();
  50.                 int op3 = sc.nextInt();
  51.                 sh = shapeFactory.getShape("Triangle", op, op2, op3);
  52.                 /*sh.display();
  53.                 sh.draw();
  54.                 sh.surface_area();
  55.                 sh.perimeter();*/
  56.  
  57.             }
  58.             else if(choice.equalsIgnoreCase("BREAK"))
  59.             {
  60.                 break;
  61.             }
  62.             /*sh.display();
  63.             sh.draw();
  64.             sh.surface_area();
  65.             sh.perimeter();*/
  66.         }
  67.     }
  68. }
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