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

There will be 2 service classes the application class is already writing and pro

ID: 3735559 • Letter: T

Question

There will be 2 service classes the application class is already writing and provided at the bottom As well as the expected output if it does not match the output it will not work

1st service class is CatalogItem

The CatalogItem class defines a single item in a store’s catalog of items available for purchase. Each

item has an integer itemID, which identifies the item, a description, and a price value. All fields

should be private, with accessor methods defined. The description and price fields should also define

mutator methods. Provide a default constructor which sets the fields to a default value, an overloaded

constructor which accepts values for all three fields and a copy constructor which creates a new object

which is a copy of the parameter object. A toString method should be defined to return

the itemID, description, and price,formatted in US currency, as a single descriptive string.

An equals method should be included. Two CatalogItem objects are considered equal when their three

field values are the same.

the 2nd class is Catalog

The Catalog class will maintain an ArrayList of CatalogItem objects. The Catalog class should be

capable of storing up to 100 CatalogItem objects in its list. However, at any given time, there is likely

less than 100 CatalogItem objects. The list and all of its object elements should be maintained privately

and not exposed to the client except through the methods provided.

The class's default constructor should instantiate an empty list of the maximum number of elements.

Here are the Method descriptions

The display method should display the list of CatalogItems currently stored in the ArrayList.

The add method adds a CatalogItem object to the ArrayList. There should be two versions of the

add method: one should accept one parameter, a CatalogItem object to add to the list. The second

add method should accept an itemId, description, and price for a CatalogItem object which

will be created and then added to the list. ensure encapsulation, the CatalogItem object

passed as a parameter to the add method must be copied before saving in the ArrayList.

The update method is used to change a CatalogItem object currently stored in the ArrayList.

There are two versions of this method. Both versions accept an itemId as the first parameter. The

second parameter is either a String value or a double value. The String value will be used to update the

CatalogItem object’s description field while the double value will be used to update the price

field.

The priceIncrease method should accept a percentage amount and increase the price field of

all CatalogItem objects in the list.

The getCatalogItem method should accept an itemId as a parameter and return the matching

CatalogItem from the ArrayList. If no matching CatalogItem is found, null should be returned.

The toString method should return the entire list as a String. For easy display, include the newline

(' ') character in the String between the CatalogItems.

A static field should be maintained to reflect the current number of CatalogItems held in the ArrayList.

The client application is already writing

public class Lab6

{

public static void main(String[] args)

{

   System.out.println("Class has not been created. There are " + Catalog.count + " items.");

   Catalog myCatalog = new Catalog();

            System.out.println(" Catalog class created. ");

            myCatalog.display();

   CatalogItem item1 = new CatalogItem(123, "Pencils", 1.25);

            CatalogItem item2 = new CatalogItem(234, "Crayons", 2.50);

            CatalogItem item3 = new CatalogItem(567, "Paper", 5.00);

            myCatalog.add(item1);

            myCatalog.add(item2);

            myCatalog.add(item3);

            myCatalog.display();

           

   myCatalog.add(987,"Coloring Book",9.75);

            myCatalog.add(876,"Magic Marker",3.75);

            myCatalog.display();

           

            System.out.print(" Changed LOCAL item " + item1.toString() + " to " );

            item1.setDescription("Pencils (10 count)");

            System.out.println(item1.toString());

            System.out.println("Change should NOT be reflected in the catalog!");

            myCatalog.display();

   System.out.println(" Changed first item in the catalog");

   myCatalog.update(item1.getItemId(),"Pencils (15 count)");

            myCatalog.update(item1.getItemId(),1.75);

            myCatalog.display();

           

   System.out.println(" Increasing prices by 10%");

            myCatalog.priceIncrease(.10);

            myCatalog.display();

           

   System.out.println(" LOCAL item2 should contain original price " +

                               item2.toString());

   System.out.println(" Locating a CatalogItem");

   CatalogItem cat = myCatalog.getCatalogItem(123);

            if (cat != null)

               System.out.println("Found item 123!");

            else

               System.out.println("Didn't find item 123!");

                       

            CatalogItem cat2 = myCatalog.getCatalogItem(123456);

            if (cat2 != null)

               System.out.println("Found item 123456!");

            else

               System.out.println("Didn't find item 123456!");

                       

   System.out.println(" Here is the final list: " + myCatalog.toString());

}

}

