JAVA IS THE LANGUAGE USED. THE BOOK USED IS HOW TO PROGRAM EARLY OBJECTS 10TH ED
ID: 3599568 • Letter: J
Question
JAVA IS THE LANGUAGE USED. THE BOOK USED IS HOW TO PROGRAM EARLY OBJECTS 10TH ED BY DEITEL DEITEL
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. The skeleton of the database structure is shown using the Unified Modeling Language (UML) 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 ArrayList instead 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:
«interface» Comparable + CompareTo0 (implements) «abstract» Item Database - item: Item + Database(0) + addltem(item: Item) + list) - id: String - title: String - addedOn: Date + Item(id: String, title: String, addedOn: Date) (has-a) (extends) «abstract» MultiMedialtem Textbook - plavingTime: integer + MultiMedialtem(id: String, title: String addedOn: Date, playingTime: Integer) - author: Strin +Textbook(id: String, title: String, addedOn: Date, author: String) (extends) CD Video - artist: Strin +CD(id: String, title: String, addedOn: Date, playingTime: integer, artist: String) - director: Strin + Video(id: String, title: String addedOn: Date, playingTime: integer, director: String)Explanation / Answer
Given the code for the object heirarchy as described in the question. For the main program to run, code is needed for ComparatorChain, sortByTitle, sortByAddedOn, sortByDirector. All fields are marked private. I have added getter/setter for convenience ... You can remove them if not needed. If the classes sortByTitle, sortByAddedOn, sortByDirector need to access the fields director, addedon or title, remove the private keyword in front of the member variable declaration. Let me know if any help is needed. Post a comment.
To indent code in eclipse, select the code by pressing Ctrl+A and then press Ctrl+i
Item.java
import java.util.Date;
public abstract class Item implements Comparable<Item>{
private String id;
private String title;
private Date addedOn;
public Item(String id, String title, Date addedOn)
{
this.id = id;
this.title = title;
this.addedOn = addedOn;
}
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;
}
@Override
public int compareTo(Item o) {
return id.compareTo(o.id);
}
public String toString()
{
return "ID: " + id + ", Title: " + title + ", Added On: " + addedOn;
}
}
Database.java
import java.util.ArrayList;
public class Database {
ArrayList<Item> item;
public Database()
{
item = new ArrayList<Item>();
}
public void addItem(Item it)
{
item.add(it);
}
public void list()
{
for(Item i : item)
System.out.println(i);
}
}
TextBook.java
import java.util.Date;
public class TextBook extends Item {
private String author;
public TextBook(String id, String title, Date addedOn, String author) {
super(id, title, addedOn);
this.author = author;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String toString()
{
return "TextBook: [" + super.toString() + ", Author: " + author + "]";
}
}
MultiMediaItem.java
import java.util.Date;
public abstract class MultiMediaItem extends Item {
private int playingTime;
public MultiMediaItem(String id, String title, Date addedOn, int playingTime) {
super(id, title, addedOn);
this.playingTime = playingTime;
}
public int getPlayingTime() {
return playingTime;
}
public void setPlayingTime(int playingTime) {
this.playingTime = playingTime;
}
public String toString()
{
return super.toString() + ", Playing Time: " + playingTime;
}
}
CD.java
import java.util.Date;
public class CD extends MultiMediaItem {
private String artist;
public CD(String id, String title, Date addedOn, int playingTime, String artist) {
super(id, title, addedOn, playingTime);
this.artist = artist;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String toString()
{
return "CD: [ "+ super.toString() + ", Artist: " + artist + "]";
}
}
Video.java
import java.util.Date;
public class Video extends MultiMediaItem {
private String director;
public Video(String id, String title, Date addedOn, int playingTime, String director) {
super(id, title, addedOn, playingTime);
this.director = director;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String toString()
{
return "Video: [" + super.toString() + ", Director: " + director + "]";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.