Advertisement
veronikaaa86

01. Computer Store

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