Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Library Fines A local public library needs a program to calculate the overdue

ID: 3735886 • Letter: 1

Question

1.      Library Fines

A local public library needs a program to calculate the overdue fines owed by its patrons. The library needs the clerk to enter the patron’s library card number, age of the patron, the number of days overdue for the item and the type of the item using the follow (enter 1, 2 or 3):

1.      Book

2.      Magazine

3.      DVD

Books that are overdue are assessed a fine of 50 cents per day. Magazines are assessed a fine of 25 cents per day. DVDs are assessed a fine of $1.50 a day. There is a maximum fine assessed of $5.00. Senior Citizens (over the age of 70) do not pay fines. Juvenile patrons (ages 6 through 17) pay a maximum fine of $1.00.

Once the fine has been calculated all information about the patron and the overdue material should be printed to the screen. Here is an example of the report that should be output:

Card number                                    12345

Age                                                   22

Item Type                                         DVD

Number of Days Overdue                2

Overdue Fine                                    $3.00

Fine adjustment reason                    (e.g, Senior citizen, Juvenile, exceed max)

Each time the program is executed it calculates the fine for a single item. If the user enters invalid data, then a message must be presented on the screen specifying the invalid information and the calculation is aborted.

a)     Run your program multiple times using the following information as input. After each run of the program save your entire console output screen to a text file as discussed in our labs.  

·       11111 is 75 years old and has an overdue magazine. The magazine is 1 day overdue.

·       22222 is 30 years old and has an overdue magazine. The magazine is 10 days overdue.

·       33333 is 10 years old and has an overdue DVD. The DVD is 2 days overdue.

·       44444 is 50 years old and has an overdue DVD. The DVD is 2 days overdue.

·       55555 is 20 years old and has an overdue book. The book is 60 days overdue.

·       66666 is 15 years old and has an overdue magazine. The magazine is 3 days overdue.

Explanation / Answer

Hi friend, you have not mentioned about Programing language.

I have implemented in Java.

Please let me know in case of any issue.

Pelase try to mention all required details:

import java.util.Scanner;

public class LibraryFines {

   public static void main(String args[]) {

       Scanner sc = new Scanner(System.in);

       System.out.print("Card number: ");

       int card = sc.nextInt();

       System.out.println();

       System.out.print("Age: ");

       int age = sc.nextInt();

       System.out.println();

       System.out.print("Select item type 1.Book 2.Magzine 3.DVD");

       int item = sc.nextInt();

       System.out.println();

       System.out.print("Number of days overdue: ");

       int days = sc.nextInt();

       Library l = new Library();

       l.setAge(age);

       if(item == 1)

           l.setItemType("Book");

       else if(item == 2)

           l.setItemType("Magzine");

       else

           l.setItemType("DVD");

       l.setLibCard(card);

       l.calculateFine();

   }

}

class Library{

   int libCard;

   int age;

   int numberDaysOverDue;

   String itemType;

   public int getLibCard() {

       return libCard;

   }

   public void setLibCard(int libCard) {

       this.libCard = libCard;

   }

   public int getAge() {

       return age;

   }

   public void setAge(int age) {

       this.age = age;

   }

   public int getNumberDaysOverDue() {

       return numberDaysOverDue;

   }

   public void setNumberDaysOverDue(int numberDaysOverDue) {

       this.numberDaysOverDue = numberDaysOverDue;

   }

   public String getItemType() {

       return itemType;

   }

   public void setItemType(String itemType) {

       this.itemType = itemType;

   }

   public void calculateFine() {

       if(this.getAge() > 70) {

           System.out.println("Overdue Fine: 0.00$");

           System.out.println("Fine adjustment reaosn: Senior Citizen");

       }

       else if (age >=6 && age <= 17) {

           System.out.println("Overdue Fine: 1.00$");

           System.out.println("Fine adjustment reaosn: Juvenile");

       }

       else {

           double fine;

           if(this.getItemType().equals("Books"))

           {

               fine = this.getNumberDaysOverDue() * 0.5;

               if(fine > 5.0) {

                   System.out.println("Overdue Fine: 5.0$");

                   System.out.println("Fine adjustment reaosn: Exceed Max");

               }

               else

                   System.out.println("Overdue Fine: "+fine+"$");

           }

           else if(this.getItemType().equals("Magzine")) {

               fine = this.getNumberDaysOverDue() * 0.25;

               if(fine > 5.0) {

                   System.out.println("Overdue Fine: 5.0$");

                   System.out.println("Fine adjustment reaosn: Exceed Max");

               }

               else

                   System.out.println("Overdue Fine: "+fine+"$");

           }

           else {

               fine = this.getNumberDaysOverDue() * 1.5;

               if(fine > 5.0) {

                   System.out.println("Overdue Fine: 5.0$");

                   System.out.println("Fine adjustment reaosn: Exceed Max");

               }

               else

                   System.out.println("Overdue Fine: "+fine+"$");

           }

       }

   }

}