And the expected results

Class has not been created. There are 0 items.

Catalog class created.

The Catalog consists of 0 items.

The Catalog consists of 3 items.

Item: 123, Pencils. Price: $1.25

Item: 234, Crayons. Price: $2.50

Item: 567, Paper. Price: $5.00

The Catalog consists of 5 items.

Item: 123, Pencils. Price: $1.25

Item: 234, Crayons. Price: $2.50

Item: 567, Paper. Price: $5.00

Item: 987, Coloring Book. Price: $9.75

Item: 876, Magic Marker. Price: $3.75

Changed LOCAL item Item: 123, Pencils. Price: $1.25 to Item: 123, Pencils (10 count). Price: $1.25

Change should NOT be reflected in the catalog!

The Catalog consists of 5 items.

Item: 123, Pencils. Price: $1.25

Item: 234, Crayons. Price: $2.50

Item: 567, Paper. Price: $5.00

Item: 987, Coloring Book. Price: $9.75

Item: 876, Magic Marker. Price: $3.75

Changed first item in the catalog

The Catalog consists of 5 items.

Item: 123, Pencils (15 count). Price: $1.75

Item: 234, Crayons. Price: $2.50

Item: 567, Paper. Price: $5.00

Item: 987, Coloring Book. Price: $9.75

Item: 876, Magic Marker. Price: $3.75

Increasing prices by 10%

The Catalog consists of 5 items.

Item: 123, Pencils (15 count). Price: $1.93

Item: 234, Crayons. Price: $2.75

Item: 567, Paper. Price: $5.50

Item: 987, Coloring Book. Price: $10.73

Item: 876, Magic Marker. Price: $4.13

LOCAL item2 should contain original price

Item: 234, Crayons. Price: $2.50

Locating a CatalogItem

Found item 123!

Didn't find item 123456!

Here is the final list:

The Catalog consists of 5 items.

Item: 123, Pencils (15 count). Price: $1.93

Item: 234, Crayons. Price: $2.75

Item: 567, Paper. Price: $5.50

Item: 987, Coloring Book. Price: $10.73

Item: 876, Magic Marker. Price: $4.13

Can you write these in java fallowing the directions given and use JGrasp

take your time and fallow the directions to the letter

when finished it will LOOK LIKE THE CODE BELLOW IT WILL HAVE A

.copy() method

.equals() method

.toString() method

/////////////////////////////////////////////////////////// sample bellow

import java.util.ArrayList;
class BookList {

private ArrayList<Book> catalog;
private static int numBooks = 0;

public BookList() {
catalog = new ArrayList<Book>();
}

public void add(Book book) {
Book newBook = new Book(book);
catalog.add(newBook);
numBooks++;
}
public void update(String title, double newPrice) {
for (Book book : catalog) {
if (title.equals(book.getTitle())) {
book.setPrice(newPrice);
}
}

}
public Book find(String title) {
Book foundBook = null;
for (Book book : catalog) {
if (title.equals(book.getTitle())) {
foundBook = new Book(book);
}
}
return foundBook;
}
public void display() {
System.out.println("-------------");
System.out.printf("There are %d books in your catalog ",
numBooks);
System.out.println(this.toString());
}

public String toString() {
String str = "";
for (Book book : catalog)
str += book.toString() + " ";
return str;
}
}

//////////////////////////////////////////////

class BookStore {
public static void main(String[] args) {

Book b1 = new Book("Intro to Java",
"James", 56.99);
System.out.println(b1);

Book b2 = b1; //same object
b2 = new Book(b1);
System.out.println(b2);

if (b2.equals(b1))
System.out.println("MATCH");

b2.setPrice(99.99);
System.out.println(b1);
System.out.println(b2);

b2 = b1.copy();
System.out.println("--------------");
b2 = new Book("Advanced Java", "Green", 65.99);

BookList books = new BookList();
books.add(b1);
books.add(b2);
System.out.println(books);
b1.setPrice(99.99);
System.out.println("changed b1");
System.out.println(books);

books.display();

books.update("Advanced Java", 99.99);
books.display();

b1 = books.find("Advanced Java");
b1.setPrice(199.99);
books.display();

books.add(new Book("Java Servlets", "Brown", 75.99));
books.display();
}//end main

}//end class

Explanation / Answer

package lab6;

public class Lab6

{

   public static void main(String[] args)

   {

       System.out.println("Class has not been created. There are " + Catalog.count + " items.");

       Catalog myCatalog = new Catalog();

       System.out.println(" Catalog class created. ");

       myCatalog.display();

       CatalogItem item1 = new CatalogItem(123, "Pencils", 1.25);

       CatalogItem item2 = new CatalogItem(234, "Crayons", 2.50);

       CatalogItem item3 = new CatalogItem(567, "Paper", 5.00);

       myCatalog.add(item1);

       myCatalog.add(item2);

       myCatalog.add(item3);

       myCatalog.display();

       myCatalog.add(987, "Coloring Book", 9.75);

       myCatalog.add(876, "Magic Marker", 3.75);

       myCatalog.display();

       System.out.print(" Changed LOCAL item " + item1.toString() + " to ");

       item1.setDescription("Pencils (10 count)");

       System.out.println(item1.toString());

       System.out.println("Change should NOT be reflected in the catalog!");

       myCatalog.display();

       System.out.println(" Changed first item in the catalog");

       myCatalog.update(item1.getItemId(), "Pencils (15 count)");

       myCatalog.update(item1.getItemId(), 1.75);

       myCatalog.display();

       System.out.println(" Increasing prices by 10%");

       myCatalog.priceIncrease(.10);

       myCatalog.display();

       System.out.println(" LOCAL item2 should contain original price " +

               item2.toString());

       System.out.println(" Locating a CatalogItem");

       CatalogItem cat = myCatalog.getCatalogItem(123);

       if (cat != null)

           System.out.println("Found item 123!");

       else

           System.out.println("Didn't find item 123!");

       CatalogItem cat2 = myCatalog.getCatalogItem(123456);

       if (cat2 != null)

           System.out.println("Found item 123456!");

       else

           System.out.println("Didn't find item 123456!");

       System.out.println(" Here is the final list: " + myCatalog.toString());

   }

}

package lab6;

import java.util.ArrayList;

public class Catalog {
   private ArrayList<CatalogItem> items;
   public static int count = 0;

   public Catalog() {
       items = new ArrayList<>(100);
   }

   public void add(CatalogItem item) {
       items.add(item);
       count++;
   }

   public void add(int itemId, String description, double price) {
       CatalogItem item = new CatalogItem();
       item.setItemId(itemId);
       item.setDescription(description);
       item.setPrice(price);
       items.add(item);
       count++;
   }

   public void add(int itemId, double price, String description) {
       CatalogItem item = new CatalogItem();
       item.setItemId(itemId);
       item.setDescription(description);
       item.setPrice(price);
       items.add(item);
       count++;
   }

   public void display() {
       for (CatalogItem catalogItem : items) {
           System.out.println(catalogItem.toString());
       }

   }

   public void update(int itemId, String string) {
       for (CatalogItem catalogItem : items) {
           if (catalogItem.getItemId() == itemId) {
               catalogItem.setDescription(string);
           }

       }

   }

