Didart

Computer Store

Oct 21st, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ComputerStore {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double totalAmount = 0;
  8.  
  9.         String type = scanner.nextLine();
  10.         while (!(type.equals("special") || (type.equals("regular")))) {
  11.             double price = Double.parseDouble(type);
  12.             if (price < 0) {
  13.                 System.out.println("Invalid price!");
  14.             } else {
  15.                 totalAmount += price;
  16.             }
  17.             type = scanner.nextLine();
  18.         }
  19.         double taxes = totalAmount * 0.20;
  20.         double finalSum = taxes + totalAmount;
  21.  
  22.         if (type.equals("special")) {
  23.             finalSum *= 0.90;
  24.         }
  25.  
  26.         if (totalAmount == 0) {
  27.             System.out.println("Invalid order!");
  28.         } else {
  29.             System.out.printf("Congratulations you've just bought a new computer!%n");
  30.             System.out.printf("Price without taxes: %.2f$%n", totalAmount);
  31.             System.out.printf("Taxes: %.2f$%n", taxes);
  32.             System.out.printf("-----------%n");
  33.             System.out.printf("Total price: %.2f$", finalSum);
  34.         }
  35.     }
  36. }
  37.  
  38. /*              System.out.printf("Congratulations you've just bought a new computer!%n" +
  39.                     "Price without taxes: %.2f$%n" +
  40.                     "Taxes: %.2f$%n" +
  41.                     "-----------%n" +
  42.                     "Total price: %.2f$", total, taxes, finalSum);  */
Advertisement
Add Comment
Please, Sign In to add comment