Programming Notes: Queue

Hi everyone, Today I finished up my programming assignment.This assignment is about Queue.Below I paste the full coding about this assignment and I hope using below question and suggestion solution can help you to understand about Queue.

Here I make my conclusion about Queue based on my understanding. When you want to answer the question try follow this step:-

1)      Create new Queue




2)      Create new Object


3)      Use While Statement

4)      In While Statement,Remove or deQueue the previous Queue

5)      Write any syntax you want like Find Informatio,Find Total,Find Sum,Find Highest and ETC

6)      Next,add back all date into Queue using inQueue into new Queue(store into queue that you create in step 1).

7)      Finally,close the while statement and write output statement if necessary.

Example:-

Queue newMember = new Queue();//Previous Queue

Queue memberOne = new Queue();//Step 1

double sum=0.0; int totalStu=0;

ClubMembers pay;//Step 2

while(!newMember.isEmpty())//Step 3

{   pay = (ClubMembers) newMember.dequeue(); //Step 4

sum += pay.calcFees(); //Step 5-calculate sum of payment

memberOne.enqueue(pay); //Step 6

}//Step 7

System.out.println(“\nThe Total Payment is: “+sum);   //Step 7

Alright,That all from me about Queue.I hope this note and suggestion solution can help you to understand about this topic.Thank You.

QUESTION:

Write a Java program to solve the following problems:

a) Create a Queue object named as qMember.

b) Create two (2) Stack objects named as gStack and pStack

c) Input member objects into qMember. Input is determined by the user. (For Lab
Assignment purpose, minimum input is 5)

d) Display all club members’ information. (Store data in temporary queue for later use)

e) Calculate the total payment received by the club if the monthly fees are based on
the table below: (Store the data in the temporary queue for later use)

Employment Type Fees (RM)
Government 200
Private 250

f) Find the oldest age of club member from the government sector.

g) Take out all member objects from qMember, and store them into two stacks named
gStack and pStack according to their employment type. (gStack for Government,
pStack for Private workers)

SUGGESTION SOLUTION

PREPARED BY FAISALUDEEN

CLUB MEMBERS APPLICATION

import java.util.*;

import javax.swing.*;

/**

*@author( Muhammad Faisaludeen Abdullah)

* @author (your name)

*

* Title (Queue)

* Date(4 Mac 2010)

* Group(CSD4KA)

*/

public class ClubMembersAppl

{

public static void main(String[]args)

{

//Question A

Queue qMember =new Queue();

Scanner inp=new Scanner(System.in);

//Question B

Stack gStack = new Stack();

Stack pStack = new Stack();

ClubMembers cm;

//Question C

System.out.print(“Enter The Number Of Queue:”);

int num=inp.nextInt();

for(int ind=0;ind<num;ind++)

{

// String brnd = JOptionPane.showInputDialog(“Enter the brand of transport : “);

System.out.print(“Enter The Name:”);

String name=inp.next();

System.out.print(“Enter The Age:”);

int age=inp.nextInt();

System.out.print(“Enter The Type:”);

String type=inp.next();

cm= new ClubMembers(name,age,type);

qMember.enqueue(cm);

}

if(qMember.isEmpty())

System.out.println(“\nQueue is Empty”);

else

System.out.println(“\nQueue is Not Empty”);

//Question D

Queue newMember = new Queue();

Object member;

System.out.println(“\nElements in queue: \n”);

while (! qMember.isEmpty())

{

member = qMember.dequeue();

System.out.println(“  ” + member.toString());

newMember.enqueue(member);

}

//Question E

Queue memberOne = new Queue();

double sum=0.0; int totalStu=0;

ClubMembers pay;

while(!newMember.isEmpty())

{   pay = (ClubMembers) newMember.dequeue();

sum += pay.calcFees();

memberOne.enqueue(pay);

}

System.out.println(“\nThe Total Payment is: “+sum);

//Question F

Queue memberTwo = new Queue();

ClubMembers old;

ClubMembers theOld=null;

int theAge=0;

while(!memberOne.isEmpty())

{

old=(ClubMembers)memberOne.dequeue();

if(old.getAge()>theAge)

{

theAge=old.getAge();

theOld=old;

memberTwo.enqueue(old);

}

}

System.out.println(“\nThe Oldest Age Is: “+theAge);

System.out.println(“\nThe OldestInformation: “+theOld);

if(memberOne.isEmpty())

System.out.println(“\nQueue memberOne is Empty”);

else

System.out.println(“\nQueue  memberOne is Not Empty”);

if(memberTwo.isEmpty())

System.out.println(“\nQueue  memberTwo is Empty”);

else

System.out.println(“\nQueue  memberTwo is Not Empty”);

//Question G

ClubMembers theLast;

while(!memberTwo.isEmpty())

{

theLast=(ClubMembers)memberTwo.dequeue();

if(theLast.getName().equalsIgnoreCase(“Government”))

{

gStack.push(theLast);

}

else if(theLast.getName().equalsIgnoreCase(“Private”))

{

pStack.push(theLast);

}

}

}//main

}//end

CLASS CLUB MEMBERS

public class ClubMembers

{

private String name;

private int age;

private String type;

private double fees;

public ClubMembers (String n, int a, String t)

{

name=n;

age=a;

type=t;

}

public String getName(){return name;}

public int getAge() {return age;}

public String getWorkType() {return type;}

public double calcFees()

{

//double fees=0.0;

if(type.equalsIgnoreCase(“Government”))

fees=200;

else if(type.equalsIgnoreCase(“Private”))

fees=250;

return fees;

}

public String toString()

{

return(“The name:”+name + “  The Age:”+age+ “  The Type:”+type);

}

}//end



Speak Your Mind

*