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

Java: This is a program designed to manage a digital bibliography. A bibliograph

ID: 3889284 • Letter: J

Question

Java:

This is a program designed to manage a digital bibliography. A bibliography can contain either books or articles. The program can be extended to allow for other types of bibliography entries as well (such as book chapters, dissertations, on-line sources, etc.). 2. The program will allow the creation of a data store for books, articles, and other sources (see below, under “Non-functional Requirements”). The user will be able to add titles, edit titles, delete titles, search for titles, and create reading lists.

It will offer the capability for storing and displaying information about Publications. 2. The program will allow the user to enter information for the author and title of a Publication and optionally the city, publisher, and year of publication. 3. The program will store the bibliographic information in a Publication object within a one-dimensional array of Publication objects. 4. The program will allow the user to delete the last Publication entered.

Need to write the model class as well as the JUnit Test Class.

******************************************************************************************

Publication: This class represents a single publication. It will need instance variables to store the author (String), title (String), city (String), publisher (String), and year of publication (int). It will need methods to set and get these values. It will also need a toString() method that returns the String required for the display list. This class will require the following methods:

• public Publication( String author, String title, String city, String publisher, int year ) — This constructor will set the values of the incoming parameters to the respective instance variables. You should use the various set... methods below to accomplish the assignments.

• public boolean canAdd() — This method will return true if the Publication object is correctly configured and false otherwise. A Publication object will be correctly configured if both the author and title attributes contain values (!null && length > 0) and the year is valid (between 1450 and the year after this one or 0 if not entered).

• public String getAuthor() — This method will return the author String. • public String getCity() — This method will return the city String.

• public String getPublisher() — This method will return the publisher String.

• public String getTitle() — This method will return the title String.

• public int getYear() — This method will return the year (as an int).

• public boolean setAuthor( String author ) — This method will set the value of the author attribute. The method will return true if the value of author is valid (!null && length > 0). If the incoming parameter is either null or an empty String, then the method should assign an empty String to author and return false.

• public void setCity( String city ) — This method will set the value of the city attribute. If the incoming parameter is null, then the value should be set to an empty String (””).

• public void setPublisher( String publisher ) — This method will set the value of the publisher attribute. If the incoming parameter is null, then the value should be set to an empty String (””).

• public boolean setTitle( String title ) — This method will set the value of the title attribute. The method will return true if the value of title is valid (!null && length > 0). If the incoming parameter is either null or an empty String, then the method should assign an empty String (””) to title and return false.

• public boolean setYear( int year ) — This method sets the value of the year attribute. The method will return true if the value of year is valid (>= 1450 && <= current year + 1) and false otherwise. Note: zero (0) is also allowed if no year is being stored. Note: this method should accept and maintain whatever value is sent. If the date is invalid, then the method should return false and the canAdd() method should return false.

• public String toString() — this method returns the String required for the display list (see above).

• Bibliography: This class represents the collection of publications used by your program. It will need an instance variable to represent the collection — this will be built around an array of Publication objects — as well as an int variable called last that indicates the position in the array for the last element added. As a collection, this class will require methods to add a Publication to the collection, delete a Publication from the collection, and get (return) a Publication from the collection. You should also provide a method that returns the size of the collection (the number of Publications currently stored, not the size of the array). This class will require the following public methods:

• public boolean add( Publication pub ) — This method adds a Publication to the end of the list. This method will return true if the Publication can be added successfully. A Publication can be added successfully if its canAdd() method returns true. If the Publication cannot be added (if its canAdd() method returns false), then the method should return false. Note: this method will need to check the size of the array to ensure that there is room to add the Publication. If the array is full, the method will need to double the size of the array as indicated below. You will need to increment the value of last whenever a Publication is added.

• public int capacity() — This method returns the current size (capacity) of the array. • public boolean deleteLast() — This method removes from the array the last Publication object that was added. You will need to decrement the value of last whenever a Publication is removed.

• public Publication get( int whichOne ) — This method will return the Publication object found at the position indicated by whichOne. If the value of whichOne is invalid, then the method should return null.

• public int size() — This method returns the size of the collection (the number of Publication objects currently stored). This is not the same as the capacity of the array (unless, of course, the array is full).

Explanation / Answer

public class Publication {

private String author;

private String title;

private String city;

private String publisher;

private int year;

/**

* @param author

* @param title

* @param city

* @param publisher

* @param year

*/

public Publication(String author, String title, String city,

String publisher, int year) {

this.author = author;

this.title = title;

this.city = city;

this.publisher = publisher;

this.year = year;

}

/**

* @return

*/

public boolean canAdd() {

if ((author != null && author.length() > 0)

&& (title != null && title.length() > 0)

&& (year >= 1450 && year <= 2018 && year != 0))

return true;

return false;

}

public String getAuthor() {

return author;

}

public String getCity() {

return city;

}

public String getPublisher() {

return publisher;

}

public String getTitle() {

return title;

}

public int getYear() {

return year;

}

/**

* @param author

* @return

*/

public boolean setAuthor(String author) {

if (author != null && author.length() > 0) {

this.author = author;

return true;

} else {

this.author = "";

return false;

}

}

/**

* @param city

*/

public void setCity(String city) {

if (city != null)

this.city = city;

else

this.city = "";

}

/**

* @param publisher

*/

public void setPublisher(String publisher) {

if (publisher != null)

this.publisher = publisher;

else

this.publisher = "";

}

/**

* @param title

* @return

*/

public boolean setTitle(String title) {

if (title != null && title.length() > 0) {

this.title = title;

return true;

} else {

this.title = "";

return false;

}

}

/**

* @param year

* @return

*/

public boolean setYear(int year) {

if (year >= 1450 && year <= 2018 && year != 0) {

this.year = year;

return true;

} else

return false;

}

/*

* (non-Javadoc)

*

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

return "Publication [author=" + author + ", title=" + title + ", city="

+ city + ", publisher=" + publisher + ", year=" + year + "]";

}

}

public class Bibliography {

private Publication[] publications;

private int last;

/**

*

*/

public Bibliography() {

// TODO Auto-generated constructor stub

publications = new Publication[10];

last = 0;

}

/**

*

*/

private void resize() {

Publication[] publicationsNew = new Publication[2 * publications.length];

System.arraycopy(publicationsNew, 0, publications, 0,

publications.length);

this.publications = publicationsNew;

}

/**

* @param pub

* @return

*/

public boolean add(Publication pub) {

if (pub.canAdd()) {

if (last == publications.length) {

resize();

}

publications[last] = pub;

last++;

return true;

} else

return false;

}

public int capacity() {

return publications.length;

}

public boolean deleteLast() {

last--;

return true;

}

/**

* @param whichOne

* @return

*/

public Publication get(int whichOne) {

if (whichOne < last)

return publications[whichOne];

return null;

}

public int size() {

return last;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote