java打印输出购物小票结算
时间: 2023-11-18 18:57:35 浏览: 146
使用JAVA打印小票
5星 · 资源好评率100%
以下是Java代码,用于打印输出购物小票结算:
```java
import java.util.Scanner;
public class Shopping {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入T恤件数:");
int tShirtNum = input.nextInt();
int tShirtPrice = 245;
int tShirtTotalPrice = tShirtNum * tShirtPrice;
System.out.println("请输入网球鞋件数:");
int tennisShoesNum = input.nextInt();
int tennisShoesPrice = 570;
int tennisShoesTotalPrice = tennisShoesNum * tennisShoesPrice;
System.out.println("请输入网球拍件数:");
int tennisRacketNum = input.nextInt();
int tennisRacketPrice = 320;
int tennisRacketTotalPrice = tennisRacketNum * tennisRacketPrice;
int totalPrice = tShirtTotalPrice + tennisShoesTotalPrice + tennisRacketTotalPrice;
double discount = 0.8;
double actualPrice = totalPrice * discount;
System.out.println("购买物品\t\t单价\t个数\t金额");
System.out.println("T恤\t\t" + tShirtPrice + "\t" + tShirtNum + "\t" + tShirtTotalPrice);
System.out.println("网球鞋\t\t" + tennisShoesPrice + "\t" + tennisShoesNum + "\t" + tennisShoesTotalPrice);
System.out.println("网球拍\t\t" + tennisRacketPrice + "\t" + tennisRacketNum + "\t" + tennisRacketTotalPrice);
System.out.println("折扣:\t\t8折");
System.out.println("消费总金额:\t" + actualPrice);
System.out.println("实际交费:\t");
double payment = input.nextDouble();
double change = payment - actualPrice;
System.out.println("找钱:\t\t" + change);
}
}
```
阅读全文