Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class factoryPatternDemo{
- public static void main(String[] args) throws FileNotFoundException{
- ShapeFactory shapeFactory = new ShapeFactory();
- Shape sh = null;
- Scanner sc = new Scanner(new FileInputStream("in.txt"));
- while(true) {
- String choice;
- choice = sc.nextLine();
- System.out.println(choice);
- if (choice.equalsIgnoreCase("CIRCLE")) {
- System.out.println("Please enter the radius");
- int op = sc.nextInt();
- sh = shapeFactory.getShape("Circle", op, 0, 0);
- System.out.println("HI");
- sh.display();
- sh.draw();
- sh.surface_area();
- sh.perimeter();
- }
- else if (choice.equalsIgnoreCase("SQUARE")) {
- System.out.println("Please enter the arm");
- int op = sc.nextInt();
- sh = shapeFactory.getShape("Square", op, 0, 0);
- sh.display();
- sh.draw();
- sh.surface_area();
- sh.perimeter();
- }
- else if (choice.equalsIgnoreCase("RECTANGLE")) {
- System.out.println("Please enter the length and width");
- int op = sc.nextInt();
- int op2 = sc.nextInt();
- sh = shapeFactory.getShape("Rectangle", op, op2, 0);
- /*sh.display();
- sh.draw();
- sh.surface_area();
- sh.perimeter();*/
- }
- else if (choice.equalsIgnoreCase("TRIANGLE")) {
- System.out.println("Please enter three arms");
- int op = sc.nextInt();
- int op2 = sc.nextInt();
- int op3 = sc.nextInt();
- sh = shapeFactory.getShape("Triangle", op, op2, op3);
- /*sh.display();
- sh.draw();
- sh.surface_area();
- sh.perimeter();*/
- }
- else if(choice.equalsIgnoreCase("BREAK"))
- {
- break;
- }
- /*sh.display();
- sh.draw();
- sh.surface_area();
- sh.perimeter();*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement