|
| 1 | +package com.premaseem; |
| 2 | + |
| 3 | +import java.util.Scanner; |
| 4 | + |
| 5 | +public class ClientFile { |
| 6 | + |
| 7 | + public static void main(String[] args) { |
| 8 | + |
| 9 | + System.out.println("Welcome to Party host example which uses visitor pattern "); |
| 10 | + Scanner scan = new Scanner(System.in); |
| 11 | + Party party; |
| 12 | + CookVisitorI visitorCook; |
| 13 | + int repeatRunFlag = 1; |
| 14 | + while (repeatRunFlag == 1) { |
| 15 | + System.out.println("Which party do you want to host "); |
| 16 | + System.out.println("press 1 for Week end party "); |
| 17 | + System.out.println("press 2 for Week day party "); |
| 18 | + int tvType = scan.nextInt(); |
| 19 | + if (tvType == 1) { |
| 20 | + party = new LoudParty(); |
| 21 | + } else { |
| 22 | + party = new CalmParty(); |
| 23 | + } |
| 24 | + |
| 25 | + System.out.println("How would you want to manage cooking of food "); |
| 26 | + System.out.println(" Press 1 for a visitor Veg Cook "); |
| 27 | + System.out.println(" Press 2 for a visitor Non- Veg Cook "); |
| 28 | + System.out.println(" Press 3 for in house cooking (no visitor) "); |
| 29 | + |
| 30 | + int type = scan.nextInt(); |
| 31 | + try { |
| 32 | + switch (type) { |
| 33 | + case 1: |
| 34 | + visitorCook = new VegCookVisitor(); |
| 35 | + party.accept(visitorCook); |
| 36 | + break; |
| 37 | + case 2: |
| 38 | + visitorCook = new NonVegCookVisitor(); |
| 39 | + party.accept(visitorCook); |
| 40 | + break; |
| 41 | + case 3: |
| 42 | + party.cookInHouse(); |
| 43 | + break; |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + } catch (Exception e1) { |
| 48 | + e1.printStackTrace(); |
| 49 | + } |
| 50 | + System.out.println("============================="); |
| 51 | + System.out.println("Press 1 to Repeat .... "); |
| 52 | + try { |
| 53 | + repeatRunFlag = scan.nextInt(); |
| 54 | + } catch (Exception e) { |
| 55 | + repeatRunFlag = 0; |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments