Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 14th, 2003, 10:12 AM
suzanne15 suzanne15 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 suzanne15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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 10:21 AM.

Reply With Quote
  #2  
Old March 14th, 2003, 12:24 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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?

Reply With Quote
  #3  
Old March 14th, 2003, 12:30 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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));			
		}
	}
}

Reply With Quote
  #4  
Old March 14th, 2003, 01:23 PM
suzanne15 suzanne15 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 suzanne15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #5  
Old March 14th, 2003, 02:14 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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 02:17 PM.

Reply With Quote
  #6  
Old March 14th, 2003, 02:22 PM
suzanne15 suzanne15 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 suzanne15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #7  
Old March 15th, 2003, 09:20 AM
suzanne15 suzanne15 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 6 suzanne15 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #8  
Old March 15th, 2003, 05:49 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > help with adding to arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway