15.3.3

来源:互联网 发布:大数据的利用过程顺序 编辑:程序博客网 时间:2024/05/16 19:54
<span style="font-size:24px;">import java.util.*;public class sfdsd {String[] goods = new String[] { "电风扇", "洗衣机", "电视机", "冰箱", "空调机" };double[] price = new double[] { 124.23, 4500, 8800.90, 5000.88, 4456 };double total;public boolean login() {boolean flag = false;Scanner input = new Scanner(System.in);System.out.print(" 请输入用户名: ");String name = input.next();System.out.print(" 请输入密码: ");String pwd = input.next();if (name.equals("Tom") && pwd.equals("123")) {System.out.println("登录成功");flag = true;}return flag;}public StringBuffer change(double d) {StringBuffer str = new StringBuffer(String.valueOf(d));for (int i = str.indexOf(".") - 3; i > 0; i = i - 3) {str.insert(i, ',');}return str;}public void show() {Scanner input = new Scanner(System.in);System.out.println("*********欢迎进入商品批发城*********");System.out.println("\t编号\t商品\t价格");for (int i = 0; i < goods.length; i++) {System.out.println("\t" + (i + 1) + "\t" + goods[i] + "\t"+ change(price[i]));}System.out.println("************************************");System.out.print("请输入您批发的商品编号: ");int choice = input.nextInt();System.out.print("请输入批发数量: ");int number = input.nextInt();switch (choice) {case 1:total = price[0] * number;break;case 2:total = price[1] * number;break;case 3:total = price[2] * number;break;case 4:total = price[3] * number;break;case 5:total = price[4] * number;break;}System.out.println("您需要付款:" + change(total));}public static void main(String[] args) {sfdsd g = new sfdsd();if (g.login()) {g.show();} else {System.out.println("退出");}}}</span>

0 0
原创粉丝点击