Don\'t really understand javadoc comments, never written them before. Need help
ID: 3872709 • Letter: D
Question
Don't really understand javadoc comments, never written them before. Need help writing them at the different makrked spots in the program.
public class Bibliography {
//
private Publication[] publications;
private int last;
public Bibliography() {
//
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;
}
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;
}
public Publication get( int c ) {
//
if ( c < last )
return publications[c];
return null;
}
public int size() {
//
return last;
}
}
*********************************************************************
public class Publication {
private String author;
private String title;
private String city;
private String publisher;
private int 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;
}
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;
}
public boolean setAuthor( String author ) {
if ( author != null && author.length() > 0 ) {
this.author = author;
return true;
} else {
this.author = "";
return false;
}
}
public void setCity( String city ) {
if (city != null) {
this.city = city;
} else {
this.city = "";
}
}
public void setPublisher( String publisher ) {
if (publisher != null) {
this.publisher = publisher;
} else {
this.publisher = "";
}
}
public boolean setTitle( String title ) {
if (title != null && title.length() > 0) {
this.title = title;
return true;
} else {
this.title = "";
return false;
}
}
public boolean setYear( int year ) {
if (year >= 1450 && year <= 2018 && year != 0) {
this.year = year;
return true;
} else
return false;
}
@Override
public String toString() {
return "Publication [ author=" + author + ", title=" + title + ", city="
+ city + ", publisher=" + publisher + ", year=" + year + " ]";
}
}
Explanation / Answer
Please find my answer.
/**
* @author pravesh
*
*/
public class Bibliography {
private Publication[] publications;
private int last;
/**
* default constructor
*/
public Bibliography() {
publications = new Publication[10];
last = 0;
}
/**
* resize publication array
*/
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;
}
/**
* @return capacity of publication array
*/
public int capacity() {
return publications.length;
}
/**
* @return true if last publication get deleted successfully
*/
public boolean deleteLast() {
last--;
return true;
}
/**
* @param c
* @return publication stored at cth index
*/
public Publication get( int c ) {
if ( c < last )
return publications[c];
return null;
}
/**
* @return number of publication stored
*/
public int size() {
return last;
}
}
#####################
/**
* @author pravesh
*
*/
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 true if Publication information is valid
*/
public boolean canAdd() {
if (( author != null && author.length() > 0 )
&& ( title != null && title.length() > 0 )
&& ( year >= 1450 && year <= 2018 && year != 0 )) {
return true;
}
return false;
}
/**
* @return author
*/
public String getAuthor() {
return author;
}
/**
* @return city
*/
public String getCity() {
return city;
}
/**
* @return publisher
*/
public String getPublisher() {
return publisher;
}
/**
* @return title
*/
public String getTitle() {
return title;
}
/**
* @return year
*/
public int getYear() {
return year;
}
/**
* @param author
* @return true if author get updated successfully
*/
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 true if title is updated successfully
*/
public boolean setTitle( String title ) {
if (title != null && title.length() > 0) {
this.title = title;
return true;
} else {
this.title = "";
return false;
}
}
/**
* @param year
* @return true if year is updated successfully
*/
public boolean setYear( int year ) {
if (year >= 1450 && year <= 2018 && year != 0) {
this.year = year;
return true;
} else
return false;
}
@Override
public String toString() {
return "Publication [ author=" + author + ", title=" + title + ", city="
+ city + ", publisher=" + publisher + ", year=" + year + " ]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.