SlavCodes

Untitled

May 2nd, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 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. 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;
  26.  
  27. try{
  28. priceOfTrip = Double.parseDouble(scan.nextLine());
  29. } catch (Exception e){
  30. priceOfTrip=0;
  31. }
  32.  
  33. int numPuzzles;
  34. try{
  35. numPuzzles = Integer.parseInt(scan.nextLine());
  36. } catch (Exception e){
  37. numPuzzles=0;
  38. }
  39.  
  40. int numTalkingDolls;
  41. try{
  42. numTalkingDolls = Integer.parseInt(scan.nextLine());
  43. } catch (Exception e){
  44. numTalkingDolls=0;
  45. }
  46.  
  47. int numFluffBears;
  48.  
  49. try{
  50. numFluffBears = Integer.parseInt(scan.nextLine());
  51. } catch (Exception e){
  52. numFluffBears=0;
  53. }
  54.  
  55.  
  56. int numMinions;
  57.  
  58. try{
  59. numMinions = Integer.parseInt(scan.nextLine());
  60. } catch (Exception e){
  61. numMinions=0;
  62. }
  63.  
  64.  
  65. int numTrucks;
  66.  
  67. try{
  68. numTrucks = Integer.parseInt(scan.nextLine());
  69. } catch (Exception e){
  70. numTrucks = 0;
  71. }
  72.  
  73.  
  74.  
  75. double numToys = numPuzzles + numTalkingDolls + numFluffBears + numMinions + numTrucks;
  76. double totalIncome = (numPuzzles * 2.60) + (numTalkingDolls * 3) + (numFluffBears * 4.10) + (numMinions * 8.20) + (numTrucks * 2);
  77.  
  78. //with discount sale toys > 50
  79. double discount = 0.25 * totalIncome;
  80. double finalPriceDiscount = totalIncome - discount;
  81. double rentDiscount = 0.1 * finalPriceDiscount;
  82. double profitDiscount = finalPriceDiscount - rentDiscount;
  83.  
  84. //without discount toys < 50
  85.  
  86. double finalPrice = totalIncome;
  87. double rent = 0.1 * finalPrice;
  88. double profit = finalPrice - rent;
  89.  
  90.  
  91. // if logic
  92. if (numToys > 50)
  93. {
  94. if (priceOfTrip <= profitDiscount)
  95. {
  96. System.out.printf("Yes! %.2f lv left.", profitDiscount - priceOfTrip);
  97. } else if (priceOfTrip > profitDiscount) {
  98. System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profitDiscount);
  99. }
  100. } else
  101.  
  102. if (numToys < 50)
  103. {
  104. if (priceOfTrip <= profit)
  105. {
  106. System.out.printf("Yes! %.2f lv left.", profit - priceOfTrip);
  107. } else if (priceOfTrip > profit){
  108. System.out.printf("Not enough money! %.2f lv needed.", priceOfTrip - profit);
  109. }
  110. }
  111. }
  112.  
  113.  
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment