Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

A Queue of Cards

You are going to parallel the development done in the lesson on inheritance where we constructed some base classes, StackNode and Stack, and derived  FloatNode and FloatStack from them.  You can work best by referring to those modules all through the development of your program.  These are the differences between what we did in the lesson and what you will do for your assignment.

  1. Instead of a Stack data structure, you will create a Queue data structure.  A Stack is last-in-first-out (LIFO).  A Queue is first-in-first-out (FIFO).
  2. Instead of deriving a FloatNode from the basic Node class, you will derive a CardNode from NodeCardNode will use the Card class of Week 1.

Here are the details:

Base Class Node

You can use the same class for a base class that was used in the modules.  However, I want you to give this class a different name.  Call it Node (not QueueNode or StackNode, just Node).

Base Class Queue

Next, do almost the same thing as we did with the Stack class, except make sure that this class works like a Queue, not a Stack.  That means

  • We add items to the Queue using Add() not Push()Push() does not appear in our Queue class.
  • We retrieve items from the Queue using Remove() not Pop()Pop() does not appear in our Queue class.
  • Remove() removes and returns the oldest item in the Queue.  This is different from Pop() which removed and returned the youngest item in the Queue.
  • Provide a ShowQueue() method that displays all the items in the Queue from oldest to youngest.
  • Instead of one Node pointer member, top, you'll need two Node pointer members, and neither should be called top (since top is not meaningful in a Queue).  Examples are head/tail, front/back, oldest/youngest, etc.  Select two names and use them accordingly.

Once you have written these two classes, write a simple test main() just like I did in the modules - show a run that displays some (generic node)s.  Test the ShowQueue() method and also build a simple loop in your main() to remove and display nodes as they are removed.   Compare the output of these two techniques -- they should be identical.  You will not hand this in.  It is just for your use in developing the full program.

Add() and Remove() will be slightly more complicated than Push() and Pop() because you have two pointers, front and back (or head and tail, or whatever you call them) to manage.  This may take some time and debugging.  Test it carefully.  Even after you get it to work, you may find that it still needs debugging later, since your "(generic node)" screen results won't tell you if things are coming off in the correct order.  You won't know that until you have real data in your Nodes.  That's the next part.

Java, Programming

  • Category:- Java
  • Reference No.:- M9522418

Have any Question?


Related Questions in Java

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As