Written in java The project consists of these Java source code files: ShoppingList.txt Item.java ShoppingListDriver.java These files can be found under these questions/ Picture. 1. implement "insert" and "remove(overloaded)" methods as specified in the ShoppingList.txt file. 2. Once completed, download and compile ShoppingListDriver.java, and run ShoppingListDriver class to test your implementation. *************ShoppingList.txt*************** public class ShoppingList{ private Item[] list; private int numberOfItems; public ShoppingList(int initialSize){ list=new Item[initialSize]; } public void insert(Item item){ // *** Student task #1 *** /*    Requirements:    1. if null item is not allowed: do nothing if null    2. if the list is full, double the array size-dynamic array allocation    3. No duplicated items-all items' names must be unique. If an item with the same name    already exists in the list, simply add quantity to the existing item in the list    4. insert the item to the array to maintain sorted-items are sorted based on item names. *** Enter your code below *** */   } public void remove(Item item){ // *** Student task #2 *** /*    Requirements:    1. If item not found(item name), display the item does not exists in the list    otherwise, remove the item from the list.    2. Hint: You do need to shift all items after removed one. *** Enter your code below *** */ } public void remove(String name){       // remove item by its name // *** Student task #3 *** /*    Requirements:    1. If item not found(item name), display the item does not exists in the list    otherwise, remove the item from the list.    2. Hint: You do need to shift all items after removed one. *** Enter your code below *** */ } private void doubling(){ //Double the list size but keep all items in the list. Item[] tmp=new Item[list.length*2]; for(int i=0; i{ private String name; //product name private int quantity; //quantity private double unitPrice; //unit price public Item(String name, int quantity, double unitPrice){ setName(name); setQuantity(quantity); setUnitPrice(unitPrice); } public String getName(){ return name; } public int getQuantity(){ return quantity; } public double getUnitPrice(){ return unitPrice; } public void setName(String name){ // The length of product name is limited to [1,50], if more than 50 characters, use the first 50 chars // must neigher be a null value nor an empty String (throw runtime exception) if(name ==null || name.length()==0){ throw new RuntimeException("null or empty String value is not allowed"); } if(name.length()>50){ name=name.substring(0, 50); } this.name = name; } public void setQuantity(int quantity){ //quantity is limited to [1, 100], assign 1 for all invalid numbers if(quantity<1 || quantity>100){ quantity=1; } this.quantity = quantity; } public void setUnitPrice(double unitPrice){ //unitPrice is limited to (0, 1000], assign 0.99 for all invalid numbers if(unitPrice<=0 || unitPrice>1000){ unitPrice=0.99; } this.unitPrice = unitPrice; } public int compareTo(Item item){ //compare two items based on their names, ignore cases return name.toLowerCase().compareTo(item.getName().toLowerCase()); } public double subtotal(){ return quantity*unitPrice; } public String toString(){ return String.format("%-50s%-5d$%.2f",name,quantity, quantity*unitPrice); } } *************ShoppingListDriver.java*************** public class ShoppingListDriver{ public static void main(String[] args){ ShoppingList sl=new ShoppingList(3); sl.insert(null); sl.insert(new Item("Bread", 2, 2.99)); sl.insert(new Item("Seafood", -1, 10.99)); sl.insert(new Item("Rice", 2, 19.99)); sl.insert(new Item("Salad Dressings", 2, 19.99)); sl.insert(new Item("Eggs", 2, 3.99)); sl.insert(new Item("Cheese", 2, 1.59)); sl.insert(new Item("Eggs", 3, 3.99)); sl.printNames(); sl.print(); System.out.println("After removing Eggs:"); sl.remove("Eggs"); sl.printNames(); } } 3. If you implement all the required methods correctly, the driver program should generate outputs similar to the following:

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
100%

Written in java

The project consists of these Java source code files:

  • ShoppingList.txt
  • Item.java
  • ShoppingListDriver.java

These files can be found under these questions/ Picture.

1. implement "insert" and "remove(overloaded)" methods as specified in the ShoppingList.txt file.

2. Once completed, download and compile ShoppingListDriver.java, and run ShoppingListDriver class to test your implementation.

*************ShoppingList.txt***************

public class ShoppingList{
private Item[] list;
private int numberOfItems;
public ShoppingList(int initialSize){
list=new Item[initialSize];
}
public void insert(Item item){

// *** Student task #1 ***

/*
   Requirements:
   1. if null item is not allowed: do nothing if null
   2. if the list is full, double the array size-dynamic array allocation
   3. No duplicated items-all items' names must be unique. If an item with the same name
   already exists in the list, simply add quantity to the existing item in the list
   4. insert the item to the array to maintain sorted-items are sorted based on item names.

*** Enter your code below ***
*/  
}
public void remove(Item item){

// *** Student task #2 ***

/*
   Requirements:
   1. If item not found(item name), display the item does not exists in the list
   otherwise, remove the item from the list.
   2. Hint: You do need to shift all items after removed one.

*** Enter your code below ***
*/

}
public void remove(String name){       // remove item by its name

// *** Student task #3 ***

/*
   Requirements:

   1. If item not found(item name), display the item does not exists in the list
   otherwise, remove the item from the list.
   2. Hint: You do need to shift all items after removed one.

*** Enter your code below ***
*/

}
private void doubling(){
//Double the list size but keep all items in the list.
Item[] tmp=new Item[list.length*2];
for(int i=0; i<list.length; i++){
tmp[i]=list[i];
}
list=tmp;
}
public int indexOf(Item item){
// return the index of the item that has the same item name in the list array, return -1 if not found
for(int i=0; i<numberOfItems; i++){
if(list[i].compareTo(item)==0)
return i;
}
return -1; // not found
}

public int indexOf(String name){
// return the index of the item that has the same item name in the list array, return -1 if not found
name=name.toLowerCase();
for(int i=0; i<numberOfItems; i++){
if(list[i].getName().toLowerCase().compareTo(name)==0)
return i;
}
return -1; // not found
}

public boolean isFull(){
return numberOfItems==list.length;
}

public boolean isEmpty(){
return numberOfItems==0;
}

public int size(){
return numberOfItems;
}

public void printNames(){
System.out.print("[");
for(int i=0; i<numberOfItems; i++){
System.out.print(list[i].getName());
if(i<numberOfItems-1)
System.out.print(", ");
}
System.out.println("]");
}  
public void print(){
for(int i=0; i<numberOfItems; i++){
System.out.println((i+1)+". "+list[i].toString());
}
}
}

*************Item.java***************

public class Item implements Comparable<Item>{
private String name; //product name
private int quantity; //quantity
private double unitPrice; //unit price

public Item(String name, int quantity, double unitPrice){
setName(name);
setQuantity(quantity);
setUnitPrice(unitPrice);
}

public String getName(){
return name;
}
public int getQuantity(){
return quantity;
}
public double getUnitPrice(){
return unitPrice;
}
public void setName(String name){
// The length of product name is limited to [1,50], if more than 50 characters, use the first 50 chars
// must neigher be a null value nor an empty String (throw runtime exception)
if(name ==null || name.length()==0){
throw new RuntimeException("null or empty String value is not allowed");
}
if(name.length()>50){
name=name.substring(0, 50);
}
this.name = name;
}
public void setQuantity(int quantity){
//quantity is limited to [1, 100], assign 1 for all invalid numbers
if(quantity<1 || quantity>100){
quantity=1;
}
this.quantity = quantity;
}
public void setUnitPrice(double unitPrice){
//unitPrice is limited to (0, 1000], assign 0.99 for all invalid numbers
if(unitPrice<=0 || unitPrice>1000){
unitPrice=0.99;
}
this.unitPrice = unitPrice;
}
public int compareTo(Item item){
//compare two items based on their names, ignore cases
return name.toLowerCase().compareTo(item.getName().toLowerCase());
}
public double subtotal(){
return quantity*unitPrice;
}
public String toString(){
return String.format("%-50s%-5d$%.2f",name,quantity, quantity*unitPrice);
}
}

*************ShoppingListDriver.java***************

public class ShoppingListDriver{

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

3. If you implement all the required methods correctly, the driver program should generate outputs similar to the following:

 

|[Bread, Cheese, Eggs, Rice, Salad Dressings, Seafood]
1. Bread
|2. Cheese
3. Eggs
4. Rice
5. Salad Dressings
6. Seafood
After removing Eggs:
[Bread, Cheese, Rice, Salad Dressings, Seafood]
$5.98
$3.18
$19.95
$39.98
$39.98
$10.99
2
2
5
2
2
1
Transcribed Image Text:|[Bread, Cheese, Eggs, Rice, Salad Dressings, Seafood] 1. Bread |2. Cheese 3. Eggs 4. Rice 5. Salad Dressings 6. Seafood After removing Eggs: [Bread, Cheese, Rice, Salad Dressings, Seafood] $5.98 $3.18 $19.95 $39.98 $39.98 $10.99 2 2 5 2 2 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
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
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