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
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 stores 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 objects 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 and finally provide Javadocs documentation ?
take your time and fallow the directions to the letter (failure to do so results in a downvote)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started