Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class BookRentalShop
- {
- public static void main(String[] args)
- {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the number of data you want to see: ");
- int inputnum = sc.nextInt();
- sc.nextLine();
- System.out.println("");
- String[] Name = new String[inputnum];
- String[] Bookname = new String[inputnum];
- String[] AuthorName = new String[inputnum];
- String[] Booktype = new String[inputnum];
- int[] NumbersofDaysBorrowed = new int[inputnum];
- int[] RentalCharges = new int[inputnum];
- String[] Types = {"Cartoon","Magazine", "Short story", "Long story", "Journal", "Novel", "Encyclopedia"};
- int[] count = new int[7];
- for (int d = 0; d < inputnum; d = d + 1)
- {
- System.out.println("Enter the name of the person:");
- Name[d] = sc.nextLine();
- System.out.println("Enter the bookname:");
- Bookname[d] = sc.nextLine();
- System.out.println("Enter the author's name:");
- AuthorName[d] = sc.nextLine();
- System.out.println("Enter the book type:");
- Booktype[d] = sc.nextLine();
- for (int k = 0; k < 7; k++)
- {
- if (Booktype[d].equals(Types[k]))
- {
- count[k]++;
- }
- }
- System.out.println("Enter the number of days that the book had been borrowed:");
- NumbersofDaysBorrowed[d] = sc.nextInt();
- sc.nextLine();
- if (Booktype[d].equalsIgnoreCase("Cartoon"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 500;
- } else if (Booktype[d].equalsIgnoreCase("Magazine"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 1000;
- } else if (Booktype[d].equalsIgnoreCase("Short story"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 500;
- } else if (Booktype[d].equalsIgnoreCase("Long story"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 1500;
- } else if (Booktype[d].equalsIgnoreCase("Journal"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 350;
- } else if (Booktype[d].equalsIgnoreCase("Novel"))
- {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 1500;
- } else {
- RentalCharges[d] = NumbersofDaysBorrowed[d] * 2500;
- }
- if(NumbersofDaysBorrowed[d] > 5)
- {
- int bookCost = RentalCharges[d] / NumbersofDaysBorrowed[d];
- RentalCharges[d] = (5 * bookCost) + ((NumbersofDaysBorrowed[d] - 5) * (bookCost / 2));
- }
- }
- System.out.printf("%s %20s %20s %20s %20s %20s %20sn", "No", "Name", "Bookname", "AuthorName", "Booktype", "Numbers of Days Borrowed", "Rental Charges");
- for (int d = 0; d < inputnum; d = d + 1)
- {
- int num = d + 1;
- System.out.printf("%s %20s %20s %20s %20s %20d %20dn", num, Name[d], Bookname[d], AuthorName[d], Booktype[d], NumbersofDaysBorrowed[d], RentalCharges[d]);
- }
- String again = "Yes";
- String exist = "No";
- while (again.equals("Yes")) {
- exist = "No";
- System.out.println("enter the search name");
- String searchname = sc.nextLine();
- for (int d = 0; d < inputnum; d = d + 1) {
- if (searchname.equals(Name[d])) {
- System.out.println("Name : " + Name[d]);
- System.out.println("Bookname : " + Bookname[d]);
- System.out.println("Number of Days Borrowed : " + NumbersofDaysBorrowed[d]);
- exist = "Yes";
- }
- }
- if (exist.equals("No")) {
- System.out.println("The search name requested is not found");
- }
- System.out.println("Do you want to search again? (Yes,No) ");
- again = sc.nextLine();
- }
- *int max = count[0];
- for (int d = 0; d < 7; d = d + 1)
- {
- for (int k = d + 1; k < 7; k = k + 1)
- {
- if (count[k] > count[d])
- {
- max = count[k];
- }
- else {
- max = count[d];
- }
- }
- }
- System.out.println("");
- System.out.println("The most rented booktype is: " + max);
- System.out.println("");
- }
- No Name Bookname AuthorName Booktype Numbers of Days Borrowed Rental Charges
- 1 J Grere bvcnvnb Journal 3 1050
- 2 K wqerwr xczzzx Novel 6 8250
- 3 opoipo kkghjhjgh bvcbcvbc Cartoon 5 2500
- 4 Q erwytiu ghfghgfd Magazine 7 6000
- 5 D sdsafhgjhgjk vvbbnbn,nbvc Novel 6 8250
- enter the search name
- No
- The search name requested is not found
- Do you want to search again? (Yes,No)
- No
- The most rented booktype is: 2
Add Comment
Please, Sign In to add comment