Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class proba12345 {
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8. String money = scan.nextLine();
  9. double sum = 0;
  10. double Money = 0;
  11.  
  12. double Nuts = 2.0;
  13. double Water = 0.7;
  14. double Crisps = 1.5;
  15. double Soda = 0.8;
  16. double Coke = 1.0;
  17.  
  18. while (!money.equals("Start")){
  19. Money = Double.parseDouble(money);
  20. sum += Money;
  21. if (Money != 0.2 && Money != 0.5 && Money!= 1 && Money != 2){
  22. System.out.printf("Cannot accept %.2f", Money);
  23. sum -= Money;
  24. }
  25. }
  26. String product = scan.nextLine();
  27. while (!product.equals("End")){
  28. product = scan.nextLine();
  29.  
  30. if (product.equals("Nuts")){
  31. if (sum < Nuts){
  32. System.out.println("Sorry, not enough money");
  33. return;
  34. }
  35. sum -= Nuts;
  36. } else if (product.equals("Water")){
  37. if (sum < Water){
  38. System.out.println("Sorry, not enough money");
  39. return;
  40. }
  41. sum -= Water;
  42. } else if (product.equals("Crisps")){
  43. if (sum < Crisps){
  44. System.out.println("Sorry, not enough money");
  45. return;
  46. }
  47. sum -= Crisps;
  48. } else if (product.equals("Soda")){
  49. if (sum < Soda){
  50. System.out.println("Sorry, not enough money");
  51. return;
  52. }
  53. sum -= Soda;
  54. } else if (product.equals("Coke")){
  55. if (sum < Coke){
  56. System.out.println("Sorry, not enough money");
  57. return;
  58. }
  59. sum -= Coke;
  60. } else {
  61. System.out.println("Invalid product");
  62. }
  63. }
  64. System.out.printf("Change: %.2f ", sum);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement