MFC界面设计

1、汉堡包

public class Humberger extends KFC {
	private String name = "汉堡包";
    private int price=15;

    public String getName() {
        return name;
    }

    public int getPrice() {
        return price;
    }
}

2、薯条

public class FrenchFries extends KFC {
	private String name = "薯条";
    private int price=10;

    public String getName() {
        return name;
    }

    public int getPrice() {
        return price;
    }
}

3、可乐

public class Beverage extends KFC {
	private String name = "可乐";
    private int price=10;

    public String getName() {
        return name;
    }

    public int getPrice() {
        return price;
    }
}

4、鸡翅

public class ChickenWings extends KFC {
	private String name = "鸡翅";
    private int price=15;

    public String getName() {
        return name;
    }

    public int getPrice() {
        return price;
    }
}

5、工场

public class Factory {
	 private Factory() {
	 }
	 
	 public static KFC creat(String name) {
	  if (name.equals("汉堡包")) {
	   return new Humberger();
	  } else if(name.equals("鸡翅")){
	   return new  ChickenWings();
	  }else if(name.equals("薯条")){
	   return new FrenchFries();
	  }else if(name.equals("可乐")){
	   return new Beverage();
	  }
	  else if (name.equals("套餐1")) {
	   return (KFC) new TC1();
	  } else if (name.equals("套餐2")) {
	   return new TC2();
	  } else {
	   return null;
	  }
	 }
	}

6、KFC

	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;
	    }
	}

7、收银

	private ArrayList<KFC> aa;
	private int money;
	private int yhq = 0;

	public Collect() {

	}

	public void setKfc(ArrayList<KFC> aa) {
		this.aa = aa;
	}

	public void setYhq(int yhq) {
		this.yhq = yhq;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public float judge() throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date start = sdf.parse("2018-10-27 00:00:00");
		Date end = sdf.parse("2018-10-28 15:00:00");
		Date day=new Date(); 
		
		float i = 0;
		float sum = 0;
		for (KFC kfc : aa) {
			if(day.equals(start)|| day.after(start) && day.equals(end) || day.before(end)){
				sum =(float) ((sum+ kfc.getPrice())*0.8);
			}else{
				sum += kfc.getPrice();
			}
		}
		if (sum >= 100) {
			if (yhq == 50) {
				i = money - sum + 20;
			} else if (yhq == 100) {
				i = money - sum + 30;
			} else {
				i = money - sum;
			}
		} else if (sum >= 50) {
			if (yhq == 50) {
				i = money - sum + 20;
			} else {
				i = money - sum;
			}
		}else {
			i = money - sum;
		}
		System.out.println("找零" + i + "元");
		return i;
	}

	public void print() {
		System.out.println("本次消费如下:");
		int sum = 0;
		StringBuffer s = new StringBuffer();
		for (KFC kfc : aa) {
			sum += kfc.getPrice();
			if (aa.indexOf(kfc) != aa.size() - 1) {
				s.append(kfc.getName() + "---------" + kfc.getPrice() + "\r\n");
			} else {
				s.append(kfc.getName() + "---------" + kfc.getPrice());
			}
		}

		System.out.println(s);
		System.out.println("共消费" + sum + "元");
		if (sum >= 50) {
			System.out.println("***您使用了优惠券满50减20***" + "\r\n");
		} else if (sum >= 100) {
			System.out.println("***您使用了优惠券满100减30***" + "\r\n");
		} else {
			System.out.println("***    没有使用优惠券       ***" + "\r\n");
		}
	}

	public void printXiaopiao() throws IOException, ParseException {
		Date day=new Date();    
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		
		BufferedWriter br = new BufferedWriter(new FileWriter("xiaopiao.txt"));
		br.write("=========================" + "\r\n");
		br.write("-------------------------" + "\r\n");
		br.write("*******欢迎光临KFC*******" + "\r\n");
		br.write("**"+df.format(day)+"**"+"\r\n"); 
		br.write("*******本次消费如下******" + "\r\n");
		int sum = 0;
		for (KFC kfc : aa) {
			sum += kfc.getPrice();
			if (aa.indexOf(kfc) != aa.size() - 1) {
				br.write("***" + kfc.getName() + "-----------" + kfc.getPrice() + "***" + "\r\n");
			} else {
				br.write("***" + kfc.getName() + "-----------" + kfc.getPrice() + "***" + "\r\n");
			}
		}
		br.write("***消费" + "-----------" + sum + "元" + "***" + "\r\n");
		br.write("***支付" + "-----------" + money + "元" + "***" + "\r\n");
		if (sum >= 50) {
			br.write("***您使用了优惠券满50减20***" + "\r\n");
		} else if (sum >= 100) {
			br.write("***您使用了优惠券满100减30***" + "\r\n");
		} else {
			br.write("***    没有使用优惠券       ***" + "\r\n");
		}
		br.write("***找零" + "-----------" + judge() + "元" + "***" + "\r\n");
		br.write("=========================" + "\r\n");
		br.newLine();
		br.flush();
		br.close();
	}

}

