Your Tasks: 1. Item class encapsulating a shopping item. An item has the following attributes: a. Name(String), the length of name is limited to [1, 50], use the first 50 characters if its length is greater than 50. For null or an empty String, throw RuntimeException with appropriate messages-either null or an empty String is not allowed. b. Category(String), the length of name is limited to [1, 50], use the first 50 characters if its lengt is greater than 50. For null or an empty String, throw RuntimeException with appropriate messages-either null or an empty String is not allowed. c. Quantity(int), its value is limited to [1, 100], for all invalid values, set default to 1. d. unitPrice(double). Its value is limited to [0, 1000], for all invalid values, set to 0.99. 2. The Item class implements Comparable that compares two items based on category, then item name, ignoring cases when comparing. 3. Item class should also include: a. Constructor that takes name, category, quantity, and unitPrice as parameters. b. All accessor and mutator methods c. Override toString() method to return item information as follows: (please note: without category, we will handle category in our ShoppingList ADT) Subtotal, for Item Name Quantity example: Eggs 2 $5.99 d. Subtotal() returns quantity"unitPrice 4. ShoppingList class. This class has the following methods: a. isEmpty() b. isFull() c. size()-return the number of unique items on the shopping list d. totalltems()-return the total number of items on the shopping list. For example, after adding two meats and 3 boxes of eggs, calling size() should return 2, while calling totalltems() should return 2+3= 5. e. grandTotal()-returns ground total of items on the shopping list. f. printNames()-print unique item names on the shopping list. g. print()-item name, quantity, subtotal, and grand total. Display categories for all items in the same category. Please refer to sample output at the end of this document. h. insert(Item item) with the following requirements: • if null item is not allowed: do nothing if null • No duplicated items-all items' category and name must be unique. If an item with the sam name and category already exists in the list, simply add quantity to the existing item in the list After inserting an item, the list should maintain sorted-based on category and name i. remove(Item item) with the following requirements: • Ifitem not found(item category and name), display the item does not exist in the list, otherwise, remove the item from the list.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

public class ShoppingListDriver{

public static void main(String[] args){
  
ShoppingList sl=new ShoppingList(3);
sl.insert(null);
sl.insert(new Item("Bread", "Carb Food", 2, 2.99));
sl.insert(new Item("Seafood","Sea Food", -1, 10.99));
sl.insert(new Item("Rice", "Carb Food",2, 19.99));
sl.insert(new Item("Salad Dressings","Dessing", 2, 19.99));
sl.insert(new Item("Eggs", "Protein",2, 3.99));
sl.insert(new Item("Cheese","Protein", 2, 1.59));
sl.insert(new Item("Eggs", "Protein",3, 3.99));
sl.printNames();
sl.print();
  
System.out.println("After removing Eggs:");
sl.remove(new Item("Eggs","Protein",0,0));
sl.printNames();
sl.print();
  
}
}

