Go Back   Java Programming Forums > Java Standard Edition Programming Help > File I/O & Other I/O Streams


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-04-2009, 07:34 PM
Junior Member
 

Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
rocafella5007 is on a distinguished road
Default Fill in the queue from the keyboard help

I am having trouble fixing my program so I can enter the data with the keyboard method. Please Help.
How do I fix my program so I can use the keyboard to type in the numbers?

Java Code
// Queue.java
// demonstrates queue
// to run this program: C>java QueueApp
//////////////////////////////////////...
class Queue
{
private int maxSize;
private long[] queArray;
private int front;
private int rear;
private int nItems;
//------------------------------------...
public Queue(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
front = 0;
rear = -1;
nItems = 0;
}
//------------------------------------...
public void insert(long j) // put item at rear of queue
{
if(rear == maxSize-1) // deal with wraparound
rear = -1;
queArray[++rear] = j; // increment rear and insert
nItems++; // one more item
}
//------------------------------------...
public long remove() // take item from front of queue
{
long temp = queArray[front++]; // get value and incr front
if(front == maxSize) // deal with wraparound
front = 0;
nItems--; // one less item
return temp;
}
//------------------------------------...
public long peekFront() // peek at front of queue
{
return queArray[front];
}
//------------------------------------...
public boolean isEmpty() // true if queue is empty
{
return (nItems==0);
}
//------------------------------------...
public boolean isFull() // true if queue is full
{
return (nItems==maxSize);
}
//------------------------------------...
public int size() // number of items in queue
{
return nItems;
}
//------------------------------------...
} // end class Queue
//////////////////////////////////////...
import java.util.Scanner;
class QueueApp
{
public static void main(String[] args)
{
Queue theQueue = new Queue(5); // queue holds 5 items

Scanner scannerObject = new Scanner(System.in);

System.out.println("Enter 10 numbers");

double[] score = new double[7];

theQueue.insert() = scannerObject.nextInt(); 

System.out.println("You entered " + x);

theQueue.insert(10); // insert 4 items
theQueue.insert(20);
theQueue.insert(30);
theQueue.insert(40);

theQueue.remove(); // remove 3 items
theQueue.remove(); // (10, 20, 30)
theQueue.remove();

theQueue.insert(50); // insert 4 more items
theQueue.insert(60); // (wraps around)
theQueue.insert(70);
theQueue.insert(80);

while( !theQueue.isEmpty() ) // remove and display
{ // all items
long n = theQueue.remove(); // (40, 50, 60, 70, 80)
System.out.print(n);
System.out.print(" ");
}
System.out.println("");
} // end main()
} // end class QueueApp



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 29-04-2009, 07:39 PM
Freaky Chris's Avatar
Senile Half-Wit
 

Join Date: Mar 2009
Location: UK
Posts: 621
Thanks: 2
Thanked 64 Times in 60 Posts
Freaky Chris will become famous soon enoughFreaky Chris will become famous soon enoughFreaky Chris will become famous soon enough

I'm feeling Cheerful
Default Re: Fill in the queue from the keyboard help

Java Code
theQueue.insert(scannerObject.nextInt());
Regards,
Chris
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
System Wide Mouse/Keyboard Hook Freaky Chris Java Native Interface 17 17-06-2009 06:06 PM
[SOLVED] Sorting an array which I hope to fill with dates scottyadam Collections and Generics 1 09-03-2009 10:08 PM
[SOLVED] How I can control Keyboard? Mohd Java Theory & Questions 3 05-01-2009 11:10 AM


100 most searched terms
Search Cloud
2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html java 2d arraylist java actionlistener java addactionlistener java double format java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programmers forum java programming forum java programming forums java programming help java project ideas java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextarea font color jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream two dimensional arraylist java writing ipod apps

All times are GMT. The time now is 11:55 PM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.