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

Thread: PLEASE HELP!!!! simple java program...

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

    Default PLEASE HELP!!!! simple java program...

    Hi there,

    im seeking HEP!!!! from any one who could solve my problem. i have a program to be written that consists of gym members details and prints tem out to the screen.

    A program is to be written to store Gym registration details. A Gym member record consists of membership number, name, postcode and fee.

    Write a class definition to represent such Gym membership details.

    Write 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.

    Write a method to display to the screen the names and membership numbers of both members.

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


    thanks ...


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: PLEASE HELP!!!! simple java program...

    This sounds like a homework assignment... could you post your code/thoughts on how to solve this? I don't want to do your homework for you.

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

    Smile Re: PLEASE HELP!!!! simple java program...

    is this what you need?

    your class "Gym" first.

    public class Gym
     
    {
     
        /*I declared all the variables as String for a while,(some kind of a dummy)
         *if there is anychanges you want, change it
         */
        private String membershipNumber;
        private String memberName;
        private String memberPostCode;
        private String gymFee;//is this registration fee??
     
        public Gym(String number, String name, String postCode, String fee)
        {
            setMembershipNumber(number);
            setMemberName(name);
            setPostCode(postCode);
            setFee(fee);
        }
     
        /*I declared all the objects as private because the Constructor itself accepsts
         *arguments and pass it to each methods parameter
         */
     
        /*There is no longer need of invoking each every method to set a
         *corresponding value
         */
     
        //set the membership number of a member as String
        private void setMembershipNumber(String number)
        {
            membershipNumber = number;
        }
     
        //sets the name of the member as String
        private void setMemberName(String name)
        {
            memberName = name;
        }
     
        //sets the post code as String
        private void setPostCode(String postCode)
        {
            memberPostCode = postCode;
        }
     
        //sets the fee as String
        private void setFee(String fee)
        {
            gymFee = fee;
        }
     
        //return methods here
        private String getMemberNumber( )
        {
            return membershipNumber;
        }
     
        private String getMemberName( )
        {
            return memberName;
        }
     
        private String getPostCode( )
        {
            return memberPostCode;
        }
     
        private String getFee( )
        {
            return gymFee;
        }
     
        /*I created a method displayOutput,just in case the user wants to use all the
         *return methods in just one call
         */
        public void displayOutput( )
        {
            System.out.println("Number: " + getMemberNumber( ) + "\n" +
                              ("Name: " + getMemberName( ) + "\n" +
                              ("Post Code: " + getPostCode( ) + "\n" +
                              ("Fee: " + getFee( )))));
        }
     
    }






    your main class or rather MAIN METHOD where you will use the the gym class


    /*Your Main program
     */
     
    public class GymMembers
     
    {
     
        public static void main(String[] args)
        {
          Gym gymMembership1 = new Gym("129983", "Zabdiel", "1490", "50.00");
          Gym gymMembership2 = new Gym("324512", "Java", "00013", "40.00");
     
          gymMembership1.displayOutput( );
          System.out.println("\n");
          gymMembership2.displayOutput( );
     
        }
    }


    im not sure if this is exactly what you need, but i've done almost of it.. you take the rest
    i dont know what database you are talking about.. arrays maybe.. its all up to you now

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

    Default Re: PLEASE HELP!!!! simple java program...

    hi there tanks alot for the code. very much appretiated!!!!
    thanks alot

    but when i compile the program i get an error from the compiler...

    C:\Documents and Settings\user\My Documents\Gym.java:91: inner classes cannot have static declarations
    public static void main(String[] args)
    ^
    1 error

    Tool completed with exit code 1



    and the code for the program is...........


    public class Gym

    {

    private String membershipNumber;
    private String memberName;
    private String memberPostCode;
    private String gymFee;

    public Gym(String number, String name, String postCode, String fee)
    {
    setMembershipNumber(number);
    setMemberName(name);
    setPostCode(postCode);
    setFee(fee);
    }

    /*I declared all the objects as private because the Constructor itself accepsts
    *arguments and pass it to each methods parameter
    */


    //set the membership number of a member as String
    private void setMembershipNumber(String number)
    {
    membershipNumber = number;
    }

    //sets the name of the member as String
    private void setMemberName(String name)
    {
    memberName = name;
    }

    //sets the post code as String
    private void setPostCode(String postCode)
    {
    memberPostCode = postCode;
    }

    //sets the fee as String
    private void setFee(String fee)
    {
    gymFee = fee;
    }

    //return methods here
    private String getMemberNumber( )
    {
    return membershipNumber;
    }

    private String getMemberName( )
    {
    return memberName;
    }

    private String getPostCode( )
    {
    return memberPostCode;
    }

    private String getFee( )
    {
    return gymFee;
    }

    /* A method displayOutput,just in case the user wants to use all the
    *return methods in just one call
    */
    public void displayOutput( )
    {
    System.out.println("Number: " + getMemberNumber( ) + "\n" +
    ("Name: " + getMemberName( ) + "\n" +
    ("Post Code: " + getPostCode( ) + "\n" +
    ("Fee: " + getFee( )))));
    }

    /*Main program
    */

    public class GymMembers

    {

    public static void main(String[] args)
    {
    Gym gymMembership1 = new Gym("129983", "Parvez", "1490", "50.00");
    Gym gymMembership2 = new Gym("324512", "Mdx", "00013", "40.00");

    gymMembership1.displayOutput( );
    System.out.println("\n");
    gymMembership2.displayOutput( );
    System.exit(0);
    }

    }
    }

  5. #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: PLEASE HELP!!!! simple java program...

    You need to move your main into your normal class.

    public class Gym
     
    {
     
    private String membershipNumber;
    private String memberName;
    private String memberPostCode;
    private String gymFee;
     
    public Gym(String number, String name, String postCode, String fee)
    {
    setMembershipNumber(number);
    setMemberName(name);
    setPostCode(postCode);
    setFee(fee);
    }
     
    /*I declared all the objects as private because the Constructor itself accepsts
    *arguments and pass it to each methods parameter
    */
     
     
    //set the membership number of a member as String
    private void setMembershipNumber(String number)
    {
    membershipNumber = number;
    }
     
    //sets the name of the member as String
    private void setMemberName(String name)
    {
    memberName = name;
    }
     
    //sets the post code as String
    private void setPostCode(String postCode)
    {
    memberPostCode = postCode;
    }
     
    //sets the fee as String
    private void setFee(String fee)
    {
    gymFee = fee;
    }
     
    //return methods here
    private String getMemberNumber( )
    {
    return membershipNumber;
    }
     
    private String getMemberName( )
    {
    return memberName;
    }
     
    private String getPostCode( )
    {
    return memberPostCode;
    }
     
    private String getFee( )
    {
    return gymFee;
    }
     
    /* A method displayOutput,just in case the user wants to use all the
    *return methods in just one call
    */
    public void displayOutput( )
    {
    System.out.println("Number: " + getMemberNumber( ) + "\n" +
    ("Name: " + getMemberName( ) + "\n" +
    ("Post Code: " + getPostCode( ) + "\n" +
    ("Fee: " + getFee( )))));
    }
     
     
    public static void main(String[] args)
    {
    Gym gymMembership1 = new Gym("129983", "Parvez", "1490", "50.00");
    Gym gymMembership2 = new Gym("324512", "Mdx", "00013", "40.00");
     
    gymMembership1.displayOutput( );
    System.out.println("\n");
    gymMembership2.displayOutput( );
    System.exit(0);
    }
    }

    // Json

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: PLEASE HELP!!!! simple java program...

    Remember you need to setup 2 different classes. Gym and GymMembers.

    public class Gym
     
    {
     
        private String membershipNumber;
        private String memberName;
        private String memberPostCode;
        private String gymFee;
     
        public Gym(String number, String name, String postCode, String fee) {
            setMembershipNumber(number);
            setMemberName(name);
            setPostCode(postCode);
            setFee(fee);
        }
     
        /*
         * I declared all the objects as private because the Constructor itself
         * accepstsarguments and pass it to each methods parameter
         */
     
        // set the membership number of a member as String
        private void setMembershipNumber(String number) {
            membershipNumber = number;
        }
     
        // sets the name of the member as String
        private void setMemberName(String name) {
            memberName = name;
        }
     
        // sets the post code as String
        private void setPostCode(String postCode) {
            memberPostCode = postCode;
        }
     
        // sets the fee as String
        private void setFee(String fee) {
            gymFee = fee;
        }
     
        // return methods here
        private String getMemberNumber() {
            return membershipNumber;
        }
     
        private String getMemberName() {
            return memberName;
        }
     
        private String getPostCode() {
            return memberPostCode;
        }
     
        private String getFee() {
            return gymFee;
        }
     
        /*
         * A method displayOutput,just in case the user wants to use all thereturn
         * methods in just one call
         */
        public void displayOutput() {
            System.out.println("Number: "
                    + getMemberNumber()
                    + "\n"
                    + ("Name: " + getMemberName() + "\n" + ("Post Code: "
                            + getPostCode() + "\n" + ("Fee: " + getFee()))));
        }
    }
    /* Main program */
     
    public class GymMembers
     
    {
     
        public static void main(String[] args) {
            Gym gymMembership1 = new Gym("129983", "Parvez", "1490", "50.00");
            Gym gymMembership2 = new Gym("324512", "Mdx", "00013", "40.00");
     
            gymMembership1.displayOutput();
            System.out.println("\n");
            gymMembership2.displayOutput();
            System.exit(0);
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. help with simple java program
    By parvez07 in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2009, 07:19 AM
  2. Simple java program to calculate wall covering of a room
    By parvez07 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 22nd, 2009, 03:31 PM
  3. Java Program Help
    By javakid93 in forum Java Theory & Questions
    Replies: 6
    Last Post: July 27th, 2009, 11:03 AM
  4. Someone please help me write a simple program!!!
    By ocean123 in forum Loops & Control Statements
    Replies: 3
    Last Post: June 14th, 2009, 09:46 PM
  5. Java program to write game
    By GrosslyMisinformed in forum Paid Java Projects
    Replies: 3
    Last Post: January 27th, 2009, 03:33 PM