Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please create in only one class : The objective of this assignment is to allow y

ID: 3848480 • Letter: P

Question

Please create in only one class :

The objective of this assignment is to allow you to work with the Stack data structure and explore the idea of first-in, last-out (FILO) servicing.

Imagine that you're visiting a local all-you-can-eat breakfast bar; among the many items on the bar is a pan of sausages. Your task is to simulate the sausage pan. Note that when new sausages are added to the pan, they're always added to the top (the worker just dumps new sausages on top of the old sausages); also note that whenever someone takes a sausage to eat, they pick the top-most sausage. Thus we've got a stack (first-in, last-out) and the bottom-most sausage is always the oldest. For sake of simplicity, imagine that the pan only allows you to select a "top" sausage (i.e. you can't pick among many).

Your task is to utilize a stack collection (the Stack or Vectorclass is appropriate). Your program should allow the user to add a sausage, remove a sausage, and print the status of the stack. The stack should store the time in which the sausage was added; and when a sausage is removed, the program should display how long the sausage "lived" in the pan (i.e. the difference from now to when it was added to the pan).

Important items to consider:

Don't allow the user to remove (pop) a sausage if the pan is empty

Displaying the status of the stack should show how many sausages are in the stack and the "age" of the topmost sausage

Use the Stack or Vector class to make your job a LOT easier (otherwise, you must implement the stack class yourself).

To get the time in Java, import java.util.* and then make use of the Date class


Again, please in only one class

Explanation / Answer

Hi,

I have heavily commented the code. Feel free to comment if you have any queries. Also give a thumbs up if this answer helped you.

//Code starts here

//Code ends here

Hope it helps!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote