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.
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
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();
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education