Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ivan;
- import java.util.Scanner;
- public class _07_Training_Hall_Equipment {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- double budget = Double.parseDouble(input.nextLine());
- double n = Double.parseDouble(input.nextLine());
- double moneySpent = 0;
- for (int i = 0; i < n; i++)
- {
- String s = input.nextLine();
- double price = Double.parseDouble(input.nextLine());
- double quantity = Double.parseDouble(input.nextLine());
- moneySpent += price * quantity;
- if (quantity < 2)
- {
- System.out.printf("Adding %.0f %ss to cart.\n",quantity,s);
- }
- else
- {
- System.out.printf("Adding %.0f %ss to cart.\n",quantity,s);
- }
- }
- if (moneySpent <= budget)
- {
- System.out.printf("Subtotal: $%.2f\n",moneySpent);
- System.out.printf("Money left: $%.2f\n",budget-moneySpent);
- }
- else
- {
- System.out.printf("Subtotal: $%.2f\n",Math.abs(moneySpent));
- System.out.printf("Not enough. We need $%.2f more.\n",moneySpent-budget);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement