SlavCodes

Untitled

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