goods.java_Goods.java

package cn.work;

import java.util.Scanner;

public class Goods {

String[] goods=new String[] {"电风扇","洗衣机","电视机","冰箱","空调机"};

double[] price=new double[] {124.23,4500,8800.90,5000.88,4456,12000.46};

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;

}else {

System.out.println("用户名或密码不匹配,登录失败!");

}

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 showGoods() {

System.out.print("*********欢迎进入商品批发城*********");

System.out.print("\n\t编号\t商品\t价格\n");

for(int i=0;i

System.out.print("\t"+(i+1));

System.out.print("\t"+goods[i]);

System.out.print("\t"+change(price[i])+"\n");

}

System.out.println("******************************");

}

public static void main(String[] args) {

Scanner input=new Scanner(System.in);

Goods g=new Goods();

int num,count;

double totle=0;

if(g.login()) {

g.showGoods();

System.out.print("请输入您批发的商品编号:");

num=input.nextInt();

System.out.print("请输入批发数量:");

count=input.nextInt();

totle=g.price[num-1]*count; //计算总金额

System.out.print("您需要付款:"+g.change(totle));

}

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值