In: Computer Science
A University Library has many items available for its students; some can be checked out and others cannot. Among those that can be checked out are journal (i.e., a literary journal) and digital video disk (i.e., a DVD). These two types have many attributes in common such as title, publisher, and dewey decimal classification. Design a class to represent the library item that would capture the common features among journals and DVDs. Then, design journal and digital video classes that are derived from the library item base class. If you feel confident enough to draw a UML class diagram depicting the classes, then feel free to do so. Otherwise, you can submit something like the following for each class The library item class does not need more attributes, but you should add at least 2 methods to the class. The journal and digital video classes should have at least 3 attributes and at least 2 methods.
The library item class does not need more attributes (you can use the ones provided, if you like), but you should add at least 2 methods to the class. The journal and digital video classes should have at least 3 attributes and at least 2 methods.
If you feel confident enough to draw a UML class diagram depicting the classes, then feel free to do so.
Deliverable
1) Implement your UML diagram into Java code for all 3 classes.
2) Create a driver class to test that your class design works. (Upload all 3 class files along with your driver class)
Deliverable
1) Implement your UML diagram into Java code for all 3 classes.
Content of the Library.java file
import java.util.Scanner;
public class Library
{
String title,publisher;
int DDC;
void setInfo()
{
Scanner sc= new
Scanner(System.in);
System.out.print("Enter the title
of the item: ");
title= sc.nextLine();
System.out.print("Enter the
publisher of the item: ");
publisher= sc.nextLine();
System.out.print("Enter the DDC of
the item: ");
DDC= sc.nextInt();
}
void display()
{
System.out.println("The title of
the item is" + title);
System.out.println("The publisher
of the item is" + publisher);
System.out.println("The DDC of the
item is" + DDC);
}
}
Content of the Journal.java file
import java.util.Scanner;
public class Journal extends Library
{
int cost,volume,issue;
void setInfo()
{
super.setInfo();
Scanner sc= new
Scanner(System.in);
System.out.print("Enter the cost of
the journal: ");
cost= sc.nextInt();
System.out.print("Enter the volume
of the journal: ");
volume= sc.nextInt();
System.out.print("Enter the issue
of the journal: ");
issue= sc.nextInt();
}
void display()
{
super.display();
System.out.println("The cost of the
journal is" + cost);
System.out.println("The volume of
the journal is" + volume);
System.out.println("The issue of
the journal is" + issue);
}
}
Content of the DigVideo.java file
import java.util.Scanner;
public class DigVideo extends Library
{
int cost,size,issue;
void setInfo()
{
super.setInfo();
Scanner sc= new
Scanner(System.in);
System.out.print("Enter the cost of
the digital video: ");
cost= sc.nextInt();
System.out.print("Enter the size of
the digital video: ");
size= sc.nextInt();
System.out.print("Enter the length
of the digital video: ");
issue= sc.nextInt();
}
void display()
{
super.display();
System.out.println("The cost of the
digital video is" + cost);
System.out.println("The size of the
digital video is" + size);
System.out.println("The length of
the digital video is" + issue);
}
}
Deliverable
2) Create a driver class to test that your class design works. (Upload all 3 class files along with your driver class)
Content of the Driver.java file
class Driver
{
public static void main(String args[])
{
Journal j= new Journal();
DigVideo d = new DigVideo();
System.out.println("Information of
Journal Item");
j.setInfo();
System.out.println();
System.out.println();
System.out.println("Information of
Digital Video Item");
d.setInfo();
System.out.println("\n\n Entered
intormation of the Journal is ");
j.display();
System.out.println("\n\n Entered
intormation of the Digital Video is ");
d.display();
}
}
*Note
The solution contains content of four files. Keep all thee file in same directory. use the following command to execute the code.
>>>javac Library.java
>>>javac Journal.java
>>>javac DigVideo.java
>>>javac Driver.java
>>>java Driver
Sample Input and Output: