Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. package ivan;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class _07_Training_Hall_Equipment {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         double budget = Double.parseDouble(input.nextLine());
  10.         double n = Double.parseDouble(input.nextLine());
  11.         double moneySpent = 0;
  12.         for (int i = 0; i < n; i++)
  13.         {
  14.             String s = input.nextLine();
  15.  
  16.             double price = Double.parseDouble(input.nextLine());
  17.             double quantity = Double.parseDouble(input.nextLine());
  18.  
  19.             moneySpent += price * quantity;
  20.             if (quantity < 2)
  21.             {
  22.                 System.out.printf("Adding %.0f %ss to cart.\n",quantity,s);
  23.  
  24.             }
  25.             else
  26.             {
  27.                 System.out.printf("Adding %.0f %ss to cart.\n",quantity,s);
  28.             }
  29.         }
  30.         if (moneySpent <= budget)
  31.         {
  32.             System.out.printf("Subtotal: $%.2f\n",moneySpent);
  33.             System.out.printf("Money left: $%.2f\n",budget-moneySpent);
  34.         }
  35.         else
  36.         {
  37.             System.out.printf("Subtotal: $%.2f\n",Math.abs(moneySpent));
  38.             System.out.printf("Not enough. We need $%.2f more.\n",moneySpent-budget);
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement