wrive java proram with comment •Library Fines • •A local public library needs a
ID: 3584897 • Letter: W
Question
wrive java proram with comment
•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):
–Book
–Magazine
–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)
Explanation / Answer
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+"$");
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.