刚学两个星期写的收银系统,完全是垃圾,大家帮忙解决几个问题
刚刚学了几个星期的java,还是十足的菜鸟,大家多多指导当我编译后,前几遍正常,但当输入特别大的值后(物品单价),就会跳出中间的一个while循环,不执行while(finalpay<=sum)的判断,也就是当付款值小于结算金额的时候也直接执行finalpay-sum,最后找的钱是负数,但又找不到什么原因,大家帮帮忙啊
还有就是想找个师傅,能帮我学习java,然后我会学sql-sever,c#,没有报酬,有的只是尊敬与汲取o(∩_∩)o...
下面是代码
package second;
import java.util.*;
public class xfd {
public static void main(String[] args) {
double i = 1;
while (i >= 1) {
Scanner input = new Scanner(System.in);
int username = 111;
int password = 111;
System.out.print("请输入管理员账号:");
int username1 = input.nextInt();
System.out.println("");
System.out.print("请输入管理员密码:");
int password1 = input.nextInt();
if (username == username1 && password == password1) {
System.out.println("进入收银管理系统,按0键退出,除0的任意键继续");
int enter = input.nextInt();
if (enter == 0) {
break;
}
int j = 1;
while (j >= 1) {
/*
* }else if(username!=username1&&password==password1){
* System.out.println("账号错误,请从新输入"); }else if
* (username!=username1&&password!=password1){
* System.out.println("账号密码错误,请重新输入:"); }else
* if(username==username1&&password!=password1){
* System.out.println("密码错误,请从新输入:"); }
*/
System.out.print("请输入T恤价格");
double shirtSpace = input.nextInt();
System.out.print("请输入网球鞋价格");
double shoeSpace = input.nextInt();
System.out.print("请输入球拍价格");
double padSpace = input.nextInt();
System.out.print("请输入T恤数量");
int shirtNo = input.nextInt();
System.out.print("请输入球鞋数量");
int shoeNo = input.nextInt();
System.out.print("请输入球拍数量");
int padNo = input.nextInt();
System.out.print("请输入付款总额");
short sum = (short) ((shirtSpace * shirtNo + shoeSpace* shoeNo + padSpace * padNo) * 0.8);
double finalPay = 0;
finalPay = input.nextInt();
while (finalPay <= sum) {
System.out.println("金额不足!请再加钱");
double finalpayadd = input.nextInt();
finalPay = finalPay + finalpayadd;
}
System.out
.println("****************消费单***************\n\n");
System.out.println("购买数量\t单价\t个数\t金额");
System.out.println("T恤\t¥" + shirtSpace + "\t" + shirtNo+ "\t" + shirtSpace * shirtNo);
System.out.println("网球鞋\t¥" + shoeSpace + "\t" + shoeNo+ "\t" + shoeSpace * shoeNo);
System.out.println("网球拍\t¥" + padSpace + "\t" + padNo + "\t" + padSpace * padNo + "\n\n\n");
int discount = 8;
System.out.println("折扣:\t\t" + discount + "折");
System.out.println("金额总计:" + "\t¥" + sum);
System.out.println("实际交费:" + "\t¥" + finalPay);
double returnMoney = finalPay - sum;
System.out.println("找钱:\t" + "\t¥" + returnMoney);
int score = (int) sum / 100 * 3;
System.out.println("本次购物所获得的积分是:" + "\t" + score);
System.out.println("****************谢谢光临*************\n\n");
System.out.println("按0键退出.任意键再按确定继续");
enter = input.nextInt();
if (enter == 0) {
System.out.println("退出收银系统");
break;
}
}
break;
} else {
System.out.println("账号或密码错误,请从新输入");
}
}
}
}