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

Thread: Error while creating Gym member database through Java programming

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Error while creating Gym member database through Java programming

    hi there,

    i have started to work on another program. it is a gym member database. where members registration details are to be added and printed out on the screen.
    A Gym member record consists of membership number, name, postcode and fee.

    there has to be a class definition to represent Gym membership details.
    With a main method that declares and initialises two new Gym membership objects.

    Write a method to request data items from the user to fill both the new Gym member objects.
    and a method to display to the screen the names and membership numbers of both members.

    Example data entry ( “Z123456”, “Paul Jones”, “HN78HG”, 250);

    i have written what i could but when i compile the program it comes up with errors that i am having a problem understanding.
    could any one HELP!!!!!!! me through with this program.
    thanks

    import javax.swing.JOptionPane;
    import java.io.*;
     
    public class gym
    {
    public static void main (String [] args) throws IOException
    {
    int Counter=0;
    member[] members = new members[45];
     
    Controller(members, Counter);
    }
     
    public static void Controller(members[] values, int Counter) throws IOException
    {
    int Control=Integer.parseInt(JOptionPane.showInputDial og("MeNu\n" + "0 To Quit\n" + "1 to Add new employee" + "2 to Print the Employee" + "3 to Search\n"));
     
    while (Control!=0)
    {
     
    if (Control==1)
    {
    for (int count=0; count<1; count++)
    {
    values[Counter]=new members();
    String name=JOptionPane.showInputDialog("Name of member", "member");
    int number=JOptionPane.showInputDialog("gym number", "gym number");
    int postcode=Integer.parseInt(JOptionPane.showInputDia log("postcode","postcode"));
    values[Counter]= new Database(name, number, postcode);
    Counter++;
    }
    } // end of if 1
     
    else if (Control==2)
    {
    for (int count=0; count<Counter; count++)
    {
    values[count].showValues();
    }
    }
     
    else if (Control==3)
    {
    int DoSearch=Integer.parseInt(JOptionPane.showInputDia log("Searching\n" + "1 to Search member\n" + "2 to Search gym number\n" + "3 to Search postcode"));
     
    if (DoSearch==1)
    {
    String nameSearching=JOptionPane.showInputDialog("Search Name of member", "Name of member");
    int result=nameSearch(values, nameSearching , Control);
    if (result==-5)
    System.out.println("member That you Searched -> Not Found");
    else
    {
    System.out.println(nameSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
    else if (DoSearch==2)
    {
    int numberSearching=JOptionPane.showInputDialog("Searc h gym number", "Search gym number");
    int result=numberSearch(values, numberSearching , Control);
    if (result==-5)
    System.out.println("number That you Searched -> Not Found");
    else
    {
    System.out.println(numberSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
    else if (DoSearch==3)
    {
    int postcodeSearching=Integer.parseInt(JOptionPane.sho wInputDialog("Search postcode", "Search postcode"));
    int result=number(values, numberSearching , Control);
    if (result==-5)
    System.out.println("postcode That you Searched -> Not Found");
    else
    {
    System.out.println(postcodeSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
    }
    Control=Integer.parseInt(JOptionPane.showInputDial og("MeNu\n" + "0 To Quit\n" + "1 to Add new member\n" + "2 to Print gym number\n" + "3 to Search postcode\n"));
    }
    }
     
    public static int nameSearch(members[] values, String Thekey, int Size)
    {
    for (int y=0; y<Size; y++)
    {
    if (values[y].name.equals(Thekey))
    {
    return y;
    }
    }
    return -5;
    }
    public static int numberSearch(members[] values, int Thekey, int Size)
    {
    for (int h=0; h<Size; h++)
    {
    if (values[h].number.equalsIgnoreCase(Thekey))
    {
    return h;
    }
    }
    return -5;
    }
    public static int postcode(members[] values, int Thekey, int Size)
    {
    for (int r=0; r<Size; r++)
    {
    if (values[r].postcode==Thekey)
    {
    return r;
    }
    }
    return -5;
    }
    }

    class gym
    {
    String name;
    int number;
    int postcode;
     
    public gym(String n, int nm, int p)
    {
    name=n;
    number=nm;
    postcode=p;
    }
    public members()
    {
    name="Edward Downing";
    number="12345";
    postcode=2009;
    }
     
    public void showValues()
    {
    System.out.println("member " + " number " + " postcode ");
    }
    }
    Last edited by Deep_4; November 8th, 2012 at 01:18 PM. Reason: Please use [code] .. [/code] tags


  2. #2
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: error checking with my gym member program. please help!!!

    i dont exactly get the proccess of the program but since i 've viewed this post.. i've tried to edit it
    and i see this errors..


    import javax.swing.JOptionPane;
    import java.io.*;
     
     
    public class gym
    {
    public static void main (String [] args) throws IOException
    {
    int Counter=0;
    member[] members = new members[45];   //you are creating and "OBJECT" member for another object "member"
                                                                        //you must define a class that will accept this type of object creation "member"
                                                                        //(e.g) <Classname> newObject = new <Classname>( );,
                                                                        // or <Class> newObject = new Class( );
     
     
    Controller(members, Counter);
    }
     
    public static void Controller(members[] values, int Counter) throws IOException
    {
    int Control=Integer.parseInt(JOptionPane.showInputDialog("MeNu\n" + "0 To Quit\n" + "1 to Add new employee" + "2 to Print the Employee" + "3 to Search\n"));
     
    while (Control!=0)
    {
     
    if (Control==1)
    {
    for (int count=0; count<1; count++)
    {
    values[Counter] = new members( );                                                              //you have a method "members( );" its an instance of a class you cannot create an instance for an instance
                                                                                                                            //or you cannot create an object for an object
    String name=JOptionPane.showInputDialog("Name of member", "member");
    int number=Integer.parseInt(JOptionPane.showInputDialog("gym number", "gym number"));
    int postcode=Integer.parseInt(JOptionPane.showInputDialog("postcode","postcode"));
    values[Counter]= new Database(name, number, postcode);                     //you dont have a class or a file that names Database
    Counter++;                                                                                                  //There is no Database Class that exist in your program or package
    }
    } // end of if 1
     
     
    else if (Control==2)
    {
    for (int count=0; count<Counter; count++)
    {
    values[count].showValues();
    }
    }
     
    else if (Control==3)
    {
    int DoSearch=Integer.parseInt(JOptionPane.showInputDialog("Searching\n" + "1 to Search member\n" + "2 to Search gym number\n" + "3 to Search postcode"));
     
    if (DoSearch==1)
    {
    String nameSearching=JOptionPane.showInputDialog("Search Name of member", "Name of member");
    int result=nameSearch(values, nameSearching , Control);
    if (result==-5)
    System.out.println("member That you Searched -> Not Found");
    else
    {
    System.out.println(nameSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
    else if (DoSearch==2)
    {
    int numberSearching=Integer.parseInt(JOptionPane.showInputDialog("Searc h gym number", "Search gym number"));
    int result=numberSearch(values, numberSearching , Control);
    if (result==-5)
    System.out.println("number That you Searched -> Not Found");
    else
    {
    System.out.println(numberSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
     
    else if (DoSearch==3)
    {
    int postcodeSearching=Integer.parseInt(JOptionPane.showInputDialog("Search postcode", "Search postcode"));
    int result = number(values, numberSearching , Control);                                   //there is no variable numbersearching
    if (result==-5)
    System.out.println("postcode That you Searched -> Not Found");
    else
    {
    System.out.println(postcodeSearching + "\nis found in position\n" + (result+1));
    values[result].showValues();
    }
    }
    }
    Control=Integer.parseInt(JOptionPane.showInputDialog("MeNu\n" + "0 To Quit\n" + "1 to Add new member\n" + "2 to Print gym number\n" + "3 to Search postcode\n"));
    }
    }
     
    public static int nameSearch(members[] values, String Thekey, int Size)
    {
    for (int y=0; y<Size; y++)
    {
    if (values[y].name.equals(Thekey))
    {
    return y;
    }
    }
    return -5;
    }
    public static int numberSearch(members[] values, int Thekey, int Size)
    {
    for (int h=0; h<Size; h++)
    {
    if (values[h].number.equalsIgnoreCase(Thekey))
    {
    return h;
    }
     
    }
    return -5;
    }
    public static int postcode(members[] values, int Thekey, int Size)
    {
    for (int r=0; r<Size; r++)
    {
    if (values[r].postcode==Thekey)
    {
    return r;
    }
    }
    return -5;
    }
    }
     
     
     
     
     
     
    //an outer class which must be used by the gym class, you have used the class name "gym" here,
    //but you didnt notice that you already define this class name before.. your main program.
     
    class TheGym  //duplicated class.This is the name of your main class ,the top-level agent class where you are using the gym class ,this must class name must be changed
    {
     
    String name;
    int number;  //this was declared as int
    int postcode;
    String num;
     
    public TheGym(String n, int nm, int p)
    {
    name=n;
    number = nm;
    postcode=p;
    }
     
    public String members( )
    {
    name="Edward Downing";
    num ="12345";            //the method was asking for a return method, on the contrary you have 2 data types inside the method which is String and int
     
    return  name + number;
    }
     
    public int postCode( )
    {
        postcode=2009; //this data member was inside the method members( ); but this method doesnt have a return type so i put a String return type in it
                       //ive put a String because i notice that you have a string data members
        return postcode;
    }
     
     
    public void showValues()
    {
    System.out.println("member " + " number " + " postcode ");
    }
    }

    is this urgent?

    please read your program carefully.. coz you will learn alot from your own errors.

    Ive edited some of it.

    for you to see the errors.. try to compare this one into the original one.
    Last edited by chronoz13; August 25th, 2009 at 08:13 AM.

  3. The Following User Says Thank You to chronoz13 For This Useful Post:

    JavaPF (August 25th, 2009)

  4. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: error checking with my gym member program. please help!!!

    thanks very much and very much appretiated for the quick response to my proble. i have tried to go over the issues you highlighted in my program, but i keep gettin errors over and over again.

    could you please help me as im trying to get it done and i have been scratching my head for a long time with this probem. once again thanks for the quick response to my problem.

    thanks

  5. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: error checking with my gym member program. please help!!!

    another tip.. i would suggest you use eclipse or netbeans IDE
    because if you are typing your program code with these IDEs, you can see already the errors before you be able
    to compile it....

    its another easy way of checking errors, im using netbeans, but i think eclipse has the same capabilities like that.
    Ofcourse it has..


    and one more thing, please practice on writing java codes in a conventional way so you or anyone can easily determine
    the errors in your program , uppercase intials for classes, small initals for objects.
    (e.g MyClass , myObject) the opening and closing curly braces , the spacing between variables,objects,
    much like that, so just in case you will encounter some syntax error, you will be able to locate it easily,

    you're far more good in programming than me ,i can see that,and that's why i can't understand your big programs yet (your program's LOGIC) , but maybe you just have some bad writings. so please practice and enhance it, so anyone that can see your program can understand it very well...


    like what hellowolrd922 have said.. IN A BUNCH OF ERRORS THERE IS ONLY ONE RIGHT ANSWER....... thats the way of programming
    Last edited by chronoz13; August 25th, 2009 at 10:37 AM.

  6. #5
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: error checking with my gym member program. please help!!!

    Id second that idea of getting your self a proper editor/IDE to precompile your code while you are typing it.

    // Json

Similar Threads

  1. Checking in.
    By Johannes in forum Member Introductions
    Replies: 7
    Last Post: August 13th, 2009, 06:11 AM
  2. Redirect error and output stream using java program
    By leenabora in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: June 16th, 2009, 04:12 AM
  3. [SOLVED] Getting Exception " java.util.InputMismatchException" in scanner package
    By luke in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: May 20th, 2009, 04:55 AM
  4. New member
    By henry in forum Member Introductions
    Replies: 2
    Last Post: May 13th, 2009, 01:31 PM
  5. Replies: 2
    Last Post: February 4th, 2009, 11:24 AM