Advertisement
Guest User

Hello France!

a guest
Oct 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. package fundamentalsExam;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class helloFrance {
  8. public static void main(String[] args) {
  9. Scanner scanner = new Scanner(System.in);
  10. List<Double> boughtItems = new ArrayList<>();
  11. String line = scanner.nextLine();
  12. double budget = Double.parseDouble(scanner.nextLine());
  13.  
  14. String[] tokens = line.split("\\|");
  15. for (int i = 0; i < tokens.length ; i++) {
  16. int borderIndex = tokens[i].indexOf("->");
  17. String item = tokens[i].substring(0,borderIndex);
  18. double price = Double.parseDouble(tokens[i].substring(borderIndex + 2));
  19.  
  20.  
  21. switch (item) {
  22. case "Clothes":
  23. double maxPrice = 50;
  24. if (price <= maxPrice) {
  25. double purchase = budget - price;
  26. if (purchase >= 0) {
  27. boughtItems.add(price);
  28. budget -= price;
  29. }
  30. }
  31. break;
  32. case "Shoes":
  33. maxPrice = 35;
  34. if (price <= maxPrice) {
  35. double purchase = budget - price;
  36. if (purchase >= 0) {
  37. boughtItems.add(price);
  38. budget -= price;
  39. }
  40. }
  41. break;
  42. case "Accessories":
  43. maxPrice = 20.50;
  44. if (price <= maxPrice) {
  45. double purchase = budget - price;
  46. if (purchase >= 0) {
  47. boughtItems.add(price);
  48. budget -= price;
  49. }
  50. }
  51. break;
  52. }
  53. }
  54.  
  55. double profit = 0;
  56. int index = 0;
  57. double sumNewPrices = 0d;
  58. for(double item : boughtItems){
  59.  
  60. if(boughtItems.get(index) == 0){
  61. profit += 0.4;
  62. boughtItems.set(index,0.4);
  63. sumNewPrices += boughtItems.get(index);
  64. index++;
  65. }else {
  66. profit += boughtItems.get(index) * 0.40;
  67. boughtItems.set(index, boughtItems.get(index) * 1.40);
  68. sumNewPrices += boughtItems.get(index);
  69. index++;
  70. }
  71. }
  72.  
  73.  
  74. boughtItems.forEach(e -> System.out.printf("%.2f ",e));
  75. System.out.println();
  76. System.out.printf("Profit: %.2f%n",profit);
  77. if(profit + sumNewPrices >= 150){
  78. System.out.println("Hello, France!");
  79. }else{
  80. System.out.println("Time to go.");
  81. }
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement