I need help with this Java problem as it's explained in the image below: Image attached can not edit only the code below: public class ShoppingList{ public void add(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){//remove all items with the same name. // *** 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 *** */ } //*****************DONOT modify codes below this line**************************** private Item[] list; private int numberOfItems; public ShoppingList(int initialSize){ list=new Item[initialSize]; } 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
I need help with this Java problem as it's explained in the image below: Image attached can not edit only the code below: public class ShoppingList{ public void add(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){//remove all items with the same name. // *** 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 *** */ } //*****************DONOT modify codes below this line**************************** private Item[] list; private int numberOfItems; public ShoppingList(int initialSize){ list=new Item[initialSize]; } 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
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
I need help with this Java problem as it's explained in the image below:
Image attached can not edit only the code below:
public class ShoppingList{
public void add(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){//remove all items with the same name.
// *** 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 ***
*/
}
//*****************DONOT modify codes below this line****************************
private Item[] list;
private int numberOfItems;
public ShoppingList(int initialSize){
list=new Item[initialSize];
}
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());
}
}
public void printItems(){
for(int i=0; i<numberOfItems; i++){
System.out.printf("%3s%-16s%3d %.2f\n",""+(i+1)+". ",list[i].getName(),list[i].getQuantity(), list[i].getUnitPrice());
}
}
public Item[] getList(){
return list;
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 5 images
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