use Java to write this program no objects and method needed. only selection stat
ID: 3753208 • Letter: U
Question
use Java to write this program
no objects and method needed. only selection statements and loops. nothing more.
A local public library needs a program to calculate the overdue fines owed by its patrons. The library needs the clerk to enter the full name and age of the patron. The clerk also needs to enter the name and the number of days overdue for the item. (The library accounts for full days overdue and not partial days overdue.) The library wants the clerk to be presented with a menu from which the type of material overdue can be chosen. The menu should look as follows:
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. Senior Citizens (over the age of 70) do not pay fines. Juvenile patrons (ages 6 through 17) pay a maximum fine of $1.00. There is a maximum fine assessed of $5.00 for all other patrons.
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:
Name Mickey Mouse
Age 22
Item Name Fantasia
Item Type DVD
Number of Days Overdue 2
Overdue Fine $3.00
Each time the program is executed it calculates the fine for a single patron.
Explanation / Answer
import java.io.*;
class Books{
public static void main(String ... args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Name:");
String name=br.readLine();
System.out.println("Enter Age:");
int age=Integer.parseInt(br.readLine());
System.out.println("Enter Product Name:");
String pname=br.readLine();
System.out.println("Enter Due days:");
int duedays=Integer.parseInt(br.readLine());
System.out.println("Select choice:");
System.out.println("1. Books");
System.out.println("2. Magazine");
System.out.println("3. DVD");
int choice=Integer.parseInt(br.readLine());
double totaldue=0;
switch(choice){
case 0://50
if(age>70)
totaldue=0;
totaldue=duedays*0.50;
if(totaldue>1&&(age>=6&&age<=17))
totaldue=1;
else if(totaldue>5)
totaldue=5;
break;
case 1://25
if(age>70)
totaldue=0;
totaldue=duedays*0.25;
if(totaldue>1&&(age>=6&&age<=17))
totaldue=1;
else if(totaldue>5)
totaldue=5;
break;
case 2://150
if(age>70)
totaldue=0;
totaldue=duedays*1.50;
if(totaldue>1&&(age>=6&&age<=17))
totaldue=1;
else if(totaldue>5)
totaldue=5;
break;
}
System.out.println("Name "+name);
System.out.println("Age "+age);
System.out.println(" Item Name "+pname);
System.out.println(" Number of Days Overdue "+duedays);
System.out.println("Due $"+totaldue);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.