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

Consider the management and maintenance of a \"library database\" in a certain s

ID: 3604455 • Letter: C

Question

Consider the management and maintenance of a "library database" in a certain school. It holds the information of material resources in use for students in that school. This information is recorded based on the object-oriented design.    (https://en.wikipedia.org/wiki/Object-oriented_design)The skeleton of the database structure is shown using the Unified Modeling Language (UML) ( https://en.wikipedia.org/wiki/Unified_Modeling_Language) diagramming method illustrated below. UML's standard notion is still being finalized for global use, and so annotations such as (has-a) to express object composition and (implements) to express inheritance are added to the diagram:

The above structure shows object variables and constructors only. Plus sign (+) indicates public visibility whereas minus sign (-) sets out private scope. The Database may use ArrayListinstead of Array to hold the collection of Item's references. Add an appropriate set of overloading/overriding methods to support the object hierarchy assumed in this context. Implement the hierarchy, populate Database with at least two items per non-abstract class, and show the "unsorted" and "sorted" list of the set of those instances. The minimal requirement of this assignment is to realize the database sort based on the lexicographical order of id as well as any combination of data variables. For instance, database records are shown based on the lexicographical order of "title," followed by"addedOn," and followed by "director."

Requirements

Realize your implementation that satisfies the following minimal requirements:

2 pt: properly exhibits right logic, i.e., readable and compilable coding

2 pt: properly realizes object hierarchy with added methods

2 pt: properly realizes object listing

2 pt: properly realizes sorting of database items based on their id values

2 pt: properly realizes sorting of database with any fields designated sorting order of items in database

extra credit: implementing with ArrayList instead of Array.

See Comparator example here(http://www.java2s.com/Code/Java/Apache-Common/ComparatorExampleForUserDefinedClass.htm) to realize all the requirements defined above. As a hint of your implementation, the following coding of main function should list the output of what this assignment mandates:

public static void main(String args[]) {

ComparatorChain chain = new ComparatorChain();

Database library = new Database();

Calendar cal = Calendar.getInstance();

// adding database entries

cal.set(1890, Calendar.AUGUST, 10);

Date date = (Date) cal.getTime();

library.addItem(new Textbook("TB15", "TextX", date, "John Doe"));

               

cal.set(1954, Calendar.JANUARY, 18);

date = (Date) cal.getTime() ;

library.addItem(new Video("V09", "VideoB", date, 70000, "J. Smith"));

               

cal.set(2000, Calendar.FEBRUARY, 29);

date = (Date) cal.getTime() ;

library.addItem(new Textbook("TB01", "TextY", date, "John Doe"));

             

cal.set(2000, Calendar.FEBRUARY, 29);

date = (Date) cal.getTime() ;

library.addItem(new CD("CD07", "CD1", date, 1000, "B.D."));

               

cal.set(1990, Calendar.APRIL, 30);

date = (Date) cal.getTime() ;

library.addItem(new CD("CD10", "CD1", date, 800, "X.Y."));

               

cal.set(2000, Calendar.FEBRUARY, 29);

date = (Date) cal.getTime();

library.addItem(new CD("CD05", "CD1", date, 1000, "B.C."));

               

cal.set(1890, Calendar.JULY, 2);

date = (Date) cal.getTime();

library.addItem(new Video("V12", "VideoA", date, 7000, "Joe Smith"));

               

// print unsorted database

System.out.println("----- DATABASE BEFORE SORTING: ----- ");

library.list();

// sort and print sorted database (by id)

Collections.sort(library.item);

System.out.println("----- DATABASE AFTER SORTING BY ID (default): ----- ");

library.list();

// sort by other fields

System.out.println("----- DATABASE AFTER SORTING BY OTHER FIELDS: -----");

System.out.println("------------ (title, addedOn, director) ----------- ");

chain.addComparator(new sortByTitle());

chain.addComparator(new sortByAddedOn());

  chain.addComparator(new sortByDirector());

Collections.sort(library.item, chain);  

library.list();

}

Please sumbmit the complete program working as required in the question. Thank you.

Do not add anything extra. Just what is aksed in the question.

interface» Comparable + Compare ToO (implements) «abstract» tem Database - id: String - title: String - addedOn: Date (has-a) - item: Item +Database) + addltem(item: Item) + list0 + Item(id: String, title: String, addedOn: Date) (extends) Textbook abstract» MultiMedialtem - author: Strin +Textbook(id: String, title: String addedOn: Date, author: String) - plavingTime: integer MultiMedialtem(id: String, title: String addedOn: Date, playingTime: Integer) (extends) CD Video - director: Strin + Video(id: String, title: String, addedOn: Date, playing Time: integer director: String) - artist: Strin +CDid: String, title: String addedOn: Date, playingTime: integer artist: String)

Explanation / Answer

import java.sql.Date;

public class Item implements Comparable<Item>{

private String id;

private String title;

private Date addedOn;

Item(String id, String title, Date addedOn){

this.id = id;

this.setTitle(title);

this.setAddedOn(addedOn);

}

@Override

public int compareTo(Item o) {

if(Integer.parseInt(this.id) < Integer.parseInt(o.id))

return -1;

else if(Integer.parseInt(this.id) > Integer.parseInt(o.id))

return 1;

else

return 0;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public Date getAddedOn() {

return addedOn;

}

public void setAddedOn(Date addedOn) {

this.addedOn = addedOn;

}

}

-------------------------------------------------------------------------------------------

import java.sql.Date;

public abstract class MultiMediaItem extends Item {

private int playingTiem;

MultiMediaItem(String id, String title, Date addedOn, int playingTiem) {

super(id, title, addedOn);

this.setPlayingTiem(playingTiem);

}

public int getPlayingTiem() {

return playingTiem;

}

public void setPlayingTiem(int playingTiem) {

this.playingTiem = playingTiem;

}

}

--------------------------------------------------------------

import java.sql.Date;

public class TextBook extends Item {

private String author;

TextBook(String id, String title, Date addedOn, String author) {

super(id, title, addedOn);

this.setAuthor(author);

}

public String getAuthor() {

return author;

}

public void setAuthor(String author) {

this.author = author;

}

}

-----------------------------------------------------------------------------------------

import java.sql.Date;

public class CD extends MultiMediaItem {

private String artest;

CD(String id, String title, Date addedOn, int playingTiem, String artest) {

super(id, title, addedOn, playingTiem);

this.setArtest(artest);

}

public String getArtest() {

return artest;

}

public void setArtest(String artest) {

this.artest = artest;

}

}

--------------------------------------------------------------------------

import java.sql.Date;

public class Video extends MultiMediaItem {

private String director;

Video(String id, String title, Date addedOn, int playingTiem, String director) {

super(id, title, addedOn, playingTiem);

this.setDirector(director);

}

public String getDirector() {

return director;

}

public void setDirector(String director) {

this.director = director;

}

}

-----------------------------------------------------------------------------------------

public class Database {

private Item item[];

private int index=0;

public Database() {

}

Database(int size){

setItem(new Item[size]);

}

public Item[] getItem() {

return item;

}

public void setItem(Item item[]) {

this.item = item;

}

public void addItem(Item i){

item[index] = i;

index++;

}

public void list(){

for(int i=0; i<index; i++){

System.out.print(item[i]+" ");

}

}

}