java⾬刷程序任意更换档数_⾬刷程序参考代码1类图:
控制杆类:
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;
}
}刻度盘类:
public class Dial {
protected int dial = 1;
public Dial()
{
dial = 1;
}
public Dial(int dial)
{
this.dial = dial;
}
public int getDial()
{
return dial;
}
public int dialUp()
{
if(dial < 3)
dial++;
return dial;
}
public int dialDown()
{
if(dial > 1)
dial --;
return dial;
}
}⾬刷类:
public class Brush { protected int speed = 0; public Brush()
{
speed = 0;
}
public Brush(int speed) {
this.speed = speed;
}
public int getSpeed()
{
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
}
中介类:
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()
{
Lever();
}
public int getDial()
{
Dial();
}
public void doSpeed()
{
int speed = 0;
switch(getLever())
{
case 1:speed = 0;break;
case 2:
switch(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()
{
java switch case string
String slever = "";
Lever())
{
case 1: slever = "停⽌";break;
case 2: slever = "间歇";break;
case 3: slever = "低速";break;
case 4: slever = "⾼速";break;
}
System.out.println("控制杆的档位为:" + slever );
System.out.println("刻度盘的刻度为:" + d.getDial());
System.out.println("⾬刷的速度为:" + b.getSpeed());
}
}Client类:
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();
while(true)
{
choice = Int();
if(choice == 0)
break;
switch(choice)
{
case 1:
Lever() >= 4)
{
System.out.println("控制杆已经处于⾼速档位,不能再升档!");
menu();
}
else
{
agent.l.leverUp();
}
break;
case 2:
Lever() <= 1)
{

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。