8、打折

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Scanner;
public class DOS {
	private ArrayList<KFC> aa = new ArrayList();
    private int yhq = 0;
    public DOS() throws IOException, ParseException{
        zhuJieMain();
    }
    public void zhuJieMain() throws IOException, ParseException{
    	System.out.println("==============================");
    	System.out.println("------------------------------");
        System.out.println("*****    欢迎来到肯德基      *****");
        System.out.println("*****     1.点餐                  *****");
        System.out.println("*****     2.领取优惠券       *****");
        System.out.println("*****     3.结账                  *****");
        System.out.println("------------------------------");
        System.out.println("==============================");
        System.out.println("请选择:");
        show();
    }
    
    public void show() throws IOException, ParseException{
        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() throws IOException, ParseException{
		System.out.println("本店退出以下产品:");
		System.out.println("1.汉堡:15/个       2.鸡翅:15/个");
		System.out.println("3.薯条:10/个       4.可乐:10/个");
		System.out.println("5.套餐1:汉堡+可乐+鸡翅:35/份");
		System.out.println("6.套餐2:汉堡+可乐+薯条:30/份");
		System.out.println("请选择:");
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		xuanze(x);
    }

    private void xuanze(int x) throws IOException, ParseException {
        KFC a = null;
        Scanner sc = new Scanner(System.in);
        while (true) {
            if (x == 1) {
                a = Factory.creat("汉堡包");
            } else if(x==2){
            	 a = Factory.creat("鸡翅");
            }else if (x == 3) {
                a = Factory.creat("薯条");
            }else if (x == 4) {
                a = Factory.creat("可乐");
            }else if (x == 5) {
                a = Factory.creat("套餐1");
            } else if (x == 6) {
                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")||s.equals("n")){
                zhuJieMain();
                break;
            }else if(s.equals("Y")||s.equals("y")){
                diancan();
                break;
            }else if (s.equals("X")||s.equals("x")){
                jieZhang();
                break;
            }
        }
    }
    public void youhuiquan() throws IOException, ParseException{
        System.out.println("============================");
        System.out.println("----------------------------");
        System.out.println("*********1.满50减20*********");
        System.out.println("*********2.满100减30********");
        System.out.println("============================");
        Scanner sc = new Scanner(System.in);
        System.out.println("请选择:");
        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")||s.equals("y")){
            zhuJieMain();
        }else{
            System.out.println("你还不想结账?");
        }
    }
    public void jieZhang() throws IOException, ParseException{
        Scanner sc = new Scanner(System.in);
        Collect c = new Collect();
        c.setKfc(aa);
        c.setYhq(yhq);
        c.print();
        System.out.println("请付款:");
        int x1 = sc.nextInt();
        c.setMoney(x1);
        c.printXiaopiao();
    }
}

9、测试

//文本测试
	import java.io.IOException;
	import java.text.ParseException;
	
	public class demo {
		public static void main(String[]args) throws IOException, ParseException{
		       DOS a= new DOS();
		   }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值