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

import java.util.ArrayList; public class Catalog { private ArrayList<CatalogItem

ID: 3734472 • Letter: I

Question

import java.util.ArrayList;
public class Catalog {
private ArrayList<CatalogItem> catalogItems;
public static int count;
public Catalog() {
catalogItems = new ArrayList<CatalogItem>();
count = 0;
}
public void add (CatalogItem catalogItem) {
if (count < 100) {
catalogItems.add(catalogItem);
count++;
} else {
System.out.println("No more capacity to add catalog item");
}
}
public void add (int itemID, String description, double priceValue) {
if (count < 100) {
CatalogItem catalogItem = new CatalogItem(itemID, description, priceValue);
catalogItems.add(catalogItem);
count++;
} else {
System.out.println("No more capacity to add catalog item");
}
}
public void update (int itemID, String description) {
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
if (catalogItem.getItemId() == itemID) {
catalogItem.setDescription(description);
break;
}
}
}
public void update (int itemID, double priceValue) {
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
if (catalogItem.getItemId() == itemID) {
catalogItem.setPriceValue(priceValue);
break;
}
}
}
public void priceIncrease(double percentageAmount ) {
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
double newPriceValue = (catalogItem.getPriceValue() * percentageAmount) + catalogItem.getPriceValue();
catalogItem.setPriceValue(newPriceValue);
}
}
public CatalogItem getCatalogItem (int itemID) {
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
if (catalogItem.getItemId() == itemID) {
return catalogItem;
}
}
return null;
}
public void display() {
if (count > 0) {
System.out.println(" The Catalog consists of "+count+" items.");
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
System.out.println(catalogItem);
}
} else {
System.out.println(" The Catalog consists of 0 items.");
}
}
@Override
public String toString() {
String output = " The Catalog consists of "+count+" items. ";
for (int i=0;i<count;i++) {
CatalogItem catalogItem = catalogItems.get(i);
output = output + catalogItem + " ";
}
return output;
}
}

===================================

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

public class CatalogItem {
private int itemID;
private String description;
private double priceValue;
public CatalogItem() {
this.itemID = 0;
this.description = "";
this.priceValue = 0;
}
public CatalogItem(int itemID, String description, double priceValue) {
this.itemID = itemID;
this.description = description;
this.priceValue = priceValue;
}
public CatalogItem(CatalogItem catalogItem) {
this.itemID = catalogItem.itemID;
this.description = catalogItem.description;
this.priceValue = catalogItem.priceValue;
}
public int getItemId() {
return itemID;
}
public String getDescription() {
return description;
}
public double getPriceValue() {
return priceValue;
}
public void setDescription(String description) {
this.description = description;
}
public void setPriceValue(double priceValue) {
this.priceValue = priceValue;
}
@Override
public String toString() {
return "Item: " + itemID + ", " + description + ". Price: $" + String.format("%.2f", priceValue);
}
}

can you do javadocs on this and take your time(failure to fallow directions results in a downvote)?

Explanation / Answer

Below are the java classes having added JavaDocs. Please check it.

CatalogItem.java

/**

* @author

* Container Class to hold CatalogItems

*

*/

public class CatalogItem {

private int itemID;

private String description;

private double priceValue;

/**

* Default Constructor to set initial values

*/

public CatalogItem() {

this.itemID = 0;

this.description = "";

this.priceValue = 0;

}

/**

* Parameterized Constructor to set the catalogItem values.

* @param itemID

* @param description

* @param priceValue

*/

public CatalogItem(int itemID, String description, double priceValue) {

this.itemID = itemID;

this.description = description;

this.priceValue = priceValue;

}

/**

* Constructor to create a new CatalogItem object from existing one.

* @param catalogItem

*/

public CatalogItem(CatalogItem catalogItem) {

this.itemID = catalogItem.itemID;

this.description = catalogItem.description;

this.priceValue = catalogItem.priceValue;

}

/**

* getter method for itemID

* @return

*/

public int getItemId() {

return itemID;

}

/**

* getter method for description

* @return

*/

public String getDescription() {

return description;

}

/**

* getter method for priceValue

* @return

*/

public double getPriceValue() {

return priceValue;

}

/**

* setter method for description

* @param description

*/

public void setDescription(String description) {

this.description = description;

}

/**

* setter method for priceValue

* @param priceValue

*/

public void setPriceValue(double priceValue) {

this.priceValue = priceValue;

}

/* (non-Javadoc)

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

*/

@Override

public String toString() {

return "Item: " + itemID + ", " + description + ". Price: $" + String.format("%.2f", priceValue);

}

}

Catalog.java

import java.util.ArrayList;

/**

* @author

* Catalog class to perform CRUD operations on CatalogItem

*

*/

public class Catalog {

private ArrayList<CatalogItem> catalogItems;

public static int count;

/**

* Default Constructor that creates an array list of Catalog Items

*/

public Catalog() {

catalogItems = new ArrayList<CatalogItem>();

count = 0;

}

/**

* Method to add a catalogItem to the ArrayList

* @param catalogItem

*/

public void add(CatalogItem catalogItem) {

if (count < 100) {

catalogItems.add(catalogItem);

count++;

} else {

System.out.println("No more capacity to add catalog item");

}

}

/**

* Method to create a new CatalogItem and add it to the ArrayList

* @param itemID

* @param description

* @param priceValue

*/

public void add(int itemID, String description, double priceValue) {

if (count < 100) {

CatalogItem catalogItem = new CatalogItem(itemID, description, priceValue);

catalogItems.add(catalogItem);

count++;

} else {

System.out.println("No more capacity to add catalog item");

}

}

/**

* Method to update the description of catalogItem in ArrayList by itemID

* @param itemID

* @param description

*/

public void update(int itemID, String description) {

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

CatalogItem catalogItem = catalogItems.get(i);

if (catalogItem.getItemId() == itemID) {

catalogItem.setDescription(description);

break;

}

}

}

/**

* Method to update the pricevalue of catalogItem in ArrayList by itemID

* @param itemID

* @param priceValue

*/

public void update(int itemID, double priceValue) {

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

CatalogItem catalogItem = catalogItems.get(i);

if (catalogItem.getItemId() == itemID) {

catalogItem.setPriceValue(priceValue);

break;

}

}

}

/**

* Method to update the priceValue of all catalogItems in the ArrayList by a specified percentageAmount

* @param percentageAmount

*/

public void priceIncrease(double percentageAmount) {

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

CatalogItem catalogItem = catalogItems.get(i);

double newPriceValue = (catalogItem.getPriceValue() * percentageAmount) + catalogItem.getPriceValue();

catalogItem.setPriceValue(newPriceValue);

}

}

/**

* Method to retrieve a CatalogItem from ArrayList by itemID

* @param itemID

* @return

*/

public CatalogItem getCatalogItem(int itemID) {

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

CatalogItem catalogItem = catalogItems.get(i);

if (catalogItem.getItemId() == itemID) {

return catalogItem;

}

}

return null;

}

/**

* Method to display the contents of the CatalogItem ArrayList

*

*/

public void display() {

if (count > 0) {

System.out.println(" The Catalog consists of " + count + " items.");

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

CatalogItem catalogItem = catalogItems.get(i);

System.out.println(catalogItem);

}

} else {

System.out.println(" The Catalog consists of 0 items.");

}

}

/*

* (non-Javadoc)

*

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

*/

@Override

public String toString() {

String output = " The Catalog consists of " + count + " items. ";

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

CatalogItem catalogItem = catalogItems.get(i);

output = output + catalogItem + " ";

}

return output;

}

}