超市收银系统Java
package SCaa; import java.util.Scanner; public class yin { // b储存商品名字 String[] b; // bb商品价格 double[] bb; // 商品的总额 double c = 0; public void yin() { System.out.println("---------------录入商品----------------"); System.out.println("请输入商品数量"); Scanner sc = new Scanner(System.in); int a = sc.nextInt(); // a 数组长度 bb = new double[a]; b = new String[a]; for (int i = 1; i <= a; i++) { System.out.println("请输入第" + i + "件商品名称"); b[i - 1] = sc.next(); System.out.println("请输入第" + i + "件商品价格"); bb[i - 1] = sc.nextDouble(); c += bb[i - 1]; } } public void yinr() { System.out.println("------------------我的购物车---------------"); for (int i = 0; i < bb.length; i++) { System.out.println("名称" + b[i]); System.out.println("价格" + bb[i]); } System.out.println(c); } public void jie() { System.out.println("你要支付" + c); double cc; Scanner sc = new Scanner(System.in); cc = sc.nextDouble(); while (cc <= c) { System.out.println("你钱不够请重新输入"); cc = sc.nextDouble(); } System.out.println("给你找钱" + (cc - c)); } public static void main(String[] args) { int a; yin ss = new yin(); do { System.out.println("欢迎使用超市结算系统"); System.out.println("***********************************"); System.out.println("1;商品录入"); System.out.println("2;我的购物车"); System.out.println("3;结算"); System.out.println("4;退出"); System.out.println("***********************************"); System.out.println("请输入你的选择"); Scanner sc = new Scanner(System.in); a = sc.nextInt(); switch (a) { case 1: ss.yin(); break; case 2: ss.yinr(); break; case 3: ss.jie(); break; case 4: System.out.println("退出成功"); break; default: System.out.println("没有这个选项"); } } while (a != 4); } }




浙公网安备 33010602011771号