DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002

    Unhappy creating a class?

    Hi there,
    I am having trouble out here (

    I created a class, and i need to be able to store information of this class, put new information at the end of it, and get information off the beginning of it (while removing it from that class in the process). I also want to know the length of my Class at any time.

    You must be asking yourselves - WHAT THE?#@#$$%

    I will try and copy paste what I am trying to do and I admit that I have no idea what I am doing.....!!!

    //create a class called queue
    //new information can only go at the end of the queue
    //information can only come out of the front of the queue

    public class Queue

    //create constructor method
    public Queue(){

    public static int myMethod (String myString, int myInteger){

    //create three seperate queue objects that
    //each have different contents:
    //store info of queue
    //put new information at end of queue
    //get information from beginning of queue
    //get information on how long is the queue



    Can someone please try and give me a clue how i am about to start this mess???

    Thank you

  2. #2
    Join Date
    Sep 2002
    i dont really get what you're trying to do here..
    can u plz expand? so u want 3 queue objects, are these 3 variables? and what type of information does queue hold? eg a string? int?
    i'll try to help out
    ¿Red Baron?
    [code] /* dont forget code tags! */ [/code]
    Come visit the Café!

  3. #3
    Join Date
    Oct 2002

    Unhappy clarification

    ok here goes....
    I am trying to creat a class that represents something called a queue. A queue is like creating a line (the kind u stand in) - new information can only go at the end, and information can only come out of the front of the queue. Information of the queue needs to be stored, new information can be put at the end of it, and you can get information off the beginning (removing it from the queue in the process). The length of the queue should also be known at any time.
    The main of the Queue class needs to have in it three seperate queue objects that each have different contents.
    Does this clarify my attempt? Or maybe it does not since my attempt was so bad!

  4. #4
    Join Date
    Oct 2002

    did some more research

    maybe I should be using a Vector()?
    something like this?

    //adds element
    public final synchronized void addElement()
    //removes element
    public final synchronized boolean removeElement()

    ??? not sure ???

  5. #5
    Join Date
    Oct 2002
    Ok, well I don't actually cover this until my next Data Structures lecture (I think). But I'll try my best to put pen to paper (or finger to keyboard ).

    import java.util.*;
    public class Queue {
    	private Vector queue;
    	public Queue() {
    		queue = new Vector();
    	public int size() {
    		return queue.size();
    	public void add(Object o) {
    	public Object remove() {
    		String element = (String) queue.firstElement();
    		return element;
    I've briefly test the code by shoving the following in at the end before closing the class:

    	public static void main (String[] args) {
    		Queue bob = new Queue();
    		bob.add("Hello Big ");
    		bob.add("Fat ");
    		System.out.println("Queue is " + bob.size() + " and message is: " + (String) bob.remove() + (String) bob.remove() + (String) bob.remove());
    It seems to work fine. There's extra features you can add but all I've done is what you asked, so if you need anything more you'll have to ask. Let me know how that is for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.