
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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;
}
}
![***
*Item.java: Item class represents grocery items to be added to the shopping list
*1
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("%-50%-5d$%.2f", name,quantity, quantity*unitPrice);](https://content.bartleby.com/qna-images/question/4e135d5c-f867-4afd-9f0d-b505f4f19664/2f892c26-8911-4507-a12e-a82d5057b36c/b7r4tug_thumbnail.png)
Transcribed Image Text:***
*Item.java: Item class represents grocery items to be added to the shopping list
*1
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("%-50%-5d$%.2f", name,quantity, quantity*unitPrice);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved 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.Similar questions
- 1). Create the class called ArrayOperations2D and include the method findRowMax below public class ArrayOperations2D { public static intl] findRowMax (int [][] anArray) int [] max = new int [anArray. length]; //for each row for (int i=0; i< anArray. length; i++) int largest = anArray [1][0]; for (int i=0; < anArray [i].langthi i++) if (anArray[i](j] > largest) largest = anArray[illjl: max [i]=largest; } return max; 2). Include the method called findRowSums below public static int[] findRowSums (int [] [] anArray) int [] rowSums = new int [anArray.length]; for (int i=0; i< anArray.length; i++) int sum = 0; for (int j=0; j<anArray(jl.length; J++) sum+=anArray [i][jl; rowSums [1] =sum; } return rowSums; 3). Add a method called findColumnMax to the class. This method should find and return the maximum value in each column of the two dimensional array 4). Add a method called findColumnSum that calculates and returns the sum of each column. 5). Add a method called…arrow_forwardJava Task 1 Create an object of type FitnessExperiment that stores an array of StepsFitnessTracker, DistanceFitnessTracker, and HeartRateFitnessTracker objects. You could use code such as the following to initialise the array containing the fitness tracker measurements: FitnessTracker[] trackers = { new StepsFitnessTracker("steps", new Steps(230)), new StepsFitnessTracker("steps2", new Steps(150)), new StepsFitnessTracker("steps2", new Steps(150)), new HeartRateFitnessTracker("hr", new HeartRate(80)), new HeartRateFitnessTracker("hr", new HeartRate(80)) }; In the FitnessExperiment class, complete the implementation of the methods named getTotalSteps()and printExperimentDetails(). The comments in the code specify how they should operate and provide you with additional hints to get you started. You can use the method getSteps()in StepsFitnessTracker, but think how you will know the real type of each object in the array of fitness trackers (trackers in the example above). FitnessTracker…arrow_forwardJAVA Program Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an employee’s identification…arrow_forward
- JAVA PROGRAM Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an employee’s identification…arrow_forward1. a. Why does the compilation of the following overloaded functions result in a compiler error?int area(float);float area (float); b. Write two (2) overloaded functions that find the least (smallest) of two integers (first function) and two characters (second function). These should be value returning functions that return the least value of the type(s) specified. Write the functions only. This includes the function headers (prototypes not needed) and the function bodies. You do not need to write the function calls or any include or using statements.arrow_forwardHelparrow_forward
- Data Structure & Algorithm: Show by fully java coded examples how any two sorting algorithms work. You should test these with various array sizes and run them several times and record the execution times. At least four array sizes are recommended. 15, 20, 25, 30. It is recommended you write the classes and then demonstrate/test them using another class. Discuss the comparative efficiencies of your two chosen sorting algorithms.arrow_forwardJava - Gift Exchange *** Please include UML Diagram and notes in code Minimum requirements are: At least 1 loop An Array or ArrayList At least 3 Java classes Use methods I am trying to make it so that the program will: Prompt for the number of people included in exchange - If not even it will state that there has to be an even number and ask for the number of people included again (loops). Prompt to enter a participant's first name Prompt for the participant's age Print out the random matching of participants so that everyone gets a gift and everyone gives a gift. Please include UML Diagramarrow_forwardPlease help with this java problemarrow_forward
- JAVA PROGRAM Homework #1. Chapter 7. PC# 2. Payroll Class (page 488-489) Write a Payroll class that uses the following arrays as fields: * employeeId. An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 * hours. An array of seven integers to hold the number of hours worked by each employee * payRate. An array of seven doubles to hold each employee’s hourly pay rate * wages. An array of seven doubles to hold each employee’s gross wages The class should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeId array. That same employee’s pay rate should be stored in element 0 of the payRate array. The class should have a method that accepts an employee’s identification…arrow_forwardJava Netbeansarrow_forwardIn C# Use a one-dimensional array to solve the following problem. Write a class called ScoreFinder. This class receives a single dimensional integer array representing passer ratings for NFL players as an argument for its constructor. The test class will provides this argument. The test class then calls upon a method from the ScoreFinder class to start the process of finding a specific rating, which will be provided by the user. The method will iterate through the array and find any matching values. For all the matches that are found, the method will note the index of the cell along with its value. At completion, the method will print a list of all the indices and the associated scores along with a count of all the matching values.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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