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

IN JAVA: A library has many type of materials to lend to patrons. Books, videos

ID: 3855960 • Letter: I

Question

IN JAVA:

A library has many type of materials to lend to patrons. Books, videos and DVDs are three types of these materials. All three have titles, but books have an author while videos and DVD have a director. Each can be lent out to a partron for 10 days (books) or 20 days (videos or DVDs). Make classes for the types of material along with a method that posts when the material was borrowed. That method should take a date and add the appropriate number of days and determine the due date properly of the material. The textbook covers date handling. Date is a class with specific properties and methods. In addition to the classes, write some code in a main method that creates media, has them borrowed by patrons and correctly tracks the due date.

Explanation / Answer

import java.io.*;
class book
{
void calc()throws IOException
{
String name,auth,date;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the name of the book");
name=br.readLine();
System.out.println("Enter the author of the book");
auth=br.readLine();
System.out.println("Enter the date you want to take in dd/mm/yyyy");
date=br.readLine().trim();
int t=10;
String fd="";
int mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int p,q,count=0;
p=date.indexOf("/");
int dd=Integer.parseInt(date.substring(0,p));
q=date.lastIndexOf("/");
int mm=Integer.parseInt(date.substring(p+1,q));
int yy=Integer.parseInt(date.substring(q+1));
  
if((yy%400==0) || ((yy%100!=0)&&(yy%4==0))) // Checking for leap year
mo[2]=29;

if(mm<0 || mm>12 || dd<0 || dd>mo[m] || yy<0 || yy>9999) // Performing Date Validation
{
System.out.println("Invalid Date");
}
else
{
while(count<t)
{
dd++;
count++;

if(dd>mo[m])
{
dd=1;
mm++;
}

if(mm>12)
{
mm=1;
yy++;
if((yy%400==0) || ((yy%100!=0)&&(yy%4==0)))
mo[2]=29;
else
mo[2]=28;
}
}
//fd=fd.concat(d)
//fd=fd+d+"/"+m+"/"+y;
//System.out.println("Future Date : "+fd);
}   
System.out.println("Name of the book"+name);
System.out.println("Name of the author"+name);
System.out.println("Issue Date"+date);
System.out.println("Return date"+dd+"/"+mm+"/"+yy);
}
}

class DVD
{
void calc()throws IOException
{
String name,auth,date;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the name of the DVD");
name=br.readLine();
System.out.println("Enter the director name");
auth=br.readLine();
System.out.println("Enter the date you want to take in dd/mm/yyyy");
date=br.readLine().trim();
int t=20;
String fd="";
int mo[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int p,q,count=0;
p=date.indexOf("/");
int dd=Integer.parseInt(date.substring(0,p));
q=date.lastIndexOf("/");
int mm=Integer.parseInt(date.substring(p+1,q));
int yy=Integer.parseInt(date.substring(q+1));
  
if((yy%400==0) || ((yy%100!=0)&&(yy%4==0))) // Checking for leap year
mo[2]=29;

if(mm<0 || mm>12 || dd<0 || dd>mo[m] || yy<0 || yy>9999) // Performing Date Validation
{
System.out.println("Invalid Date");
}
else
{
while(count<t)
{
dd++;
count++;

if(dd>mo[m])
{
dd=1;
mm++;
}

if(mm>12)
{
mm=1;
yy++;
if((yy%400==0) || ((yy%100!=0)&&(yy%4==0)))
mo[2]=29;
else
mo[2]=28;
}
}
//fd=fd.concat(d)
//fd=fd+d+"/"+m+"/"+y;
//System.out.println("Future Date : "+fd);
}   
System.out.println("Name of the book"+name);
System.out.println("Name of the author"+name);
System.out.println("Issue Date"+date);
System.out.println("Return date"+dd+"/"+mm+"/"+yy);
}
}
class lend
{
public static void main(String args[])throws IOException
{
book ob=new book();
DVD ob2=new DVD();
int ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("1.Rent Book");
System.out.println("2.DVD or vidoes");
System.out.println("Enter your choice");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
ob.calc();
break;
case 2:
ob2.calc();
break;
default:
System.out.println("Invalid Choice");
break;
}
  
}

}