模拟超市收银系统,计算顾客购买商品总价,根据实收金额计算找零,反馈给用户所需要的所有信息
import java.util.Scanner;
public class Cashier{
public static void main(String[] args){
//输入数据
Scanner sc = new Scanner(System.in);
System.out.println("请输入单价...");
double danjia = sc.nextDouble();
System.out.println("请输入数量...");
double shuliang = sc.nextDouble();
System.out.println("请输入金额...");
double jine = sc.nextDouble();
sc.close();
//计算总价格
double zongjia = 0.0;
zongjia = danjia * shuliang;
//计算找零
double zhaoling = jine - zongjia;
System.out.println("应收:¥"+zongjia+"实收:¥"+jine+"找零:¥"+zhaoling);
}
}
|
|