Question: import java.util.Queue; //A data structure (based on a queue) to represent a grocery //store line. //Grocery lines can only contain people and can be compared

import java.util.Queue;

//A data structure (based on a queue) to represent a grocery //store line. //Grocery lines can only contain people and can be compared //to eachother based on the number of items left to process //in the line. The lines also have id numbers. class GroceryLine extends SimpleQueue implements Comparable { //Creates a grocery store line with a given ID. public GroceryLine(int id) { //O(1) } //Returns the ID of the grocery line. public int getId() { //O(1) } //Sums up all items for all people in the line. //For example,if there are two people in line, one //with 16 items and one with 54 items, //this method will return 70. public int itemsInLine() { //O(n), where n = the number of people in line } //Compare one grocery line to another based on //the number of items in the line and then, if //the two lines are tied, by their id. //If the two lines are tied, it compares them by their id. public int compareTo(GroceryLine otherLine) { //O(n+m), where n = the number of people in the //first line and m = the number of people in the //second line

return 0; } //Processes (removes) one item from the first //person in line. If the person has no more //items they are removed from the line. public void processItem() { //O(1) } //Converts the line to a string. //in following Format: [id]: Person([#]) = [#] shopper(s) with [#] item(s) //For example, if Line 3 has two people in it (one with 16 items and one with 54): //The string would be: 3: Person(16) Person(54) = 2 shopper(s) with 70 item(s) public String toString() { //O(n), where n = the number of people in line return null; } //------------------------------------------------------------- // Main Method For Your Testing -- Edit all you want //------------------------------------------------------------- public static void main(String[] args) { GroceryLine line = new GroceryLine(0); Person mason = new Person(10); Person george = new Person(20); line.offer(mason); line.offer(george); if (line.getId()==0 && line.itemsInLine() == 30){ System.out.println("Yay 1"); } line.processItem(); if (line.itemsInLine() == 29 && line.peek().getNumItems()==9){ System.out.println("Yay 2"); }

GroceryLine line2 = new GroceryLine(1); Person washington = new Person(40); line2.offer(washington); if (line.compareTo(line2)<0){ System.out.println("Yay 3"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!