SlavCodes

Untitled

May 2nd, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8.  
  9.  
  10. Scanner scan = new Scanner(System.in);
  11.  
  12.  
  13. double priceOfTrip;
  14.  
  15. try{
  16. priceOfTrip = Double.parseDouble(scan.nextLine());
  17. } catch (Exception e){
  18. priceOfTrip=0;
  19. }
  20.  
  21. if(priceOfTrip <= 0){
  22. return;
  23. }
  24.  
  25. int numPuzzles;
  26. try{
  27. numPuzzles = Integer.parseInt(scan.nextLine());
  28. } catch (Exception e){
  29. numPuzzles=0;
  30. }
  31.  
  32. int numTalkingDolls;
  33. try{
  34. numTalkingDolls = Integer.parseInt(scan.nextLine());
  35. } catch (Exception e){
  36. numTalkingDolls=0;
  37. }
  38.  
  39. int numFluffBears;
  40.  
  41. try{
  42. numFluffBears = Integer.parseInt(scan.nextLine());
  43. } catch (Exception e){
  44. numFluffBears=0;
  45. }
  46.  
  47.  
  48. int numMinions;
  49.  
  50. try{
  51. numMinions = Integer.parseInt(scan.nextLine());
  52. } catch (Exception e){
  53. numMinions=0;
  54. }
  55.  
  56.  
  57. int numTrucks;
  58.  
  59. try{
  60. numTrucks = Integer.parseInt(scan.nextLine());
  61. } catch (Exception e){
  62. numTrucks = 0;
  63. }
  64.  
  65. if(priceOfTrip + numPuzzles + numTalkingDolls + numFluffBears + numMinions + numTrucks == 0){
  66. return;
  67. }
  68.  
  69. double numToys = numPuzzles + numTalkingDolls + numFluffBears + numMinions + numTrucks;
  70. double totalIncome = (numPuzzles * 2.60) + (numTalkingDolls * 3) + (numFluffBears * 4.10) + (numMinions * 8.20) + (numTrucks * 2);
  71.  
  72. //with discount sale toys > 50
  73. double discount = 0.25 * totalIncome;
  74. double finalPriceDiscount = totalIncome - discount;
  75. double rentDiscount = 0.1 * finalPriceDiscount;
  76. double profitDiscount = finalPriceDiscount - rentDiscount;
  77.  
  78. //without discount toys < 50
  79.  
  80. double finalPrice = totalIncome;
  81. double rent = 0.1 * finalPrice;
  82. double profit = finalPrice - rent;
  83.  
  84.  
  85. // if logic
  86. if (numToys > 50)
  87. {
  88. if (priceOfTrip <= profitDiscount)
  89. {
  90. System.out.printf("Yes! %.2f lv left.", profitDiscount - priceOfTrip);
  91. } else if (priceOfTrip > profitDiscount) {
  92. System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profitDiscount);
  93. }
  94. } else
  95.  
  96. if (numToys < 50)
  97. {
  98. if (priceOfTrip <= profit)
  99. {
  100. System.out.printf("Yes! %.2f lv left.", profit - priceOfTrip);
  101. } else if (priceOfTrip > profit){
  102. System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profit);
  103. }
  104. }
  105. }
  106.  
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment