#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0

    Delete specific item from LinkedList or Queue


    The program I have here is working but at the delete section, I need to delete a specific data I inputted. Here's the code.


    Code:
    import javax.swing.*;
    import java.util.*;
    
    class ClinicRuslan
    {
     public static void main(String[]args)
     {
      String name="";
      String IC="";
      String gender="";
      int age=0;
      String priority="";
      int choice=0;
      String option="";
      String output="";
      
      Patient temp;
      Queue normalQueue = new Queue();
      Queue priorityQueue = new Queue();
    
      LinkedList AllQueue = new LinkedList();
      AllQueue.add(normalQueue);
      AllQueue.add(priorityQueue);
      
      while (choice==0)
      {
       option=JOptionPane.showInputDialog(null,"Welcome to Clinic Ruslan.\n\"Clinic Ruslan Registration\"\nChoose Option\n\tAdd\n\tDelete\n\tView\n\tExit");
       if (option.equalsIgnoreCase("Add"))
       {
    	JOptionPane.showMessageDialog(null,"ADDING");
    	name = JOptionPane.showInputDialog(null,"Name");
    	IC = JOptionPane.showInputDialog(null,"IC");
    	gender = JOptionPane.showInputDialog(null,"Gender[Male/Female]");
    	age = Integer.parseInt(JOptionPane.showInputDialog(null,"Age"));
    	priority = JOptionPane.showInputDialog(null,"Priority[normal/critical]");
    	temp = new Patient(name, IC, gender, age, priority);
    	if (priority.equalsIgnoreCase("Critical"))
    	{
    	 priorityQueue.enqueue(temp);
    	}
    	else
    	{
    	 normalQueue.enqueue(temp);
    	}
       }
       else if (option.equalsIgnoreCase("Delete"))
       {
    	if(!priorityQueue.isEmpty())
        {
    	 for(int i=0; i<priorityQueue.size(); i++)
         {
    	  temp = (Patient)priorityQueue.front();
    	  System.out.println(temp.toString());
    	  output+=temp.toString();
    	  priorityQueue.dequeue();
    	 }
    	}
    	if(!normalQueue.isEmpty())
        {
    	 for(int i=0; i<normalQueue.size(); i++)
    	 {
    	  temp = (Patient)normalQueue.front();
    	  System.out.println(temp.toString());
    	  output+=temp.toString();
    	  normalQueue.dequeue();
    	 }
    	}
    	JOptionPane.showInputDialog(null,"\nSelect which appointment will be deleted.(Define the name)\n"+output);
    	output="";
       }
       else if (option.equalsIgnoreCase("View"))
       {
    	if(!priorityQueue.isEmpty())
        {
    	 for(int i=0; i<priorityQueue.size(); i++)
    	 {
    	  temp = (Patient) priorityQueue.front();
    	  System.out.println(temp.toString());
          output+=temp.toString();
    	 }
    	}
    	if(!normalQueue.isEmpty())
        {
    	 for(int i=0; i<normalQueue.size(); i++)
    	 {
    	  temp = (Patient) normalQueue.front();
    	  System.out.println(temp.toString());
    	  output+=temp.toString();
    	 }
    	}
    	JOptionPane.showMessageDialog(null,"VIEWING\n"+output);
    	output="";		
       }
       
       else if (option.equalsIgnoreCase("Exit"))
       break;
       else
       JOptionPane.showMessageDialog(new JFrame(), "You have entered invalid input. Please enter \"Add\", \"Delete\", \"View\", or \"Exit\" ", 
       "Wrong Input",JOptionPane.ERROR_MESSAGE);
       choice=JOptionPane.showConfirmDialog(null,"Do you want to continue?","Continue?", JOptionPane.YES_NO_OPTION);
      }
      System.exit(0);
     }
    }

    At my delete section, it deletes all of the data I inputted previously but need to delete only one of the data. Need help.


    P.S.: Yes, this is my final year project.
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    When you delete, it looks like you aren't doing any kind of comparison. You are deleting everything.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    Well, that is what I'm trying to fix. I followed what my lecturers says but he said that to find on my own when deleting one specific item. Since been doing a lot of research, I can't find it anywhere.

    Is there any way to delete it? Thanks in advance.
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,020
    Rep Power
    1285
    It seems like you want to look for an item to see if it matches.

    But what you are doing is going through every elements and dequeueing.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    6
    Rep Power
    0
    Is it possible to change them? Or I should make a new one?

IMN logo majestic logo threadwatch logo seochat tools logo