Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that uses the Stack, Queue, and Date classes to create a Queue of Stacks of Dates. Your program should have only one

Write a program that uses the Stack, Queue, and Date classes to create a Queue of Stacks of Dates.
Your program should have only one Queue. The Queue will contain inside 4 Stacks.
Each Stack will contain the following objects:
Stack 1(Dates): 12/07/1941,10/12/1492,10/14/1066,05/05/1861,07/04/1776
Stack 2(String): "Attack on Pearl Harbour", "Discovery of America", "Battle of Hastings", "Battle of Puebla", "Declaration of Independence"
Stack 3(Integer): 1,2,3,4,5
Stack 4(Double): Math.PI, Math.E, Math.sqrt(2), Math.sin(Math.PI/4), Math.random()
Add a 6th element to each Stack containing your own name, birthday, SWC ID, and a fictitious GPA.
Your program should push the given values into the 4 Stacks.
Finally, the Stacks must be enqueued in a Queue containing the four Stacks.
The following fragment can be used in main() to start your program:
public static void main(String[] args)
{
Stack[] st = new Stack[4] ;
Queue queue = new Queue();
String[] data1={"Attack on Pearl Harbour", "Discovery of America", "Battle of Hastings", "Battle of Puebla", "Declaration of Independence", "Raul Vargas"};
Date[] data2={new Date("12/07/1941"), new Date("10/12/1492"), new Date("10/14/1066"), new Date("05/05/1861"), new Date("07/04/1776"), new Date("03/28/1969")};
Integer[] data3={1,2,3,4,5,4774};
Double[] data4={Math.PI, Math.E, Math.sqrt(2), Math.sin(Math.PI/4), Math.random(),3.68};
// YOUR CODE GOES HERE:
// Form the Stacks using the proper Stack constructor, add your own data
// and push the values into the Stacks.
// Then enqueue each of the four Stacks and print them as a Queue
System.out.println(queue);
}
A sample run is shown below. Note how my information is shown in Stacks that are inside the Queue:
Raul Vargas Declaration of Independence Battle of Puebla Battle of Hastings Discovery of America Attack on Pearl Harbour
3/28/19697/4/17765/5/186110/14/106610/12/149212/7/1941
477454321
3.680.464572101448295970.70710678118654751.41421356237309512.7182818284590453.141592653589793

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions