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

CSC248 - FUNDAMENTALS OF DATA STRUCTURES 

QUEUE: LAB 1 

 
NAME  :  PUTERI NURAININ SOFIYA BINTI MOHD YUSWARDI 

STUDENT NO.  :  2018408852 

GROUP  :  RCS1104D 
 
 
A. Display the number of records stored in the queue named washQ. 

System.out.println("--QUESTION a--)"); 
carWash c1; 
   
while(!washQ.isEmpty()) // step 1: check if NOT empty 

c1= (carWash)washQ.dequeue(); //step 2: dequeue and cast 
System.out.println(c1);//step 3: whatever 
tempQ.enqueue(c1); //step 4: enQ to tempQ 

//step 5: restore 
while(!tempQ.isEmpty()) 
washQ.enqueue(tempQ.dequeue()); 
 
 
 
 
 
 

B. Calculate the number of cars with "Super Shine" wash. 

System.out.println("--QUESTION b--)"); 
carWash c2; 
int count=0; 
   
while(!washQ.isEmpty())// check if NOT empty 

c2=(carWash)washQ.dequeue(); //dequeue and cast 
if(c2.getWashSelection().contains("Super Shine"))//whatever 

count++; 
}   
tempQ.enqueue(c2); //enQ to tempQ 

while(!tempQ.isEmpty()) 
CSC248 - FUNDAMENTALS OF DATA STRUCTURES 
QUEUE: LAB 1 

washQ.enqueue(tempQ.dequeue()); 
System.out.println("Number of cars with Super Shine wash: " +count); 
   
 
 
 
 
 
 
 

C. Calculate the total payment collected. 

 
System.out.println("--QUESTION c--)"); 
double total1=0; 
carWash c3; 
   
while(!washQ.isEmpty())//check if NOT empty 

c3=(carWash)washQ.dequeue();//dequeue and cast 
total1= total1 +c3.getAmountCharge();//whatever 
tempQ.enqueue(c3); 

while(!tempQ.isEmpty()) 
washQ.enqueue(tempQ.dequeue()); 
 
System.out.println("Total payment:RM " + total1);  
 
 
 
 

D. Find records of those who chose for "Full Service" from washQ and moved 
them into another queue named FSQueue. 

 
System.out.println("--QUESTION d--)"); 
Queue FSQueue= new Queue(); 
carWash c4; 
  
while(!washQ.isEmpty()) 

c4=(carWash)washQ.dequeue(); 
CSC248 - FUNDAMENTALS OF DATA STRUCTURES 
QUEUE: LAB 1 

if(c4.getWashSelection().equalsIgnoreCase("FullService")) 
   
FSQueue.enqueue(c4); 
   
tempQ.enqueue(c4); 

while(!tempQ.isEmpty()) 
washQ.enqueue(tempQ.dequeue()); 
 
 
 
 
 

E. Display the number of cars, MPVs and lorries in FSQueue. 

 
System.out.println("--QUESTION e--)"); 
carWash c5; 
int count2=0; 
int count3=0; 
int count4=0; 
   
while(!FSQueue.isEmpty()) 

c5=(carWash)FSQueue.dequeue(); 
if (!c5.getCarType().contains("Cars")) 
count2++; 
if(!c5.getCarType().contains("MPV")) 
count3++; 
if(!c5.getCarType().contains("Lorry")) 
count4++; 
   
tempQ.enqueue(c5); 

while(!tempQ.isEmpty()) 
washQ.enqueue(tempQ.dequeue()); 
System.out.println("Number of cars: "+ count2); 
System.out.println("Number of MPV: "+ count3); 
System.out.println("Number of Lorry: "+ count4); 
   
 
 
 
 
CSC248 - FUNDAMENTALS OF DATA STRUCTURES 
QUEUE: LAB 1 

F. Display the latest contents of washQ. 

 
System.out.println("--QUESTION f)--"); 
 
System.out.println(" Latest content : "); 
carWash c6; 
   
while(!washQ.isEmpty()) 

c6=(carWash)washQ.dequeue(); 
System.out.println(" "+c6); 
tempQ.enqueue(c6); 

 
 
 
 
 
 
 

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