Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package bookstore.pkg2;
  7.  
  8. /**
  9. *
  10. * @author LemoneFresh
  11. */
  12. import java.util.Scanner;
  13.  
  14. public class Bookstore2 {
  15.  
  16. /**
  17. *
  18. * @param costBook Cost of Book
  19. * @param numEbook Number of Ebooks Bought
  20. * @param baseCharge Base charge cost*numbought
  21. * @return returns the base charge of books
  22. */
  23. public static double calcBasecharge(double costBook,int numEbook){
  24. double baseCharge = costBook*numEbook;
  25. return baseCharge;
  26.  
  27.  
  28. }
  29. /**
  30. *
  31. * @param baseCharge Takes the base charge for calculations
  32. * @param numEbook Takes number of ebooks for calculations
  33. * @return returns the amount of service charge based on the number of books.
  34. */
  35. public static double calcServicecharge(double baseCharge, int numEbook){
  36. final double serviceUnder8 = 0.07,
  37. serviceOver8 = 0.05,
  38. serviceOver15 = 0.03,
  39. serviceOver20 = 0.0;
  40. double serviceCharge = 0.0;
  41.  
  42. if (numEbook >= 20) {serviceCharge =baseCharge*serviceOver20;}
  43.  
  44. else if (numEbook > 15) {serviceCharge = baseCharge*serviceOver15;}
  45.  
  46. else if (numEbook > 8) {serviceCharge = baseCharge*serviceOver8;}
  47.  
  48. else {serviceCharge = baseCharge*serviceUnder8;}
  49. return serviceCharge;
  50. }
  51.  
  52. public static double calcDiscount(double productCharge, int memStatus,double baseCharge ){
  53. final double noMem = 1,
  54. bronzeMem = 0.10,
  55. silverMem = 0.15,
  56. goldMem = 0.20;
  57. double discount = 0.0;
  58.  
  59. if (memStatus==3) {discount = productCharge*goldMem;}
  60.  
  61. else if (memStatus==2) {discount = productCharge*silverMem;}
  62.  
  63. else if (memStatus==1) {discount = productCharge*bronzeMem;}
  64.  
  65. else {discount = baseCharge*noMem;}
  66.  
  67. return discount;
  68. }
  69.  
  70. /**
  71. * @param args the command line arguments
  72. */
  73. public static void main(String[] args) {
  74. // TODO code application logic here
  75.  
  76. //define variables
  77. String custFirst,
  78. custLast;
  79.  
  80. double
  81. costBook = 0.0,
  82. baseCharge = 0.0,
  83. productCharge = 0.0,
  84. subTotal = 0.0,
  85. totalTax = 0.0;
  86.  
  87. int numEbook = 0,
  88. memStatus = 0;
  89.  
  90. final double tax = 0.055;
  91.  
  92.  
  93.  
  94.  
  95. // create a Scanner object to accept keyboard input
  96. Scanner keyboard = new Scanner(System.in);
  97.  
  98. //callculate product charge.
  99. productCharge = baseCharge+calcServicecharge(costBook,numEbook);
  100.  
  101. //subtotal
  102. subTotal = productCharge-calcDiscount(productCharge,memStatus,baseCharge);
  103. //get total tax
  104. totalTax = subTotal*tax;
  105.  
  106. System.out.printf("Please enter your first name.");
  107. custFirst = keyboard.nextLine();
  108. //get last name
  109. System.out.printf("Please enter your last name.");
  110. custLast = keyboard.nextLine();
  111.  
  112. //get price
  113. System.out.printf("Please enter the price of the book");
  114. costBook = keyboard.nextDouble();
  115.  
  116. //get num of books
  117. System.out.printf("Please enter the number of books you took.");
  118. numEbook = keyboard.nextInt();
  119. //membershipstatus
  120. System.out.printf("Enter your membership Status:\n" +
  121. "3 represents gold member\n" +
  122. "2 represents silver member\n" +
  123. "1 represents bronze member\n" +
  124. "0 represents nonmember: -->");
  125. memStatus = keyboard.nextInt();
  126. //print results.
  127. System.out.printf("Your base cost is %.2f",calcBasecharge(costBook,numEbook));
  128. System.out.printf("Your service charge is $%.2f",calcServicecharge(costBook,numEbook));
  129. System.out.printf("Your Discount is $%.2f",calcDiscount(productCharge,memStatus,baseCharge));
  130. System.out.printf("Your Subtotal is $%.2f",subTotal);
  131.  
  132. }
  133.  
  134.  
  135.  
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement