subject

Grocery FRQ (ArrayLists) public class Grocery
{
private String category;
private int units;
private double price;
/*there may be other instance variables, constructors and methods not shown*/
public boolean equals (Grocery g)
{
/*implementation not shown*/
}
public int getUnits(){
return units;
}
public double getPrice(){
return price;
}
public String getCategory(){
return category;
}
public class Shopping
{
private ArrayList myGroceries;
public Shopping(Grocery[] groc){
/*to be implemented in part A*/
}
public Grocery findBestValue(String c){
/*to be implemented in part B*/
}
}
The Shopping constructor initializes the myGroceries instance variable with elements from the groc array. Only unique Grocery items are added to the myGroceries list (i. e. there are no duplicate Grocery items in myGroceries). A Grocery item is considered unique if at least one of the attributes differs (the category, units, and/or price). For example, if given the code:
Grocery[] theGroceries = {new Grocery("cereal", 1, 4.99), new Grocery("milk", 1, 4.29),
new Grocery("cereal", 2, 7.99), new Grocery("cereal", 1, 4.99),
new Grocery("candy", 48, 10.99), new Grocery("candy", 6, 1.00)};
Shopping myShopping = new Shopping(theGroceries);
The Grocery item "cereal", 1, 4.99 is not unique as there is another Grocery item with the same category, unit, and price.
The Grocery item "cereal", 2, 7.99 is unique because it is different from the other Grocery item by both the number of units and price.
Then the myGroceries arraylist of the Shopping class would be initialized with the following Grocery contents:
"cereal", 1, 4.99
"milk", 1, 4.29
"cereal", 2, 7.99
"candy", 48, 10.99
"candy", 6, 1.00
Complete the Shopping constructor.
Grocery items can be categorized. Grocery items have a number of units (quantity) and price (for the collection of units). The findBestValue method locates all Grocery items of the Shopping class with the same category c and determines the best priced option of the category by determining the lowest price per unit. The findBestValue method returns the best priced Grocery item of category c.
Precondition - there exists at least one such element with category c.
For example, the myGroceries arrayList contains the following Grocery items:
"cereal", 1, 4.99 (price per unit is 4.99)
"milk", 1, 4.29 (price per unit is 4.29)
"cereal", 2, 8.00 (price per unit is 4.00)
"candy", 50, 10.00 (price per unit is 0.20)
"candy", 10, 1.00 (price per unit is 0.10)
Then a call to findBestValue() would return the last Grocery item (with the category "candy", number of units is 10 and price is 1.00);
Write the findBestValue() method below.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:50
In this lab, you complete a prewritten c++ program for a carpenter who creates personalized house signs. the program is supposed to compute the price of any sign a customer orders, based on the following facts: the charge for all signs is a minimum of $35.00. the first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. if the sign is made of oak, add $20.00. no charge is added for pine. black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering. instructions ensure the file named housesign.cppis open in the code editor. you need to declare variables for the following, and initialize them where specified: a variable for the cost of the sign initialized to 0.00 (charge). a variable for the number of characters initialized to 8 (numchars). a variable for the color of the characters initialized to "gold" (color). a variable for the wood type initialized to "oak" (woodtype). write the rest of the program using assignment statements and ifstatements as appropriate. the output statements are written for you. execute the program by clicking the run button. your output should be: the charge for this sign is $82. this is the code, // housesign.cpp - this program calculates prices for custom made signs. #include #include using namespace std; int main() { // this is the work done in the housekeeping() function // declare and initialize variables here // charge for this sign // color of characters in sign // number of characters in sign // type of wood // this is the work done in the detailloop() function // write assignment and if statements here // this is the work done in the endofjob() function // output charge for this sign cout < < "the charge for this sign is $" < < charge < < endl; return(0); }
Answers: 1
question
Computers and Technology, 22.06.2019 17:40
Consider the simple 3-station assembly line illustrated below, where the 2 machines at station 1 are parallel, i.e., the product only needs to go through one of the 2 machines before proceeding to station 2.what is the throughput time of this process?
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
What are ways to switch windows in excel? check all that apply. on the status bar, click the windows button, and then click the file name. on the task bar, click to display the excel jump list, and then click the file name. on the view tab, in the window group, click switch windows, and then click the file name. on the review tab, in the viewing group, click files, and then click the file name.
Answers: 1
question
Computers and Technology, 24.06.2019 07:50
Write a defining table and then a program that determines if you can sleep in or not. your program should get all its input from your computer’s clock. on all weekdays (monday through friday) that are not holidays, your program should output “get up! ” on all other days (weekends and holidays), your program should output “sleep in.” the three holidays that your program must check for are january 1 (new year’s day), july 4 (u.s. independence day), and december 25 (christmas). you don’t need to include other holidays in your program because most other holidays do not occur on a fixed day each year.
Answers: 1
You know the right answer?
Grocery FRQ (ArrayLists) public class Grocery
{
private String category;
private...
Questions
question
Mathematics, 04.09.2019 03:30
question
Mathematics, 04.09.2019 03:30
question
Mathematics, 04.09.2019 03:30
Questions on the website: 13722360