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 13 of 13

Thread: HELP ME HERE PLZ ... =(

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy HELP PLZ !!

    Hi ALL ..

    I'm having problems with this program ..

    The Program is clinical laboratory ..

    This Code for choosing what you want to do ..

    press (1) open new file .. press (2) for open existing file ..

    The IDEA : I will use Arrays to store each Patien name and gender .. when I want to open an existing file ..
    I will search for the name is it found or not .. if not .. I will open a new file .. I f yes .. I will display it on the screen ..

    There are ERRORS in the program .. and I'm a noob in arrays ..

    the code is :

    Main Class :

    import java.util.Scanner;
     
    public class PTest
    {
     
    	public static void main(String[] args)
    	{
     
    	Scanner input = new Scanner(System.in);
        	int arraylength=10;
    	String[] PatientName={"------","------","------","------","------","------","------","------","------","------"};
      	String[] Gender={"------","------","------","------","------","------","------","------","------","------"};
    	System.out.printf("%s\t\t %s\t\t","(1)Open New File","(2)Open Existing File");
     
             	int x=input.nextInt();
             	P obj= new P (PatientName,Gender);
     
                if(x==1) 
             	{
             		obj.showfiles();
             		System.out.println("Enter the number of file");
             		int y=input.nextInt();
     
             		obj.newPatient(y);
              if (x==2)
             	{   
     
             		 obj.showfiles();
             		 obj.searchName();
                         }
     
    }

    the Second Class :

    import java.util.Scanner;
     
    public class P
    {   	
           int arraylength=10;
           private String [] patientname;
           private String [] gender;
           Scanner input=new Scanner(System.in);
     
         public P (String [] PatientName , String [] Gender)
         {
         	setPatientName(PatientName); 
         	setGender (Gender);
         }
     
         public void setPatientName(String PatientName)
        {  
     
    	System.out.print("\nEnter the name: ");
                         for(int i=0;i<arraylength;i++)
    	 {
                               patientname[i] = input.nextLine();
                               break;
    	 }
         }
     
         public String getPatientName (int i)
         {
     
                     return patientname[i]; 
         }
     
     
         public void setGender ( String Gender)
         {  
                      System.out.print("\nEnter the gender: ");
     
                     for(int i=0;i<arraylength;i++)
    	{
    	          gender[i]=input.nextLine();
    	          break;
    	}
          }
     
          public String getGender(int i)
          { 
                       return gender[i];
          }
     
          public  void searchName()
         {
                      String[] patientName; 
                      System.out.print("\nEnter the name: ");
                      String N = input.next();
                      System.out.print("\nEnter the gender: ");
                     String G=input.next();
     
     
                  int result=search(patientName,name);
     
               if (result!=-1)
               {  
     
           	System.out.println("Registered Patient");
     
          	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: ",name,gender);
     
               } 
     
            else
            {
     
                System.out.println("You are not registered");
                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: ",getPatientName(),getGender());
            }		 	
     
        }
     
        public  int search(String[] array,String setName)
        {
     
            for ( int j=0; j  < array.length; j++ )
            if ( array[j] != null )
            if ( array[j].equals(setName) )  return j ; //found name.
     
            return -1 ; // name not found 
     
        }
     
     
      public void showfiles()
      { 
      	int arraylength=10;
      	String[] PatientName={"------","------","------","------","------","------","------","------","------","------"};
      	String[] Gender={"------","------","------","------","------","------","------","------","------","------"};
     
      	System.out.println("Ptient Name\t\tGender");
      	for (int i=0;i<arraylength;i++)
      		System.out.printf("%2d%20s%10s%20s",(i+1),PatientName[i],Gender[i]);
     
      }
     
      public void newPatient(int y)
      {
      	for (int i=y;i<arraylength;i++)
      	{
      		 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: ",getPatientName(i),getGender(i));
      	}
      }
     
    }

    PLZ PLZ HELP ME ..


  2. #2
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy HELP ME HERE PLZ ... =(

    HI ALL ..

    Sorry About the other Thread .. I managed to do a bitter code than that one & correct ALOT of ERRORS .. I'm Sorry

    This is the Modified Code :

    Class Main :

     
    import java.util.Scanner;
    public class CL
    {
    	public static void main(String[] args)
    	{
    	  Scanner input=new Scanner(System.in);
     
             String name=null;
             String gender=null;
             String date=null; 
             System.out.print("\n(1) Open New File \t(2) Open Existing File\n\n");
             System.out.print("Enter number of choice you want:");	
             int x=input.nextInt();
             if(x==1)
             {
              Patient obj1= new Patient (name,gender,date);	  
    		  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: ",obj1.getPatientName(),obj1.getGender(),obj1.getDate());
             }
     
             if (x==2)
             {   
              System.out.print("\nEnter the name: ");
              String N = input.next();
              Patient obj2= new Patient (N);	  
              obj2.searchName(N);
           //   Patient obj2= new Patient (N);
             }
       }
    }

    The Second Class :
    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 ; 
        }   
    }

    The Problem is ::

    when I open a new File :

    It Display :
    Patient Name:       Gender:         Date: 
    null                null            2/3/2010

    The Date is True .. BUT .. why is the name null and the gender

    ALSO..

    when I open an existing file .. it display you are not registered ..

    what the wrong with the code ,,

    Any help is greatly APPRECIATED ..

    and SORRY again abbout the other thread ..

  3. #3
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by Yazan View Post
    The Date is True .. BUT .. why is the name null and the gender
    Because you don't store the name and gender to the name and gender fields in the patient constructor - you add them to an array for some unexplained reason (why would a patient need multiple names and multiple genders??).

    If you stepped through the code by hand, you'd spot this in a minute.

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME HERE PLZ ... =(

    THX dlorde 4 your help ..

    my Idea is : I have some stored Patient files in the array ..
    so when I open a new file .. I will store the new Patient in the same array ,,
    when I want to open an existing file .. I will enter the name and it will tell me "Registered PAtient"
    if not .. display "You are not Reigisterd" ..

    BUT I Dunno How to Correct my CODE ..

    PLZ HELP ..

  5. #5
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by Yazan View Post
    my Idea is : I have some stored Patient files in the array ..
    so when I open a new file .. I will store the new Patient in the same array ,,
    when I want to open an existing file .. I will enter the name and it will tell me "Registered PAtient"
    if not .. display "You are not Reigisterd" ..
    You'll declare those arrays static so they are shared by the patients - the way it is, every patient will have their own arrays with only their own details in them.

    BUT I Dunno How to Correct my CODE ..
    You could try what I suggested before - store the name and gender to the name and gender fields in the patient constructor.

  6. #6
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    490
    Thanks
    8
    Thanked 46 Times in 44 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by dlorde View Post
    why would a patient need multiple names and multiple genders??
    Sex change surgery?

  7. #7
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by Darryl.Burke View Post
    Sex change surgery?
    HAHA i LOL-ed

  8. #8
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME HERE PLZ ... =(

         	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;
    				 }
    i guess its this, the for loop, you breaked it. patientName[0] thus name becomes null too as the value of 0 position in the array is a null. therefore you're printing null values

  9. #9
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by Darryl.Burke View Post
    Sex change surgery?
    LOL! for someone who keeps changing their mind

  10. #10
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by javanub:( View Post
    i guess its this, the for loop, you breaked it. patientName[0] thus name becomes null too as the value of 0 position in the array is a null. therefore you're printing null values
    The whole loop is wrong, but that's not the problem.

  11. #11
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME HERE PLZ ... =(

    oh...can you kindly point out the main problem? i'm too lazy to go through the whole piece of code LOL!

  12. #12
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: HELP ME HERE PLZ ... =(

    Quote Originally Posted by javanub:( View Post
    oh...can you kindly point out the main problem?
    I already did.

  13. #13
    Member
    Join Date
    Jan 2010
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: HELP ME HERE PLZ ... =(

    oh i didn't see it