package com.example;
public class EggPk extends Pencake {
public EggPk(String name, double value) {
super(name, value);
}
@Override
public void taste() {
System.out.println("肉松鸡蛋味");
}
}
package com.example;
public class FishPk extends Pencake{
public FishPk(String name, double value) {
super(name, value);
}
@Override
public void taste() {
System.out.println("小鱼干味");
}
}
package com.example;
public class HotdogPk extends Pencake {
public HotdogPk(String name, double value) {
super(name, value);
}
@Override
public void taste() {
System.out.println("热狗味");
}
}
package com.example;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
buyPencake();
}
private static void buyPencake() {
int totalmoney = 0;
Pencake[] pencakeList = new Pencake[1024];
int j = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("煎饼果子售卖系统:" + "\n" +
"1:充值金额" + "\n" +
"2:购买煎饼果子" + "\n" +
"3:打印账单" + "\n" +
"4:退出系统");
while (true) {
if (scanner.hasNextInt()) {
String type = scanner.nextLine();
if (type.equals("1")) {
System.out.println("请输入您要充值的金额:");
int czMoney = Integer.valueOf(scanner.nextLine());
if (czMoney >= 100 && czMoney < 200) {
totalmoney += czMoney + 30;
System.out.println("充值" + czMoney + "元成功,实际充值" + (czMoney + 30) + "元");
} else if (czMoney >= 200 && czMoney < 300) {
totalmoney += czMoney + 80;
System.out.println("充值" + czMoney + "元成功,实际充值" + (czMoney + 80) + "元");
} else if (czMoney >= 300) {
totalmoney += czMoney + 130;
System.out.println("充值" + czMoney + "元成功,实际充值" + (czMoney + 130) + "元");
}
} else if (type.equals("2")) {
if (totalmoney <= 0) {
System.out.println("不充钱想买啥");
} else {
System.out.println("输入你要买的煎饼果子数量");
int pkCount = Integer.valueOf(scanner.nextLine());
for (int i = 0; i < pkCount; i++) {
System.out.println("输入你要买的煎饼果子种类:");
String pkType = scanner.nextLine();
if (pkType.equals("1")) {
YuanweiPk yuanweiPk = new YuanweiPk("原味", 5);
totalmoney -= 5;
pencakeList[j] = yuanweiPk;
j++;
System.out.println("购买原味成功");
} else if (pkType.equals("2")) {
HotdogPk hotdogPk = new HotdogPk("热狗火腿", 8);
totalmoney -= 8;
pencakeList[j] = hotdogPk;
j++;
System.out.println("购买热狗果子成功");
} else if (pkType.equals("3")) {
FishPk fishPk = new FishPk("小鱼干鸡排", 10);
totalmoney -= 10;
pencakeList[j] = fishPk;
j++;
System.out.println("购买小鱼干果子成功");
} else if (pkType.equals("4")) {
EggPk eggPk = new EggPk("鸡蛋肉松", 7);
totalmoney -= 7;
pencakeList[j] = eggPk;
j++;
System.out.println("购买鸡蛋果子成功");
}
}
}
} else if (type.equals("3")) {
for (int i = 0; i < j; i++) {
if (pencakeList[i] instanceof YuanweiPk) {
pencakeList[i].print();
pencakeList[i].taste();
} else if (pencakeList[i] instanceof HotdogPk) {
pencakeList[i].print();
pencakeList[i].taste();
} else if (pencakeList[i] instanceof FishPk) {
pencakeList[i].print();
pencakeList[i].taste();
} else if (pencakeList[i] instanceof EggPk) {
pencakeList[i].print();
pencakeList[i].taste();
}
}
} else if (type.equals("4")) {
System.out.println("欢迎下次光临");
break;
} else {
scanner.next();
System.out.println("输入错误,请重新输入");
}
System.out.println("请重新选择功能:" + "\n" +
"1:充值金额" + "\n" +
"2:购买煎饼果子" + "\n" +
"3:打印账单" + "\n" +
"4:退出系统");
} else {
scanner.next();
System.out.println("输入错误,请重新输入");
}
}
}
}
package com.example;
public class Pencake {
String name;
double value;
public Pencake(String name, double value) {
this.name = name;
this.value = value;
}
public void taste() {
}
public void print() {
System.out.println(name + value + "钱一个");
}
}