#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0

    Unhappy help with adding to queues


    hi
    i want to get input from a user (user name and a filename) through the ms-dos window(see the code below), and then i want add these strings to an queue and then print out the queue. I am having problems remembering how to do this if any of you could help me i'd be greatful
    thanx

    Heres the code i have so far:

    import java.io.*;
    public class queuedriver1
    {
    public static void main(String[]args)throws IOException
    {

    BufferedReader keyboard = new BufferedReader( new InputStreamReader( System.in ) );
    String inString;
    inString = keyboard.readLine();
    }
    }
    Last edited by suzanne15; March 14th, 2003 at 11:21 AM.
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I am not sure what your queston is. Are you saying that you want to keep reading line after line of user input until the user says they are done all the while storing the strings they have been inputting, then echo them to the screen?
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Somthing like this may be what you want?
    Code:
    import java.io.*;
    import java.util.ArrayList;
    public class queuedriver1 {
    	public static void main(String[] args) throws IOException {
    
    		BufferedReader keyboard =
    			new BufferedReader(new InputStreamReader(System.in));
    		ArrayList list = new ArrayList();
    		String inString = "";
    		while(!inString.equals("done")) {
    			inString = keyboard.readLine();
    			list.add(inString);
    		}
    		for (int i = 0; i < list.size(); i++) {
    			System.out.println((String)list.get(i));			
    		}
    	}
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    yeh thats a good start thanx very much for your help but would it work the same adding to a queue instead and would it be just as easy to alter the code

    suzanne
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I am not sure what you mean by "queue". The only queue class I know of in Java is javax.jms.Queue. Is this to what you are referring?

    Or are you just talking about a collection that is First In First Out (FIFO)?
    Last edited by Nemi; March 14th, 2003 at 03:17 PM.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    i dont really know what u mean but its an abstract data type i need to insert the words i enter so that they get added to a queue im sorry if u dont understand im really grateful for your help
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    Sorry i am being a bit vague but im not 100% sure what i am doing myself. I have been given the following question to do, and yes the queue is in terms of a FIFO
    thanx for your help
    suzanne

    Question 4
    Minimal solution
    add items to queue
    Request information from user (name, file)
    print [and remove] item from queue
    Simulate printing first item on queue
    list contents of queue
    Alphabetically sorted by user
    remove a specified item from the queue
    Only owner of job can remove it
    Must provide a list of queue items, alphabetically ordered by
    user (and within that by sequence of addition to the queue).
    Must use a bst for this
  14. #8
  15. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You can use one of several java collections to implement a queue. Here is one that someone did using a linked list
    http://javaalmanac.com/egs/java.util/coll_Queue.html

    You could feasibly do the same using an ArrayList or Vector or something
    Code:
        ArrayList queue = new ArrayList();
        
        // Add to end of queue
        queue.add(object);
        
        // Get head of queue
        Object o = queue.remove(0);
    It sounds like they are expecting a lot out of you without you knowing a lot about Java. Hope what I have given helps.

IMN logo majestic logo threadwatch logo seochat tools logo