File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /bin
Original file line number Diff line number Diff line change 1+ package com .premaseem .facade ;
2+
3+ import java .util .Scanner ;
4+
5+ public class ClientForEntertainmentUnitFacade {
6+
7+ public static void main (String [] args ) {
8+ Scanner scan = new Scanner (System .in );
9+ int repeatRunFlag = 1 ;
10+
11+
12+ System .out .println ("This is Facade Pattern example which provides a smiple interface for the client to play a moive in entertainment unit (simplifies the setup proccess of entertainment unit) " );
13+
14+ EntertainmentFacade entertainmentFacade = new EntertainmentFacade ();
15+ while (repeatRunFlag == 1 ) {
16+ System .out .println ("What would you like to do with your entertainment unit today " );
17+ System .out .println (" Press 1 for movie" );
18+ System .out .println (" Press 2 for music" );
19+ System .out .println (" Press 3 for game " );
20+ int entType = scan .nextInt ();
21+ System .out .println ("Please enter the name " );
22+ String name = scan .next ();
23+
24+
25+ switch (entType ) {
26+ case 1 :
27+ entertainmentFacade .playMovie (name );
28+ break ;
29+ case 2 :
30+ entertainmentFacade .playMusic (name );
31+ break ;
32+ case 3 :
33+ entertainmentFacade .playGame (name );
34+ break ;
35+ }
36+
37+ System .out .println ("Press 1 for more entertainment and 0 for EXIT .... " );
38+ try {
39+ repeatRunFlag = scan .nextInt ();
40+ } catch (Exception e ) {
41+ repeatRunFlag = 0 ;
42+ }finally {
43+ entertainmentFacade .masterPowerOff ();
44+ }
45+
46+
47+ }
48+ }
49+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .facade ;
2+
3+ public class EntertainmentDevice {
4+
5+ }
6+
7+ class Nexus {
8+ public void downloadmedia (String name ) {
9+ System .out .println ("Searching the media " );
10+ System .out .println ("Making online payment " );
11+ System .out .println ("downloaded from Nexus" + name );
12+ }
13+ }
14+
15+ class Amplifier {
16+
17+ void powerOn () {
18+ System .out .println ("Power on Amplifier" );
19+ }
20+
21+ void powerOff () {
22+ System .out .println ("power Off Amplifer " );
23+ }
24+
25+ void attachAmplifierForMusic () {
26+ System .out .println ("Attaching music amplification" );
27+ }
28+
29+ void attachAmplifierForHomeTheater () {
30+ System .out .println ("Attaching movie amplification " );
31+ }
32+ }
33+
34+ class Projecter {
35+
36+ void powerOn () {
37+ System .out .println ("Power on Projector" );
38+ }
39+
40+ void powerOff () {
41+ System .out .println ("power Off Projector " );
42+ }
43+
44+ void adjustProjectorForMovie () {
45+ System .out .println ("Attaching home theater mode" );
46+ }
47+
48+ void adjustProjectorForGame () {
49+ System .out .println ("Attaching game console " );
50+ }
51+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem .facade ;
2+
3+ public class EntertainmentFacade {
4+
5+ Nexus nexus = new Nexus ();
6+ Amplifier amplifer = new Amplifier ();
7+ Projecter projector = new Projecter ();
8+
9+ public void playMovie (String name ) {
10+ nexus .downloadmedia (name );
11+ masterPowerOn ();
12+ amplifer .attachAmplifierForHomeTheater ();
13+ projector .adjustProjectorForMovie ();
14+ }
15+
16+ public void playMusic (String name ) {
17+ nexus .downloadmedia (name );
18+ amplifer .powerOn ();
19+ amplifer .attachAmplifierForMusic ();
20+ }
21+
22+ public void playGame (String name ) {
23+ nexus .downloadmedia (name );
24+ masterPowerOn ();
25+ amplifer .attachAmplifierForMusic ();
26+ projector .adjustProjectorForGame ();
27+ }
28+
29+ public void masterPowerOff () {
30+ amplifer .powerOff ();
31+ projector .powerOff ();
32+ }
33+
34+ public void masterPowerOn () {
35+ amplifer .powerOn ();
36+ projector .powerOn ();
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments