Вы находитесь на странице: 1из 4

package assignment_02;

class Queue implements BankQueue {

private int[] queue;

private int front;

private int rear;

private int size;

private int total;

public Queue(int size)

if(size < 2)

throw new IllegalStateException("Size must be more than [1]");

this.size = size;

queue = new int[this.size];

rear = front = 0;

total = 0;

public int GetTotal()

return total;

public boolean isEmpty()

return (total == 0);

public boolean isFull()

return (size == total);

}
public int Front()

if(isEmpty())

throw new IllegalStateException("Queue is Empty");

return queue[front];

public int Back()

return (queue[rear - 1]);

public int Pop()

if(isEmpty())

throw new IllegalStateException("Queue is Empty");

int frontItem = queue[front];

total--;

queue[front] = 0;

front = (front + 1) % size;

return frontItem;

public void Push(int var)

if(isFull())

throw new IllegalStateException("Queue is Full");

total++;

queue[rear] = var;

rear = (rear + 1) % size;

public int Size()


{

if(rear >= front)

return (rear - front);

else

return (rear - front + queue.length);

public class Assignment_02 {

public static void main(String[] args) {

int firstCustomer = 1;

Queue queue = new Queue(50);

for(int i = 0; i < 60; i++)

if(i != 0 && i % 4 == 0 && i % 7 == 0)

queue.Push(firstCustomer);

System.out.println("[*]Customer number ["+(firstCustomer++)+"] just arrived at ["+i+"


minutes]");

System.out.println("[*]Customer number ["+(queue.Pop())+"] left at ["+i+" minutes]");

continue;

if(i % 4 == 0)

queue.Push(firstCustomer);

System.out.println("[*]Customer number ["+(firstCustomer++)+"] just arrived at ["+i+"


minutes]");

}
else if(i % 7 == 0)

System.out.println("[*]Customer number ["+(queue.Pop())+"] left at ["+i+" minutes]");

System.out.println("***");

System.out.println("[*]currently sereving customer number: ["+queue.Front()+"]");

System.out.println("[*]Total customers in line: ["+queue.GetTotal()+"]");

Вам также может понравиться