Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your assignment is to design and implement a Java class that defines a linked list and to use that class to create a simple queue

Your assignment is to design and implement a Java class that defines a linked list and to use that class to create a simple queue in a Java program. Remember the Source/input Code feature of NetBeans referenced in the NetBeans Project Presentation. When you are adding code to a Java program it allows you to quickly and correctly generate required code segments with little effort. In your program you are to read an input file with an unknown number of name and age pairs. The input file will be provided for you. Your program should work for an input file of any size. Your program should work if the sequence of the input is changed from run to run. When executing your program In NetBeans, the working directory is the directory of your project. To facilitate us evaluating your work, add the file to the project directory you create in NetBeans. I have not been able to find a way to do this from within NetBeans, but you can do easily with the Windows File Explorer or similar system utility. The name of the file that will be provided for you will be Lab1InputFile.txt. Please add it to your project folder with exactly that name. All internal references to the file in your program should be the file names only. Do not include the full path. Your program should have the following functionality:

1. Define a Java class, MyListQueue. You should design it to be a linked list used as a queue. It should have two attributes: a reference variable to point to the front of your list, and a second reference variable to point to the back of your list. You should include the following functionality with methods in your class: enqueue an item, dequeue an item, count the number of items in the list, and a toString function to print a formatted list of the contents of the queue.

2. Define a second Java class, MyLink. You should design it so that its objects can be the items in your MyListQueue list. It should have three attributes: name (a String), age (an Integer), and a reference variable (type MyLink) to point to the next items in the linked list.

3. Read a name/age pair from the file, create a MyLink object with the pair, and enqueue each object into the queue. Remember a new item is always enqueued at the back of the queue.

4. When all the input items have been enqueued, print the number of items in the queue by using the count method of the MyListQueue object. Then print the individual items in the queue using the toString method.

5. Dequeue two items from the queue and print the count and the remaining items. Remember an item is always dequeued from the front of the queue. 6. Your queue should handle a special situation. When the queue is empty, both reference variables should be equal to null. You will need to address instructions for enqueueing or dequeueing when the queue is empty. ***You must implement your queue with the classes described above. You may not use any list or queue class in the Java API.***

The .txt file reads as:

Diane

23

Bill

22

Jackie

20

Tom

25

Jane

22

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

More Books

Students also viewed these Databases questions

Question

Why is global business important?

Answered: 1 week ago

Question

Conduct an effective performance feedback session. page 360

Answered: 1 week ago