The PoD and class have been completed for you. You will be responsible for the c
ID: 3915900 • Letter: T
Question
The PoD and class have been completed for you.
You will be responsible for the completion of the Fridge class. The toString() method, constructor and attributes have been given to you.
import java.util.*;
public class PoD
{
public static void main( String [] args )
{
Scanner in = new Scanner( System.in );
Fridge fridge = new Fridge();
String[] input = new String[6];
String[] forTopShelf, forMiddleShelf, forBottomShelf;
String takeFromTop, takeFromMiddle, takeFromBottom;
for (int i=0; i<6; i++)
{
input[i] = in.nextLine();
}
forTopShelf = input[0].split(",");
forMiddleShelf = input[1].split(",");
forBottomShelf = input[2].split(",");
takeFromTop = input[3];
takeFromMiddle = input[4];
takeFromBottom = input[5];
fridge.addGroceries(forTopShelf, fridge.topShelf);
fridge.addGroceries(forMiddleShelf, fridge.middleShelf);
fridge.addGroceries(forBottomShelf, fridge.bottomShelf);
System.out.println(fridge);
fridge.getIngredient(takeFromTop,fridge.topShelf);
fridge.getIngredient(takeFromMiddle,fridge.middleShelf);
fridge.getIngredient(takeFromBottom,fridge.bottomShelf);
System.out.println(fridge);
in.close();
System.out.print("END OF OUTPUT");
}
}
----------------------------------------------------------------------
import java.util.*;
public class Fridge
{
//attributes
protected Stack<String> topShelf = new Stack<String>();
protected Stack<String> middleShelf = new Stack<String>();
protected Stack<String> bottomShelf = new Stack<String>();
//constructor
public Fridge(){}
//PLEASE START WORK HERE
//===============================================
/**
* @method addGroceries(String[] groceries, Stack<String> shelf)
*
* @param groceries String[]) : groceries to add to shelf
* @param shelf (Stack<String>) : shelf to add the groceries to
* @returns void
*
* Add provided groceries to front of the specified shelf
*/
/**
* @method getIngredient(String ingredient)
*
* @param ingredient (String) : ingredient to obtain
* @param shelf (Stack<String>) : shelf that the ingredient is (definitely) on.
* @returns void
*
* You need a new ingredient, but it is (possibly) not at the front of the shelf.
* Take out whatever ingredients are necessary to remove what you need and then
* return the removed items back in the reverse order that you took them out.
*/
//===============================================
//PLEASE END WORK HERE
public String toString()
{
String fridgeContents = "--- FRIDGE CONTENTS --- "
+ "Top Shelf:" + topShelf + " "
+ "Middle Shelf:" + middleShelf + " "
+ "Bottom Shelf:" + bottomShelf + " ";
return fridgeContents;
}
}
Fridge class Fridge #groceryLine LinkedList«Perso #topShelf. Stack #middleShelf. Stack #bottomshelf Stack +Fridge) Constructor +addGroceries(String.Stack): Add provided groceries to front of the specified shelf +getingredient(String Stack):You need a new ingredient, but it is (possibly) not at the front of the shelf. Take out whatever ingredients are necessary to remove what you need and then return the removed items back in the reverse order that you took them out. +toString) outputs String describing contents of the fridge's shelvesExplanation / Answer
import java.util.*; public class Fridge { //attributes protected Stack topShelf = new Stack(); protected Stack middleShelf = new Stack(); protected Stack bottomShelf = new Stack(); //constructor public Fridge() { } //PLEASE START WORK HERE //=============================================== /** * @param groceries String[]) : groceries to add to shelf * @param shelf (Stack) : shelf to add the groceries to * @method addGroceries(String[] groceries, Stack shelf) * @returns void ** Add provided groceries to front of the specified shelf */ public void addGroceries(String[] groceries, Stack shelf) { for (int i = 0; i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.