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: 3733935 • 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 put javadocs doumentation

and see if there are any == methods that can be replaced with .equals methods ?

thank you

Explanation / Answer

import java.util.ArrayList; public class Catalog { private ArrayList catalogItems; public static int count; public Catalog() { catalogItems = new ArrayList(); count = 0; } /** * * @param catalogItem (catalog item to add to catalog) * Adds given catalogItem to the catalog */ public void add (CatalogItem catalogItem) { if (count < 100) { catalogItems.add(catalogItem); count++; } else { System.out.println("No more capacity to add catalog item"); } } /** * * @param itemID (id of catalog item) * @param description (description of catalog item) * @param priceValue (price of catalog item) * Adds a new catalog item with id, description and price */ 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"); } } /** * * @param itemID (id of catalog item) * @param description (new description of catalog item) * Updates description of given catalog item */ public void update (int itemID, String description) { for (int i=0;i