(系统)商店购物管理系统

来源:互联网 发布:第四方支付钱包源码 编辑:程序博客网 时间:2024/05/01 01:42

需求:

这里写图片描述

解决代码

package day62;public class Custom {    String ID;    String passWd;    public Custom(String iD, String passWd) {        this.ID = iD;        this.passWd = passWd;    }    public int check(int sum) {        if ((this.ID).equals("TOM") && (this.passWd).equals("123456")) {            System.out.println("登陆成功");            sum = 1;        } else {            System.out.println("账号密码不匹配");            sum = 0;        }        return sum;    }}
package day62;import java.nio.channels.ShutdownChannelGroupException;public class Thing {    int num = 0;    double price = 0.0;    String name = "";    public Thing() {    }    public Thing(int num, String name, double price) {        super();        this.num = num;        this.price = price;        this.name = name;    }    public void show() {        System.out.println("*********************欢迎进入商品批发城*********************");        System.out.println("\t编号\t商品\t价格");        System.out.println("\t1\t电风扇\t124.23");        System.out.println("\t2\t洗衣机\t4,500.0");        System.out.println("\t3\t电视机\t8,800.9");        System.out.println("\t4\t冰箱\t5,000.88");        System.out.println("\t5\t空调机\t4,456.0");        System.out.println("******************************************************");    }    public double change(int sum, int add) {        Thing goods = null;        switch (sum) {        case 1:            goods = new Thing(1, "电风扇", 124.23);            break;        case 2:            goods = new Thing(2, "洗衣机", 4500.0);            break;        case 3:            goods = new Thing(3, "电视机", 8800.9);            break;        case 4:            goods = new Thing(4, "冰箱", 5000.88);            break;        case 5:            goods = new Thing(5, "空调机", 4456.0);            break;        }        double price = goods.price * add;        return price;    }}
package day62;import java.util.Scanner;public class ThingTest {    public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);        int sum = 0;        do {            System.out.println("请输入您的账号");            String id = scanner.next();            System.out.println("请输入您的密码");            String pw = scanner.next();            Custom custom = new Custom(id, pw);            sum = custom.check(sum);        } while (sum == 0);        Thing thing = new Thing();        thing.show();        System.out.println("请输入商品编号:");        int num = scanner.nextInt();        System.out.println("请输入商品的数量");        int add = scanner.nextInt();        System.out.println(thing.change(num, add));    }}

这里写图片描述