//This is the package file
package radz1990;
import java.io.*;
import java.util.*;
import java.lang.*;
public class radz1991a1
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
Scanner obj=new Scanner(System.in);
public String name=new String("0");
public String patientid=new String("0");
public String prescription=new String("0");
public String Illness=new String("0");
public String Address=new String("0");
public String ladate=new String("0");
public int age=0;
public char sex=0;
radz1991a1 ob0,object;
String p0;
public radz1991a1()
{
}
public radz1991a1(String name,String patientid,String prescription,String Illness,String Address,String ladate,int age,char sex)
{
System.out.println("Welcome to the Radhika chawla Hospital:-the best in medical services that you can get");
this.name=name;
this.patientid=patientid;
this.prescription=prescription;
this.Illness=Illness;
this.Address=Address;
this.ladate=ladate;
this.age=age;
this.sex=sex;
} 
public radz1991a1(radz1991a1 object)
{
this.object=object;
}
public radz1991a1 addpatient(radz1991a1 object) throws IOException
{
ob0=object;
System.out.println("Enter the following patient details:-");
System.out.println("Name:-");
ob0.name=obj.nextLine();
System.out.println("Patient ID:-");
ob0.patientid=obj.nextLine();
System.out.println("Prescription:-");
ob0.prescription=obj.nextLine();
System.out.println("Illness:-");
ob0.Illness=obj.nextLine();
System.out.println("Address:-");
ob0.Address=obj.nextLine();
System.out.println("Last Appointment Date:-");
ob0.ladate=obj.nextLine();
System.out.println("Age:-");
ob0.age=Integer.parseInt(ob.readLine());
System.out.println("Sex:-");
ob0.sex=(char)new InputStreamReader(System.in).read ();
return ob0;
}
public void updatepatient(radz1991a1 object) throws IOException
{
ob0=object;
System.out.println("Enter the following patient details:0-");
System.out.println("Name:-");
ob0.name=obj.nextLine();
System.out.println("Patient ID:-");
ob0.patientid=obj.nextLine();
System.out.println("Prescription:-");
ob0.prescription=obj.nextLine();
System.out.println("Illness:-");
ob0.Illness=obj.nextLine();
System.out.println("Address:-");
ob0.Address=obj.nextLine();
System.out.println("Last Appointment Date:-");
ob0.ladate=obj.nextLine();
System.out.println("Age:-");
ob0.age=Integer.parseInt(ob.readLine());
System.out.println("Sex:-");
ob0.sex=(char)new InputStreamReader(System.in).read ();
}
public void searchpatient(radz1991a1 object) throws IOException
{
ob0=object;
System.out.println("The patient with the patientid "+patientid+"exists and has the following details:-");
System.out.println("Name:-"+ob0.name);
System.out.println("Patient ID:-"+ob0.patientid);
System.out.println("Prescription:-"+ob0.prescription);
System.out.println("Illness:-"+ob0.Illness);
System.out.println("Address:-"+ob0.Address);
System.out.println("Last Appointment Date:-"+ob0.ladate);
System.out.println("Age:-"+ob0.age);
System.out.println("Sex:-"+ob0.sex);
}
public void displaypatient(radz1991a1 object) throws IOException
{
ob0=object;
System.out.println("The patient with the patientid "+patientid+"has the following details:-");
System.out.println("Name:-"+ob0.name);
System.out.println("Patient ID:-"+ob0.patientid);
System.out.println("Prescription:-"+ob0.prescription);
System.out.println("Illness:-"+ob0.Illness);
System.out.println("Address:-"+ob0.Address);
System.out.println("Last Appointment Date:-"+ob0.ladate);
System.out.println("Age:-"+ob0.age);
System.out.println("Sex:-"+ob0.sex);
}
}



//This is the main file with the object array in it
import java.io.*;
import java.lang.*;
import java.util.*;
import radz1990.radz1991a1;
class radz1990a1
{
public static void main(String[] args)
{
try
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
Scanner obj=new Scanner(System.in);
String name=new String("0");
String patientid=new String("0");
String prescription=new String("0");
String Illness=new String("0");
String Address=new String("0");
String ladate=new String("0");
int age=0,i=0,n=0,d=0;
char sex=0;
int choice;
char ch='y' ;
radz1991a1 object[]=new radz1991a1[8];
radz1991a1 temp=new radz1991a1(name,patientid,prescription,Illness,Address,ladate,age,sex);
radz1991a1 temp2=new radz1991a1();
radz1991a1 temp3=new radz1991a1();
String pid=new String();
do
{
do
{
System.out.println("Menu:-\n1.Press 1 to create a patient id and a patient profile\n2.Press 2 to upadte the patient id\n3.Press 3 to search a patient in the syatem\n4.Press 4 to diaplay a patient's account\n0.Press 0 to exit\nEnter your choice:-");
choice=Integer.parseInt(ob.readLine());
}while(choice <0||choice>6);
switch(choice)
{
case 1:temp2=temp3.addpatient(temp);
object[i]=temp2;
++i;
break;
case 2:System.out.println("Enter the patient id of the patient whose details you want to update");
pid=obj.nextLine();
for(n=0;n<i;n++)
{
System.out.println("The value of n="+n);
if(object[n].patientid.equals(pid))
{
d=1;
System.out.println("d="+d);
break;
}
}
if(d==0)
System.out.println("Please enter the valid patient id");
else
{
object[n].updatepatient(object[n]);
}
d=0;
break;
case 3:System.out.println("Enter teh patientid of the patient you want to search");
pid=obj.nextLine();
for(n=0;n<i;n++)
{
System.out.println("The value of n="+n);
if(object[n].patientid.equals(pid))
{
d=1;
System.out.println("d="+d);
break;
}
}
if(d==0)
System.out.println("The patient with the pateient-id"+pid+"does not exist in the system");
else
{
object[n].searchpatient(object[n]);
}
d=0;
break;
case 4:
System.out.println("Enter teh patientid of the patient you want to search");
pid=obj.nextLine();
for(n=0;n<i;n++)
{
System.out.println("The value of n="+n);
if(object[n].patientid.equals(pid))
{
d=1;
System.out.println("d="+d);
break;
}
}
if(d==0)
System.out.println("Please make sure yu entered the correct patient id");
else
{
object[n].searchpatient(object[n]);
}
d=0;
break;
case 0:System.exit(0);
default:System.out.println("\nInvalid Choice");
for(n=0;n<i;n++)
{
System.out.println(object[n].patientid);
}
break;
}
System.out.println("\nDo you wish to continue\ny. Press y to continue\nn. Press n to exit");
ch=new Scanner(System.in).next().charAt(0);
}while(ch=='y');
}
catch(Exception e)
{
}
}
}

Here is the code
it's a clinic program
i have to use package and object arrays
i have a difficulty in using them together
if i make three patients:
1 pid=23
2 pid=26
3 pid=21
and update pid=21
i cannot search and display pid=23 or pid=26
please help

Recommended Answers

All 4 Replies

you are making this way too complicated. break down your code in methods that way it'll be way easier to read and find any problems in there.

please i donot have much time
help me if you think you can

once i move forward in the object array backward traversal seems impossible

Your unformatted code is very hard to read and understand. Can you post code that is properly formatted?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.