RGAlex

O1. ComputerStore / O1. Mid Exam Retake

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