   public void update(int itemId, double d) {
       for (CatalogItem catalogItem : items) {
           if (catalogItem.getItemId() == itemId) {
               catalogItem.setPrice(d);
           }

       }

   }

   public void priceIncrease(double d) {
       for (CatalogItem catalogItem : items) {
           catalogItem.setPrice(catalogItem.getPrice() + d);
       }

   }

   public CatalogItem getCatalogItem(int itemId) {
       for (CatalogItem catalogItem : items) {
           if (catalogItem.getItemId() == itemId) {
               return catalogItem;
           }
       }
       return null;
   }

   @Override
   public String toString() {
       return "Catalog [items=" + items + "]";
   }
  
  

}

package lab6;

public class CatalogItem {
private int itemId;
private String description;
private double price;
public CatalogItem() {

}
public CatalogItem(int itemId, String description, double price) {
   super();
   this.itemId = itemId;
   this.description = description;
   this.price = price;
}
public int getItemId() {
   return itemId;
}
public void setItemId(int itemId) {
   this.itemId = itemId;
}
public String getDescription() {
   return description;
}
public void setDescription(String description) {
   this.description = description;
}
public double getPrice() {
   return price;
}
public void setPrice(double price) {
   this.price = price;
}
@Override
public String toString() {
   return "CatalogItem [itemId=" + itemId + ", description=" + description + ", price=" + price + "]";
}

}

Output

Class has not been created. There are 0 items.

Catalog class created.
CatalogItem [itemId=123, description=Pencils, price=1.25]
CatalogItem [itemId=234, description=Crayons, price=2.5]
CatalogItem [itemId=567, description=Paper, price=5.0]
CatalogItem [itemId=123, description=Pencils, price=1.25]
CatalogItem [itemId=234, description=Crayons, price=2.5]
CatalogItem [itemId=567, description=Paper, price=5.0]
CatalogItem [itemId=987, description=Coloring Book, price=9.75]
CatalogItem [itemId=876, description=Magic Marker, price=3.75]

Changed LOCAL item CatalogItem [itemId=123, description=Pencils, price=1.25] to CatalogItem [itemId=123, description=Pencils (10 count), price=1.25]
Change should NOT be reflected in the catalog!
CatalogItem [itemId=123, description=Pencils (10 count), price=1.25]
CatalogItem [itemId=234, description=Crayons, price=2.5]
CatalogItem [itemId=567, description=Paper, price=5.0]
CatalogItem [itemId=987, description=Coloring Book, price=9.75]
CatalogItem [itemId=876, description=Magic Marker, price=3.75]

Changed first item in the catalog
CatalogItem [itemId=123, description=Pencils (15 count), price=1.75]
CatalogItem [itemId=234, description=Crayons, price=2.5]
CatalogItem [itemId=567, description=Paper, price=5.0]
CatalogItem [itemId=987, description=Coloring Book, price=9.75]
CatalogItem [itemId=876, description=Magic Marker, price=3.75]

Increasing prices by 10%
CatalogItem [itemId=123, description=Pencils (15 count), price=1.85]
CatalogItem [itemId=234, description=Crayons, price=2.6]
CatalogItem [itemId=567, description=Paper, price=5.1]
CatalogItem [itemId=987, description=Coloring Book, price=9.85]
CatalogItem [itemId=876, description=Magic Marker, price=3.85]

LOCAL item2 should contain original price
CatalogItem [itemId=234, description=Crayons, price=2.6]

Locating a CatalogItem
Found item 123!
Didn't find item 123456!

Here is the final list: Catalog [items=[CatalogItem [itemId=123, description=Pencils (15 count), price=1.85], CatalogItem [itemId=234, description=Crayons, price=2.6], CatalogItem [itemId=567, description=Paper, price=5.1], CatalogItem [itemId=987, description=Coloring Book, price=9.85], CatalogItem [itemId=876, description=Magic Marker, price=3.85]]]

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