Guest User

Untitled

a guest
Dec 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. import java.util.Scanner;
  2. class BookRentalShop
  3. {
  4. public static void main(String[] args)
  5. {
  6. Scanner sc = new Scanner(System.in);
  7. System.out.print("Enter the number of data you want to see: ");
  8. int inputnum = sc.nextInt();
  9. sc.nextLine();
  10. System.out.println("");
  11. String[] Name = new String[inputnum];
  12. String[] Bookname = new String[inputnum];
  13. String[] AuthorName = new String[inputnum];
  14. String[] Booktype = new String[inputnum];
  15. int[] NumbersofDaysBorrowed = new int[inputnum];
  16. int[] RentalCharges = new int[inputnum];
  17. String[] Types = {"Cartoon","Magazine", "Short story", "Long story", "Journal", "Novel", "Encyclopedia"};
  18. int[] count = new int[7];
  19.  
  20. for (int d = 0; d < inputnum; d = d + 1)
  21. {
  22. System.out.println("Enter the name of the person:");
  23. Name[d] = sc.nextLine();
  24. System.out.println("Enter the bookname:");
  25. Bookname[d] = sc.nextLine();
  26. System.out.println("Enter the author's name:");
  27. AuthorName[d] = sc.nextLine();
  28. System.out.println("Enter the book type:");
  29. Booktype[d] = sc.nextLine();
  30. for (int k = 0; k < 7; k++)
  31. {
  32. if (Booktype[d].equals(Types[k]))
  33. {
  34. count[k]++;
  35. }
  36. }
  37. System.out.println("Enter the number of days that the book had been borrowed:");
  38. NumbersofDaysBorrowed[d] = sc.nextInt();
  39. sc.nextLine();
  40. if (Booktype[d].equalsIgnoreCase("Cartoon"))
  41. {
  42. RentalCharges[d] = NumbersofDaysBorrowed[d] * 500;
  43. } else if (Booktype[d].equalsIgnoreCase("Magazine"))
  44. {
  45. RentalCharges[d] = NumbersofDaysBorrowed[d] * 1000;
  46. } else if (Booktype[d].equalsIgnoreCase("Short story"))
  47. {
  48. RentalCharges[d] = NumbersofDaysBorrowed[d] * 500;
  49. } else if (Booktype[d].equalsIgnoreCase("Long story"))
  50. {
  51. RentalCharges[d] = NumbersofDaysBorrowed[d] * 1500;
  52. } else if (Booktype[d].equalsIgnoreCase("Journal"))
  53. {
  54. RentalCharges[d] = NumbersofDaysBorrowed[d] * 350;
  55. } else if (Booktype[d].equalsIgnoreCase("Novel"))
  56. {
  57. RentalCharges[d] = NumbersofDaysBorrowed[d] * 1500;
  58. } else {
  59. RentalCharges[d] = NumbersofDaysBorrowed[d] * 2500;
  60. }
  61. if(NumbersofDaysBorrowed[d] > 5)
  62. {
  63. int bookCost = RentalCharges[d] / NumbersofDaysBorrowed[d];
  64. RentalCharges[d] = (5 * bookCost) + ((NumbersofDaysBorrowed[d] - 5) * (bookCost / 2));
  65. }
  66. }
  67. System.out.printf("%s %20s %20s %20s %20s %20s %20sn", "No", "Name", "Bookname", "AuthorName", "Booktype", "Numbers of Days Borrowed", "Rental Charges");
  68. for (int d = 0; d < inputnum; d = d + 1)
  69. {
  70. int num = d + 1;
  71. System.out.printf("%s %20s %20s %20s %20s %20d %20dn", num, Name[d], Bookname[d], AuthorName[d], Booktype[d], NumbersofDaysBorrowed[d], RentalCharges[d]);
  72. }
  73. String again = "Yes";
  74. String exist = "No";
  75. while (again.equals("Yes")) {
  76. exist = "No";
  77. System.out.println("enter the search name");
  78. String searchname = sc.nextLine();
  79. for (int d = 0; d < inputnum; d = d + 1) {
  80. if (searchname.equals(Name[d])) {
  81. System.out.println("Name : " + Name[d]);
  82. System.out.println("Bookname : " + Bookname[d]);
  83. System.out.println("Number of Days Borrowed : " + NumbersofDaysBorrowed[d]);
  84. exist = "Yes";
  85. }
  86. }
  87. if (exist.equals("No")) {
  88. System.out.println("The search name requested is not found");
  89. }
  90. System.out.println("Do you want to search again? (Yes,No) ");
  91. again = sc.nextLine();
  92. }
  93. *int max = count[0];
  94. for (int d = 0; d < 7; d = d + 1)
  95. {
  96. for (int k = d + 1; k < 7; k = k + 1)
  97. {
  98. if (count[k] > count[d])
  99. {
  100. max = count[k];
  101. }
  102. else {
  103. max = count[d];
  104. }
  105. }
  106. }
  107. System.out.println("");
  108. System.out.println("The most rented booktype is: " + max);
  109. System.out.println("");
  110. }
  111.  
  112. No Name Bookname AuthorName Booktype Numbers of Days Borrowed Rental Charges
  113. 1 J Grere bvcnvnb Journal 3 1050
  114. 2 K wqerwr xczzzx Novel 6 8250
  115. 3 opoipo kkghjhjgh bvcbcvbc Cartoon 5 2500
  116. 4 Q erwytiu ghfghgfd Magazine 7 6000
  117. 5 D sdsafhgjhgjk vvbbnbn,nbvc Novel 6 8250
  118. enter the search name
  119. No
  120. The search name requested is not found
  121. Do you want to search again? (Yes,No)
  122. No
  123.  
  124. The most rented booktype is: 2
Add Comment
Please, Sign In to add comment