【发布时间】:2020-11-18 20:35:45
【问题描述】:
我必须创建一个数组来保存用户输入,该输入是 3 个字母代码后跟一个票号。例如)Ama-34。我该怎么做呢? 我知道 long 是不正确的,我只是在另一个项目中对其进行建模。 我还必须允许我遇到困难的用户输入和操作。 这就是我目前所拥有的......
class QueueOrder{
//Global Variables
static Scanner orderScan = new Scanner(System.in);
//Variables
public int MaxSize;
//How to make an array hold both names and numbers??
public long[] BodaciousArray;
public int Front; //Track the front pointer
public int Rear; //track the last pointer
public int NumberOfOrders; //track the number of orders in the system
//Constructor
public QueueOrder(int size){
MaxSize = size;
BodaciousArray = new long[MaxSize];
Front = 0;
Rear = -1;
NumberOfOrders = 0;
}
//Enqueue - add to the rear of the queue
//Allow the server to add one to the array
public void Enqueue(){
long j = 0;
//Add a wrap around
if(Rear == MaxSize - 1){
Rear = -1;
}
//Increment the rear and insert a new item
BodaciousArray[++Rear] = j;
NumberOfOrders++;
}
//Dequeue - remove one from the array
//Allow the server to remove what is next in line
public long Dequeue(){
//Get the first value and incrament the front
long temp = BodaciousArray[Front++];
//Add a wrap around
if(Front == MaxSize){
Front = 0;
}
//Remove one item
NumberOfOrders--;
return temp;
}
//Peek at the front of the queue
//Allow the server to see what order is next
public long peekFront(){
return BodaciousArray[Front];
}
//Check to is the queue is empty
public boolean isEmpty(){
return(NumberOfOrders == 0);
}
//Check to see if the queue is full
public boolean isFull(){
return(NumberOfOrders == MaxSize);
}
//Check how many items are in the queue
public int size(){
return NumberOfOrders;
}
public void DisplayQueueOrder(){
int i;
if(Front == Rear){
System.out.println("There are no orders to fill");
}else{
for(i = Front; i < Rear; i++){
System.out.print("The current orders are: "
+ BodaciousArray[i] + ", ");
}
}
}
【问题讨论】:
标签: java arrays queue user-input