Results 1 to 3 of 3
  1. #1
    jatin89 is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    Default delete from Queue not working

    leaveQ method does not work.

    To see the other files related to these code click here:(Its a dropbox location)

    https://www.dropbox.com/sh/22onq0oub...K_aA4y1kqWdRka

    Java Code:
    public class CustomerQ {
    	
    	private int MaxLength;
    	private int totalCustomers;	//assuming #of customers served
    	int Qlength;
    	Customer cus;
    	LinkedList4Q cus4Q;
    	
    	public CustomerQ()
    	{
    		this.Qlength=0;
    		cus=new Customer();
    		cus4Q=new LinkedList4Q();
    	}
    	
    	/**
    	 * New Customer join the queue at the end of it
    	 * @param toJoin	Customer to be joined
    	 * @param joinTime	Time when Customer joins
    	 */
    	public void joinQ(Customer toJoin, int joinTime)
    	{
    		this.cus4Q.insertAtEnd(toJoin);
    		this.cus.setTimeJoinedQ(joinTime);
    		this.Qlength++;
    	}
    	
    	/**
    	 * Customer leaving from front of the queue
    	 * @param timeToWindow	time when customer reach the window
    	 * @return	customer from the front of the queue
    	 */
    	public Customer leaveQ(int timeToWindow)
    	{
    		Customer tmp;
    		tmp=this.cus4Q.getInfo();
    		
    		cus4Q=this.cus4Q.delete(cus4Q.getInfo());
    		
    		this.totalCustomers++;
    		
    		this.cus.setTimeToWindow(timeToWindow);
    		return tmp;
    		
    		 //return null;
    	}
    	
    	
    	/*
    	 * To get the length of current queue
    	 */
    	public int queueLength()
    	{
    		int count=0;
    		Llist tmp = new Llist();
    		tmp=this.cus4Q;
    		if(tmp.isEmpty())
    		{
    			count=0;
    		}
    		else
    		{
    			while(tmp.getNext()!=null){
    				
    				tmp=tmp.getNext();
    				count++;
    			}
    		}
    		
    		return count;
    	}
    	
    	/* Setter for maxLength BCZ it is private*/
    	public void setMaxLength()
    	{
    		this.MaxLength=this.queueLength();
    	}
    	
    	/* Getter for maxLength BCZ it is private */
    	public int getMaxLengh()
    	{
    		return this.MaxLength;
    	}
    
    	/**
    	 * No idea what it supposed to be so
    	 * @return	it returns totalCustomers which served
    	 */
    	public int getTotalCustomer()
    	{
    		return this.totalCustomers;
    	}
    	
    	public static void main(String[] args) {
    		
    		CustomerQ cQ = new CustomerQ();
    		Customer c= new Customer();
    		cQ.joinQ(cQ.cus, 21);
    		
    		System.out.println(cQ.cus.getTimeJoinedQueue());
    		System.out.println(cQ.queueLength());
    		//cQ.leaveQ(27);
    		//System.out.println(cQ.cus.timeInQ());
    		cQ.joinQ(cQ.cus,25);
    		System.out.println(cQ.cus.getTimeJoinedQueue());
    		System.out.println(cQ.queueLength());
    		//cQ.leaveQ(30);
    		//System.out.println(cQ.cus.timeInQ());
    		System.out.println(cQ.queueLength());
    		//cQ.leaveQ(30);
    		System.out.println(cQ.cus4Q.isEmpty());
    	}
    
    
    }

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,873
    Rep Power
    25

    Default Re: delete from Queue not working

    does not work.
    Please explain.
    Post some output that shows the problem.
    Add some comments to the output explaining what the problem is and show what the output should be.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: delete from Queue not working

    Or, put another way, "does not work" tells us very little.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 9
    Last Post: 04-03-2014, 08:35 PM
  2. Replies: 0
    Last Post: 05-27-2011, 09:46 AM
  3. Queue
    By DCY in forum New To Java
    Replies: 6
    Last Post: 05-04-2010, 09:07 PM
  4. Replies: 2
    Last Post: 04-20-2009, 09:00 AM
  5. Using a queue
    By Krmeus in forum New To Java
    Replies: 0
    Last Post: 12-10-2007, 04:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •