收银员找钱系统
package superMarket.expense.change;public class T1 {
int money1;// 顾客的钱
int money2;// 超市的钱
public void setMoney1(int money1) {
this.money1 = money1;
System.out.println("顾客支付金额为:" + money1);
}
public int getMoney1() {
return money1;
}
public void setUseMoney2(int money2) {
this.money2 = money2;
System.out.println("您本次消费金额为:" + money2);
}
public int getUseMoney2() {
return money2;
}
public static void main(String[] args) {
T1 p = new T1();
p.setMoney1(1000);
p.getMoney1();
// System.out.println(p.getMoney());
p.setUseMoney2(369);
p.getUseMoney2();
int balance = p.getMoney1() - p.getUseMoney2();
System.out.println("应找给顾客的金额:" + balance);
int oneHundred = balance / 100;
int ten = balance % 100 / 10;
int one = balance % 100 % 10;
System.out.println("一百元的" + oneHundred + "张");
if (ten > 5) {
System.out.println("五十元的 1张");
System.out.println("二十元的" + ten % 5 / 2 + "张");
System.out.println("十元的" + ten % 5 % 2 + "张");
} else {
if (ten >= 2) {
System.out.println("二十元的" + ten / 2 + "张");
System.out.println("十元的" + ten % 2 + "张");
} else
System.out.println("l元的" + ten + "张");
}
if (ten >= 5) {
System.out.println("五元的 1张");
System.out.println("两元的" + one % 5 / 2 + "张");
System.out.println("一元的" + one % 5 % 2 + "张");
} else {
if (one >= 2) {
System.out.println("两元的" + one / 2 + "张");
System.out.println("l元的" + one % 2 + "张");
} else
System.out.println("l元的" + one + "张");
}
}
}