CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Gym Membership

  1. #1
    Join Date
    Mar 2018
    Posts
    1

    Gym Membership

    So I am quite new to Java and I am looking for any pointers. I need to write a program to devise the membership of members to a gym.

    Need to work out cost of new members-this depends upon a level of membership
    Need to add a yearly cost to all members
    Need to add a joining fee

    So far this is what I have

    Code:
    import java.util.Scanner;                       // user input
    
    public class Gym
    {
        public static void main ( String[] args )
        {
            //  define constants
            final double generalmembership = 100;      
            final double studentmembership= 55;
            final double undereightmembership = 35;
            final double COMPETITION_FEE       = 10;        // fee all members pay
        
            //Input Variables 
            char type; // 'G' General membership or 'S' Student membership or 'U' for Under eighteen membership
    	
            //  Set up for user input
            Scanner input = new Scanner( System.in );
            /********************************************************************/
    
            // Read Inputs
            System.out.println ( "Please enter major ('G' for General Member, 'S' for Student or 'U' for Under Eighteen): " );
            type = input.nextLine().charAt(0);
            {
                //Cost of Memberships
                If (type == 'G' || type == 'g') {
                    type = 'G';
                }
                else if (type == 'S' || type == 's') {
                    type = 'S';
                }
                else if (type == 'U' || type == 'u') {
                }
    
                //Calculate membership costs
    Any pointers/criticism is welcome as I am here to learn and develop
    Last edited by 2kaud; March 10th, 2018 at 04:58 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Gym Membership

    [When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#']

    Cheers!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Feb 2017
    Posts
    677

    Re: Gym Membership

    Quote Originally Posted by REDSTAR81 View Post
    Any pointers/criticism is welcome as I am here to learn and develop
    I suppose you haven't compiled anything yet because then you would've detected the error in this line,

    Code:
                If (type == 'G' || type == 'g') {
    It's a common newbie mistake to enter lots of code ending up with an impregnable pile they cannot get to work.

    A much better strategy is to use the so called "stepwise refinement" method. First you get a minimal trivial "Hello World" program up and running. Then you add functionality little by little in small incremental steps and most importantly, after each change you make sure everything works as intended. Eventually you'll end up with a complete working program because it's been working all the time.

    First find out how far you get on your own. Only ask for help when you're truly at your wit's end and totally desperate. That's how you learn how to program.

    Good luck!
    Last edited by wolle; March 11th, 2018 at 02:05 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured