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

Thread: Where do I create my array?

  1. #1
    Junior Member SkynetSystems's Avatar
    Join Date
    Aug 2011
    Location
    England
    Posts
    9
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Where do I create my array?

    Hi, I am trying to make a simple program which is meant to resemble a hospital patient database.

    My aim is that when the user types in a patients name, I want it to type a couple of messages using methods which I have done successfully, for example "searching database". I want the program to then search an array for the patients name, if found, print the patients details/medical history onto the screen.

    Here is a sample of what I have got so far, I have been watching tutorials off youtube for guidance:

    public class HospitalOne {
     
         private String patient;
     
    	 public void setPatient(String name) {
    	     patient = name;
    	 }
    	 public String getPatient() {
    	     return patient;
    	 }
         public void details() {
    	     System.out.printf("Patient: %s", getPatient());
    	 }
    	 public void searching() {
    	     System.out.println("");
    	     System.out.println("Searching Database...");
    	 }
     
    	 public String[][] patName[100][10];
     
    	 patName[0][0] = "Name: Stephen Myhill";
    	 patName[0][1] = "Location: Chesterfield";
    	 patName[0][2] = "D.O.B: 31/2/80";
    	 patName[0][3] = "Medical History:";
     
    }
    import java.util.Scanner;
     
    class MainProgram {
     
    	 public static void main(String[] args) {
     
    	     Scanner input = new Scanner(System.in);
    		 HospitalOne col = new HospitalOne();
    		 System.out.println("Enter the name of the patient: ");
    		 String tempP = input.nextLine();
     
    		 col.setPatient(tempP);
    		 col.details();
    		 col.searching();
     
    		 if (col.patName[][].equalsIgnoreCase(tempP)) {
     
     
    		 }		 
    	 }
    }

    I am getting all kinds of errors but cannot identify and fix them. I don't even know if I am doing this correctly.

    My questions are:-

    1. Where should I be creating my array?
    2. Should I have a multi-dim array or should I use arrayList?


    Thank you for your time.

    Regards,

    SS.

    P.S - bit off topic, but what is wrong with java-forums.org (It is not loading for me anymore. I had a PM from some dude, replied and since then cannot get back on there).
    Last edited by SkynetSystems; September 2nd, 2011 at 04:20 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,302
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Where do I create my array?

    For future reference, please post the errors in their entirety...it helps pin down where exactly they are occurring. You are assigning values to the array outside of a method, and the array has not been instantiated as well. I'd advice - since java is object oriented - you create classes which define the data you wish to store as opposed to a parallel array. For searching, a Map might help.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Where do I create my array?

    I am getting all kinds of errors
    Please copy and paste here the full text of the error messages.

    Should I have a multi-dim array or should I use arrayList?
    You should create a class to hold the patient data and put instances of that into an ArrayList.

  4. #4
    Junior Member SkynetSystems's Avatar
    Join Date
    Aug 2011
    Location
    England
    Posts
    9
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Where do I create my array?

    There are 36 errors in the HospitalOne class which would have taken me around an hour to type in so I printscreened them, all of the following 'hidden' errors match the array errors.

    cmd2.jpg
    Attached Images Attached Images
    Last edited by SkynetSystems; September 2nd, 2011 at 05:00 PM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Where do I create my array?

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  6. #6
    Junior Member SkynetSystems's Avatar
    Join Date
    Aug 2011
    Location
    England
    Posts
    9
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Where do I create my array?

    C:\mywork>javac HospitalOne.java
    HospitalOne.java:19: error: ']' expected
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: illegal start of type
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: <identifier> expected
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: ';' expected
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: illegal start of type
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: <identifier> expected
    public String[][] patName[100][10];
    ^
    HospitalOne.java:19: error: ';' expected
    public String[][] patName[100][10];
    ^
    HospitalOne.java:21: error: illegal start of type
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: <identifier> expected
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: ';' expected
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: illegal start of type
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: <identifier> expected
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: ';' expected
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: illegal start of type
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:21: error: <identifier> expected
    patName[0][0] = "Name: Stephen Myhill";
    ^
    HospitalOne.java:22: error: ']' expected
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: ';' expected
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: illegal start of type
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: <identifier> expected
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: ';' expected
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: illegal start of type
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:22: error: <identifier> expected
    patName[0][1] = "Location: Chesterfield";
    ^
    HospitalOne.java:23: error: ']' expected
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: ';' expected
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: illegal start of type
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: <identifier> expected
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: ';' expected
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: illegal start of type
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:23: error: <identifier> expected
    patName[0][2] = "D.O.B: 31/2/80";
    ^
    HospitalOne.java:24: error: ']' expected
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: ';' expected
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: illegal start of type
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: <identifier> expected
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: ';' expected
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: illegal start of type
    patName[0][3] = "Medical History:";
    ^
    HospitalOne.java:24: error: <identifier> expected
    patName[0][3] = "Medical History:";
    ^
    36 errors

    C:\mywork>
    Last edited by SkynetSystems; September 2nd, 2011 at 05:03 PM. Reason: unnecessary info.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Where do I create my array?

    What do you want to do with this statement?
     public String[][] patName[100][10];
    That looks like a mix of defining an array and giving it a value. Try this:
    public String[][] patName = new String[100][10];

    The other errors could be because patName was not defined.

  8. #8
    Junior Member SkynetSystems's Avatar
    Join Date
    Aug 2011
    Location
    England
    Posts
    9
    My Mood
    Mellow
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Where do I create my array?

    Ah brilliant, I can't believe I didn't spot that mistake. :O

    Ok, so i'm going to take your advice and create a new class. Will have to look up arrayList also, thank you for the guidance.

Similar Threads

  1. HELP: UNABLE TO CREATE AND PRINT A 3-DIMENSIONAL ARRAY
    By baraka.programmer in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 3rd, 2011, 03:44 PM
  2. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM
  3. Replies: 2
    Last Post: April 21st, 2011, 10:29 AM
  4. How to create a sorted set from the contents of an array
    By davie in forum Collections and Generics
    Replies: 1
    Last Post: March 11th, 2010, 02:44 PM
  5. [SOLVED] Create new Array from old Array
    By satory in forum Collections and Generics
    Replies: 1
    Last Post: February 24th, 2010, 11:44 AM