import java.util.Scanner;
public class Patient
{
private String[] patientName={null,"N1",null,null,"N2",null,"N3",null,null,"N4"};
private String[] Gender={null,"M",null,null,"F",null,"M",null,null,"F"};
String name=null;
String gender=null;
private int Month;
private int Day;
private int Year;
Scanner input=new Scanner(System.in);
public Patient (String name , String gender, String date)
{
setPatientName(name);
setGender (gender);
setDate(Month,Day,Year);
}
public Patient (String name )
{
searchName (name);
}
public void setPatientName(String name)
{
int i;
System.out.print("\nEnter the name: ");
name = input.next();
for(i=0; i<patientName.length; i++)
{
patientName[i]=name;
break;
}
}
public String getPatientName ()
{
return name;
}
public void setGender ( String gender)
{
int i;
System.out.print("\nEnter the gender: ");
gender = input.next();
for(i=0;i<Gender.length;i++)
{
Gender[i]=gender;
break;
}
}
public String getGender()
{
return gender;
}
public void setDate(int month , int day , int year )
{
Month = checkMonth( month );
setYear (year);
Day = checkDay( day );
}
public String getDate()
{
return String.format( "%d/%d/%d", Day , Month , Year );
}
public int checkMonth( int month )
{
System.out.print("\nEnter the month: ");
month = input.nextInt();
if ( month > 0 && month <= 12 )
return month;
else
{
System.out.printf("Invalid month (%d) set to 1.", month );
return 1;
}
}
public int checkDay( int day )
{
System.out.print("\nEnter the day: ");
day = input.nextInt();
int daysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if ( day > 0 && day <= daysPerMonth[ Month ] )
return day;
if ( Month == 2 && day == 29 && ( Year % 400 == 0 ||
( Year % 4 == 0 && Year % 100 != 0 ) ) )
return day;
System.out.printf( "Invalid day (%d) set to 1.", day );
return 1;
}
public void setYear (int year)
{ System.out.print("\nEnter the year: ");
year = input.nextInt();
Year = year;
}
public int getYear()
{
return Year;
}
public void searchName(String name)
{
int result=search(name);
if (result!=-1)
{
System.out.println("Registered Patient");
System.out.printf("\n\n%s\t\t%s\n%s\t\t\t\t%s\n\n","Patient Name: ","Gender: ",name,Gender[result]);
}
else
{
System.out.println("You are not registered");
setGender (gender);
setDate(Month,Day,Year);
System.out.printf("\n\n%s\t\t%s\t\t%s\n%s\t\t\t\t%s\t\t\t%s\n\n","Patient Name: ","Gender: ","Date: ",name,getGender(),getDate());
}
}
public int search(String name)
{int a=0;
for ( int j=0; j < patientName.length; j++ )
{
if ( name == patientName[j] )
a = j ; // found
else
a = -1 ; //not found.
}
return a ;
}
}