Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: having problem with data structure

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default having problem with data structure

    im having problem to solve this question,can someone teach me the code to solve this problem
    java.JPG

    as this is my progress app class

    my code.JPG

    here is my class
    class 1.JPGclass 2.JPG


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: having problem with data structure

    Please post your code directly using code or highlight tags which are explained here. The graphics are very hard/impossible to read and the text they contain cannot be copied and pasted into our own work areas.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: having problem with data structure

    public class PatientApp
    {
        public static void main(String[]args)
     
        {
            String patName; 
            String patIC; 
            String treatment; 
            String treatmentDate;
            String patStatus;
     
            ArrayList patientAL =new ArrayList();
            ArrayList childAL=new ArrayList();
     
     
            for(int i=0;i<2;i++)
            {
                patName=JOptionPane.showInputDialog("Patient Name : ");
                patientAL.add(patName);
                patIC=JOptionPane.showInputDialog("Patient IC : ");
                patientAL.add(patIC);
                treatment=JOptionPane.showInputDialog("treatment (extraction, restoration,scaling) : ");
                patientAL.add(treatment);
                treatmentDate=JOptionPane.showInputDialog("Date : ");
                patientAL.add(treatmentDate);
                patStatus=JOptionPane.showInputDialog("status (children or adult): ");
                patientAL.add(patStatus);
     
            }
     
            for(int j=0;j<2;j++)
            {            
               JOptionPane.showInputDialog("Enter patient IC no without(-) : ");
     
     
            }
     
        }
    }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: having problem with data structure

    Progress. Now explain specifically what you need help with. Copy/paste the assignment step(s) you're working on and the code you've written for those parts, any compiler or run time errors you're getting, describe any program behaviors you'd like to change, post sample runs if you can, and ask specific questions.

  5. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: having problem with data structure

    this my class
    public class Patient
    {
     
        private String patName; //patient’s name
        private String patIC; //patient’s NRIC/birth cert.
        private String treatment; //type of treatment received:
        private String treatmentDate; //in format dd/mm/yyyy
        private String patStatus; //children or adult
     
        //normal constructor
        public Patient(String name,String IC, String treatmnt,String date, String status)
        {
            patName=name;
            patIC =IC;
            treatment =treatmnt;
            treatmentDate=date;
            patStatus=status;
     
        }
     
     
       //accessor methods
        public String getName()
        { 
            return patName;
        }
     
        public String getIC()
        {
            return patIC;
        }
     
        public String getTreatment()
        {
            return treatment;
        }
     
        public String getTreatmentDate()
        {
            return treatmentDate;
        }
     
        public String getStatus()
        {
            return patStatus;
        }
     
        public void setTreatment(String treatmnt)//mutator method
        {
            treatment=treatmnt;
        } 
     
     
        public String toString()//return string
        {
            String s;
            s="Patient Name : "+patName+"Patient IC : "+patIC+"Treatment : "+treatment+"Date : "+treatmentDate+"Status : "+patStatus;
     
            return s;
     
     
        }
    }

    i having problem to do this
    question.JPG

  6. #6
    Member
    Join Date
    Sep 2013
    Posts
    68
    My Mood
    Confused
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default Re: having problem with data structure

    In your main method you didn't instantiate the patient class so why you build a class that you are not using?

    If you want to search a patient using patient’s NRIC/birth cert then its better if you go for Hash-map instead of arraylist.
    make patient patient’s NRIC/birth cert as a key for hash-map and value as a patient class object.
    HashMap<String, Patient> patientHashMap = new HashMap<>();

    and then populate the hashmap as
    patientHashMap.put(patIC,new Patient(patName, patIC, treatment, treatmentDate, patStatus));

    i suggest you to use hash-map because it's easy with the hash-map to search using key based criteria.

    if(patientHashMap.containsKey(patIC)){
            	   System.out.println(patientHashMap.get(patIC));
               }
    .

Similar Threads

  1. Re: Data Structure
    By jim17 in forum Object Oriented Programming
    Replies: 3
    Last Post: November 16th, 2011, 11:14 PM
  2. Data Structure
    By Faha in forum Object Oriented Programming
    Replies: 9
    Last Post: November 10th, 2011, 01:35 AM
  3. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  4. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  5. data structure assignment .. help me : |
    By Noni in forum Object Oriented Programming
    Replies: 4
    Last Post: March 21st, 2011, 10:33 AM

Tags for this Thread