Control Lever Class
public class Lever {protected int Lever = 1;public Lever () {Lever = 1;} Public Lever (int Lever) {this.lever = Lever;} public int Getlever () {return lever;} public int Leverup () {if (Lever < 4) Lever++;return lever;} public int Leverdown () {if (Lever > 1) lever--;return lever;}}
Scale Plate Class
public class Dial {protected int Dial = 1;public Dial () {Dial = 1;} public Dial (int lever) {this.dial = lever;} public int getdial () {return dial;} public int dialUp () {if (Dial < 3) Dial++;return dial;} public int Dialdown () {if (Dial > 1) Dial--;return dial;}}
Wiper type
public class Brush {protected int speed = 0;public Brush () {speed = 0;} Public Brush (int.) {this.speed = speed;} public int getspeed () {return speed;} public void Setspeed (int.) {this.speed = speed;}}
proxy class
public class Agent {protected Lever l;protected Dial d;protected Brush b;public Agent () {L = new Lever ();d = new Dial (); b = New Brush ();} public int Getlever () {return l.getlever ();} public int getdial () {return d.getdial ();} public void Dospeed () {int speed = 0;switch (L.getlever ()) {Case 1:speed = 0;break;case 2:switch (d.getdial ()) {Case 1:speed = 4;break;case 2:speed = 6;break;case 3:speed = 12;break;} Break;case 3:speed = 30;break;case 4:speed = 60;break;} B.setspeed (speed);} public void Show () {String slever = "", Switch (L.getlever ()) {Case 1:slever = "Stop"; break;case 2:slever = "intermittent"; Break;case 3: Slever = "Low Speed"; break;case 4:slever = "high speed"; break;} SYSTEM.OUT.PRINTLN ("Control Lever's Gear is:" + slever); SYSTEM.OUT.PRINTLN ("The scale of the dial is:" + d.getdial ()); SYSTEM.OUT.PRINTLN ("Wiper speed:" + b.getspeed ());}}
Test class
Import Java.util.scanner;public class Brush_test {public static void menu () {System.out.println ("================== Please choose operation============ "); System.out.println ("\t==========1:lever up==========="); System.out.println ("\t==========2:lever down========="); System.out.println ("\t==========3:dial up============"); System.out.println ("\t==========4:dial down=========="); System.out.println ("\t==========0:quit==============="); System.out.println ("====================================================="); System.out.println ("Input the Number (0~4):");} public static void Main (string[] args) {Agent Agent = new agent (); Scanner input = new Scanner (system.in); int choice = 0;menu (); try{//A lot of students asked why input would be warned, actually input to do close () operation, reference to this code, Later will speak while (true) {choice = Input.nextint (); if (choice = = 0) break;switch (choice) {Case 1:if (Agent.getlever () >= 4) { System.out.println ("The control lever is already in the high-speed gear, can no longer upshift!" "); menu (); continue;} Else{agent.l.leverup ();} Break;case 2:if (Agent.getlever () <= 1) {System.out.println ("The control lever is already in the stop fileBit, can not drop the gear again! "); menu (); continue;} Else{agent.l.leverdown ();} Break;case 3:if (agent.getdial () >= 3) {System.out.println ("The dial is already in the highest scale and can no longer be upshift!") "); menu (); continue;} Else{agent.d.dialup ();} Break;case 4:if (agent.getdial () <= 1) {System.out.println ("The dial is already in the lowest scale and cannot be lowered! "); menu (); continue;} Else{agent.d.dialdown ();} Break;default:system.out.println ("Please enter digital 0~4"); menu (); continue;} Switchagent.dospeed (); Agent.show (); menu ();} While}finally{input.close ();}}}
Java Third Job Reference code