15

import java.util.Scanner;  
  
  
public class M {  
    String[] goods=new String[]{"电风扇","洗衣机","电视机","冰箱","空调机"};  
    double[] price=new double[]{124.23,4500,8800.9,5000,4456};  
    public boolean login(){  
        boolean flag=false;  
        Scanner input=new Scanner(System.in);  
        System.out.println("请输入用户名:");  
        String name=input.next();  
        System.out.println("请输入密码:");  
        String pwd=input.next();  
        if(name.equals("TOM")&&pwd.equals("12345")){  
            System.out.println("登陆成功!  ");  
            flag=true;  
        }else{  
            System.out.println("用户名或密码不正确,登陆失败!");  
        }  
        return flag;  
    }  
    public StringBuffer change(String string){  
        StringBuffer str=new StringBuffer(String.valueOf(string));  
        for(int i=str.indexOf(".")-3;i>0;i=i-3){  
            str.insert(i, ',');  
        }  
        return str;  
    }  
    public void shows(){  
        System.out.println("*****欢迎进入商品批发城*******");  
        System.out.println("\t编号\t商品\t价格\n");  
        for(int i=0;i<goods.length;i++){  
            System.out.println("\t"+(i+1));  
            System.out.println("\t"+goods[i]);  
            System.out.println("\t"+change(price[i]+"\n"));  
        }  
        System.out.println("*********************************");  
    }  
    public static void main(String[] args) {  
        Scanner input=new Scanner(System.in);  
        M a=new M();  
        int serial,num;  
        double totle=0;  
        if(a.login()){  
            a.shows();  
            System.out.println("请输入您批发的商品编号");  
            serial=input.nextInt();  
            System.out.println("请输入批发数量");  
            num=input.nextInt();  
            switch(serial){  
            case 1:  
                totle=124.23*num;  
                break;  
            case 2:  
                totle=4500*num;  
                break;  
            case 3:  
                totle=8800.9*num;  
                break;  
            case 4:  
                totle=5000*num;  
                break;  
            case 5:  
                totle=4456*num;  
                break;  
                  
            }  
            System.out.println("您需要付款"+totle);  
        }  
  
      
    }  
}  

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36074157/article/details/52670087
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