Write program for queue of cards, JAVA Programming

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.

Posted Date: 2/16/2013 6:30:05 AM | Location : United States







Related Discussions:- Write program for queue of cards, Assignment Help, Ask Question on Write program for queue of cards, Get Answer, Expert's Help, Write program for queue of cards Discussions

Write discussion on Write program for queue of cards
Your posts are moderated
Related Questions
Explain the library java.lang.Math ? The Java class library is huge. We will not cover it all presently. In fact, the remaining eight classes will focus mostly on the class lib

Writing a report

In Java not all classes must be described separate from each other. You may put the definition of one class under the definition of another class. The class inside class is called

hi i want to get my assingment done

WebSphere - Weblogic and Apache: Building/Installation  and maintenance of Solaris and Linux machines. Exposure to Sun Hardware : Sunfire v880,v890.V440,X4600

When is AlreadyBoundException thrown and by which method? Ans) AlreadyBoundException is thrown by bind(String name) method when a remote object is already registered with the re

list The Java Class Library? Java holds an extensive library of pre-written classes you can use in your programs. These classes are separated into groups known as packages. Th

My name is Myers, the project director of an online business that is scheduled to commence this summer in Nigeria. We are in the process of recruiting members to the project team a

What are the different messaging paradigms JMS supports? Ans) Publish and Subscribe i.e. pub/suc and Point to Point i.e. p2p.

any example of games that is created by java ?