Your Tasks:
1. Item class encapsulating a shopping item. An item has the following attributes:
a. Name(String), the length of name is limited to [1, 50], use the first 50 characters if its length is
greater than 50. For null or an empty String, throw RuntimeException with appropriate
messages-either null or an empty String is not allowed.
b. Category(String), the length of name is limited to [1, 50], use the first 50 characters if its length
is greater than 50. For null or an empty String, throw RuntimeException with appropriate
messages-either null or an empty String is not allowed.
c. Quantity(int), its value is limited to [1, 100], for all invalid values, set default to 1.
d. unitPrice(double). Its value is limited to [0, 1000], for all invalid values, set to 0.99.
2. The Item class implements Comparable that compares two items based on category, then item
name, ignoring cases when comparing.
3. Item class should also include:
a. Constructor that takes name, category, quantity, and unitPrice as parameters.
b. All accessor and mutator methods
c. Override toString() method to return item information as follows: (please note: without
category, we will handle category in our ShoppingList ADT)
Subtotal, for
Item Name
Quantity
example:
Eggs
2
$5.99
d. Subtotall) returns quantity"unitPrice
4. ShoppingList class. This class has the following methods:
a. isEmpty()
b. isFull()
c. size()-return the number of unique items on the shopping list
d. totalltems()-return the total number of items on the shopping list. For example, after adding
two meats and 3 boxes of eggs, calling size() should return 2, while calling totalltems() should
return 2+3= 5.
e. grandTotal()-returns ground total of items on the shopping list.
f. printNames()-print unique item names on the shopping list.
g. print()-item name, quantity, subtotal, and grand total. Display categories for all items in the
same category. Please refer to sample output at the end of this document.
h. insert(Item item) with the following requirements:
• if null item is not allowed: do nothing if null
• No duplicated items-all items' category and name must be unique. If an item with the same
name and category already exists in the list, simply add quantity to the existing item in the
list
· After inserting an item, the list should maintain sorted-based on category and name
i. remove(ltem item) with the following requirements:
• If item not found(item category and name), display the item does not exist in the list,
otherwise, remove the item from the list.
5. Once completed, download and run the ShoppingListDriver class.
• ShoppingListDriver.java
6. If you implement all the required methods properly, the driver program should generate outputs
similar to the following:
Transcribed Image Text:Your Tasks: 1. Item class encapsulating a shopping item. An item has the following attributes: a. Name(String), the length of name is limited to [1, 50], use the first 50 characters if its length is greater than 50. For null or an empty String, throw RuntimeException with appropriate messages-either null or an empty String is not allowed. b. Category(String), the length of name is limited to [1, 50], use the first 50 characters if its length is greater than 50. For null or an empty String, throw RuntimeException with appropriate messages-either null or an empty String is not allowed. c. Quantity(int), its value is limited to [1, 100], for all invalid values, set default to 1. d. unitPrice(double). Its value is limited to [0, 1000], for all invalid values, set to 0.99. 2. The Item class implements Comparable that compares two items based on category, then item name, ignoring cases when comparing. 3. Item class should also include: a. Constructor that takes name, category, quantity, and unitPrice as parameters. b. All accessor and mutator methods c. Override toString() method to return item information as follows: (please note: without category, we will handle category in our ShoppingList ADT) Subtotal, for Item Name Quantity example: Eggs 2 $5.99 d. Subtotall) returns quantity"unitPrice 4. ShoppingList class. This class has the following methods: a. isEmpty() b. isFull() c. size()-return the number of unique items on the shopping list d. totalltems()-return the total number of items on the shopping list. For example, after adding two meats and 3 boxes of eggs, calling size() should return 2, while calling totalltems() should return 2+3= 5. e. grandTotal()-returns ground total of items on the shopping list. f. printNames()-print unique item names on the shopping list. g. print()-item name, quantity, subtotal, and grand total. Display categories for all items in the same category. Please refer to sample output at the end of this document. h. insert(Item item) with the following requirements: • if null item is not allowed: do nothing if null • No duplicated items-all items' category and name must be unique. If an item with the same name and category already exists in the list, simply add quantity to the existing item in the list · After inserting an item, the list should maintain sorted-based on category and name i. remove(ltem item) with the following requirements: • If item not found(item category and name), display the item does not exist in the list, otherwise, remove the item from the list. 5. Once completed, download and run the ShoppingListDriver class. • ShoppingListDriver.java 6. If you implement all the required methods properly, the driver program should generate outputs similar to the following:
(Bread, Rice, Salad Dressings, Cheese, Eggs, Seafood]
Name
Qty $Subtotal
Carb Food:
1. Bread
2. Rice
2 $5.98
2 $39.98
Dessing
1. Salad Dressings
2 $39.98
Protein:
1. Cheese
2. Eggs
2 $3.18
5 $19.95
Sea Food:
1. Seafood
1 $10.99
Number of Items: 14
Grand Totalt : $120.06
After removing Eggs:
(Bread, Rice, Salad Dressings, Cheese, Seafood]
Name
Qty $Subtotal
Carb Food:
1. Bread
2. Rice
2 $5.98
2 $39.98
Dessing:
1. Salad Dressings
2 $39.98
Protein:
1. Cheese
2 $3.18
Sea Food
1. Seafood
1 $10.99
Number of Items:
9
Grand Total:: $100.11
Transcribed Image Text:(Bread, Rice, Salad Dressings, Cheese, Eggs, Seafood] Name Qty $Subtotal Carb Food: 1. Bread 2. Rice 2 $5.98 2 $39.98 Dessing 1. Salad Dressings 2 $39.98 Protein: 1. Cheese 2. Eggs 2 $3.18 5 $19.95 Sea Food: 1. Seafood 1 $10.99 Number of Items: 14 Grand Totalt : $120.06 After removing Eggs: (Bread, Rice, Salad Dressings, Cheese, Seafood] Name Qty $Subtotal Carb Food: 1. Bread 2. Rice 2 $5.98 2 $39.98 Dessing: 1. Salad Dressings 2 $39.98 Protein: 1. Cheese 2 $3.18 Sea Food 1. Seafood 1 $10.99 Number of Items: 9 Grand Total:: $100.11
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education