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
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.
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
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.
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(-) : "); } } }
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.
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
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)); }