简单实现肯德基点餐系统,提供单点与套餐选项,可选择优惠券
核心代码块:
(1)显示的实现:
package 肯德基;
import java.util.ArrayList;
import java.util.Scanner;
public class Show {
private ArrayList<KFC> aa = new ArrayList<>();
private int yhq = 0;
public Show(){
zhuJieMain();
}
public void zhuJieMain(){
System.out.println("欢迎来到KFC点餐系统");
System.out.println("1.点餐");
System.out.println("2.领取优惠券");
System.out.println("3.结账");
show();
}
public void jieZhang(){
Scanner sc = new Scanner(System.in);
Server c = new Server();
c.setKfc(aa);
c.setYhq(yhq);
c.print();
int x1 = sc.nextInt();
c.setMoney(x1);
c.printXiaopiao();
}
public void show(){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
if(x==1){
diancan();
}
else if(x==2){
youhuiquan();
}else if(x==3){
jieZhang();
}
else{
System.out.println("输入错误");
}
}
public void diancan(){
System.out.println("本店有以下产品可供选则:");
System.out.println("1.香辣鸡腿包:10元/个");
System.out.println("2.套餐1:腿堡+可乐+辣翅:20元/份");
System.out.println("3.套餐2:腿堡+辣翅+蛋挞:30元/份");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
xuanze(x);
}
private void xuanze(int x) {
KFC a = null;
Scanner sc = new Scanner(System.in);
while (true) {
if (x == 1) {
a = Factory.creat("香辣鸡腿包");
} else if (x == 2) {
a = Factory.creat("套餐1");
} else if (x == 3) {
a = Factory.creat("套餐2");
} else {
System.out.println("没有该套餐");
}
aa.add(a);
System.out.println("继续Y,或返回上一页X/N");
String s = sc.next();
if (s.equals("N")){
zhuJieMain();
break;
}else if(s.equals("Y")){
diancan();
break;
}else if (s.equals("X")){
zhuJieMain();
break;
}
}
}
public void youhuiquan(){
System.out.println("1.满50减20,2.满100减30");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
if(x==1){
yhq=50;
}else if(x==2){
yhq=100;
}else{
System.out.println("没有该操作");
}
System.out.println("你现有优惠券"+yhq+"元");
System.out.println("返回Y");
String s = sc.next();
if (s.equals("Y")){
zhuJieMain();
}else{
System.out.println("你还不想结账?");
}
}
}
(2)单点
可再根据喜好向其中增添其他类型的食物
public class Food extends KFC{
private int price = 10;
private String name = "香辣鸡腿包";
public int getPrice() {
return price;
}
@Override
public String getName() {
return name;
}
}
(3)套餐
public class SetMeal1 extends KFC {
private String name = "套餐1:腿堡+可乐+辣翅20元/份";
private int price=20;
@Override
public String getName() {
return name;
}
@Override
public int getPrice() {
return price;
}
}
只列举了一种套餐,可继续添加其余套餐
(3)方法类的实现
public class KFC {
private String name;
private int price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
在此只展示了部分核心代码与有代表性的代码块,此代码可扩充性强,可以随意按照自己喜好在其中添加不同的食物与套餐。