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

Thread: Need any assistance

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need any assistance

    Hi i am new to java and i was wondering if someone could help me with this code

    Trinbago Attractions Ltd. has engaged your company, The Software Development
    Company Ltd., to design and develop a software solution to replace the paper-based
    system currently used to manage operational data and support business operations.
    Business analysis personnel from your company have recently concluded their
    investigation phase of the client organization and have produced documentation detailing
    their findings inclusive of a basic analysis of stakeholder needs.
    The team has provided the following:
    1. There are two major users of the system, general clerical staff and attraction staff.
    2. Clerical Staff can:
    a. Register Customers (requires the customer’s name, age, gender, weight
    and height)
    b. Edit Customer Details
    c. Search for Customers
    d. Accept Payment
    e. View Packages
    3. The attraction staff can:
    a. View Customer Details
    b. View attraction rules and regulations
    c. Scan customer passes
    4. Every attraction needs to have a an algorithm that takes into consideration three
    factors, in order to determine if a customer can access the attraction. These factors
    are:
    a. Customer Age
    b. Customer Height
    c. Customer Weight
    5. The main attraction is called “The Blue Flipper” which requires:
    a. A minimum age of 10 and a maximum age of 65
    b. A minimum weight of 55 pounds and a maximum weight of 220 pounds
    c. A minimum height of 3.5 feet and a maximum height of 7 feet
    d. If a customer meets the height and weight requirements but is under aged
    they can still go on the ride.

    you are required to develop two parts of the system:
    1. The customer registration to be used by the clerical staff
    2. The core logic for gaining admission to “The Blue Flipper”

    I've gotten this far.
    import java.util.Scanner;
     
    import java.util.ArrayList;
    import java.util.List;
     
    public class SimpleMenu{
     
    	private static final String CREATE_PERSON_OPTION = "1";
    	private static final String SEARCH_PERSON_OPTION = "2";
    	private static final String QUIT_OPTION = "Q";
     
    	private static final int POSITION_NOT_FOUND = -1;
     
    	public static void printMainMenu( Scanner console ){
    		System.out.println( "\nPlease enter an option:" );
    		System.out.println( "Enter 1 to create a person." );
    		System.out.println( "Enter 2 to search a person." );
    		System.out.println( "Enter Q to quit.\n" );
    	}
     
    	public static void printCreatePersonMenu( Scanner console, List<String> names, List<Integer> ages ){
    		System.out.print( "\nPlease enter a name: " );
    		String name = console.next();
    		System.out.print( "Please enter an age: " );
    		Integer age = console.nextInt();
     
    		names.add( name );
    		ages.add( age );
    	}
     
    	public static int findPersonPosition( String name, List<String> names ){
    		return POSITION_NOT_FOUND;
    	}
     
    	public static void printSearchPersonMenu( Scanner console, List<String> names, List<Integer> ages ){
    		System.out.print( "Please enter a name: " );
    		String name = console.next();
     
    		int position = findPersonPosition( name, names );
    		if( position == POSITION_NOT_FOUND ){
    			System.out.printf( "Person with name %s was not found.\n", name );
    		}
    		else{
    			System.out.printf( "Found %s who is %d years old.\n", name, ages.get( position ) );
    		}
    	}
     
    	public static void handleOption( String option, Scanner console, List<String> names, List<Integer> ages ){
    		if( option.equals( CREATE_PERSON_OPTION ) ){
    			printCreatePersonMenu( console, names, ages );
    		}
    		else if( option.equals( SEARCH_PERSON_OPTION ) ){
    			printSearchPersonMenu( console, names, ages );
    		}
    		else{
    			System.out.println( "You entered an invalid option" );
    		}
    	}
     
    	public static void promptAndPrint( Scanner console, List<String> names, List<Integer> ages ){
    		while( true ){
     
    			printMainMenu( console );
    			String option = console.next();
    			if( option.equals( QUIT_OPTION ) ){
    				break;
    			}
    			handleOption( option, console, names, ages );
    		}
    	}
     
    	public static void main( String args[] ){
    		Scanner console = new Scanner( System.in );
     
    		List<String> names = new ArrayList<String>();
    		List<Integer> ages = new ArrayList<Integer>();
     
    		promptAndPrint( console, names, ages );
    	}
    }
    Last edited by Norm; April 10th, 2018 at 08:25 PM. Reason: added code tags

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need any assistance

    I've gotten this far.
    Ok, what do you want to do next? Pick an item, design the code and try writing it.
    If you have problems, post the code (Wrapped in code tags) and ask your questions about the problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need any assistance

    alright i've gotten this far but i keep getting an error on line 107 telling me that else without an if can some please help me

    import java.util.Scanner;

    import java.util.ArrayList;
    import java.util.List;

    public class SimpleMenu3{

    private static final String CREATE_PERSON_OPTION = "1";
    private static final String SEARCH_PERSON_OPTION = "2";
    private static final String Edit_PERSON_OPTION = "3";
    private static final String QUIT_OPTION = "Q";

    private static final int POSITION_NOT_FOUND = -1;

    public static void printMainMenu( Scanner console ){
    System.out.println( "\nPlease enter an option:" );
    System.out.println( "Enter 1 to create a person." );
    System.out.println( "Enter 2 to search a person." );
    System.out.println( "Enter 3 to edit a person." );
    System.out.println( "Enter Q to quit.\n" );
    }

    public static void printCreatePersonMenu( Scanner console, List<String> names, List<Integer> ages, List<String> genders, List<Integer> weights, List<Double> heights ){
    System.out.print( "\nPlease enter a name: " );
    String name = console.next();
    System.out.print( "Please enter an age: " );
    Integer age = console.nextInt();
    System.out.print( "\nPlease enter gender: " );
    String gender = console.next();
    System.out.print( "Please enter a weight in lbs: " );
    Integer weight = console.nextInt();
    System.out.print( "Please enter a height in feet: " );
    Double height = console.nextDouble();

    names.add( name );
    ages.add( age );
    genders.add( gender );
    weights.add( weight );
    heights.add( height );
    }

    public static void printEditPersonMenu( Scanner console, List<String> names, List<Integer> ages, List<String> genders, List<Integer> weights, List<Double> heights ){
    System.out.print( "Please enter a name: " );
    String name = console.next();

    int position = findPersonPosition( name, names );
    if( position == POSITION_NOT_FOUND ){
    System.out.printf( "Person with name %s was not found.\n", name );
    }
    else{
    System.out.print( "Please enter an age: " );
    Integer age = console.nextInt();
    System.out.print( "\nPlease enter gender: " );
    String gender = console.next();
    System.out.print( "Please enter a weight in lbs: " );
    Integer weight = console.nextInt();
    System.out.print( "Please enter a height in feet: " );
    Double height = console.nextDouble();

    names.add( name );
    ages.add( age );
    genders.add( gender );
    weights.add( weight );
    heights.add( height );
    }
    }

    public static int findPersonPosition( String name, List<String> names ){
    int i = 0;
    while( i < names.size() ){
    String thing = names.get(i);
    if( thing.equals( name ) ){
    return i;
    }
    ++i;
    }
    return POSITION_NOT_FOUND;

    }

    public static void printSearchPersonMenu( Scanner console, List<String> names, List<Integer> ages, List<String> gender, List<Integer> weights, List<Double> heights ){
    System.out.print( "Please enter a name: " );
    String name = console.next();

    int position = findPersonPosition( name, names );
    if( position == POSITION_NOT_FOUND ){
    System.out.printf( "Person with name %s was not found.\n", name );
    }
    else{
    System.out.printf( "Person name is %s.\n", names.get ( position ) );
    System.out.printf( "Person age is %d.\n", ages.get ( position ) );
    System.out.printf( "Person gender is %s.\n", gender.get ( position ) );
    System.out.printf( "Person weight is %d lbs.\n", weights.get ( position ) );
    System.out.printf( "Person height is %.2f ft.\n", heights.get ( position ) );
    }
    }

    public static void handleOption( String option, Scanner console, List<String> names, List<Integer> ages, List<String> gender, List<Integer> weights, List<Double> heights ){
    if( option.equals( CREATE_PERSON_OPTION ) ){
    printCreatePersonMenu( console, names, ages, gender, weights, heights );
    }
    else if( option.equals( SEARCH_PERSON_OPTION ) ){
    printSearchPersonMenu( console, names, ages, gender, weights, heights );
    }
    else if( option.equals( Edit_PERSON_OPTION ) ){
    printEditPersonMenu( console, names, ages, gender, weights, heights );
    else{
    System.out.println( "You entered an invalid option" );
    }
    }

    public static void promptAndPrint( Scanner console, List<String> names, List<Integer> ages, List<String> gender, List<Integer> weights, List<Double> heights ){
    while( true ){

    printMainMenu( console );
    String option = console.next();
    if( option.equals( QUIT_OPTION ) ){
    break;
    }
    handleOption( option, console, names, ages, gender, weights, heights );
    }
    }

    public static void main( String args[] ){
    Scanner console = new Scanner( System.in );

    List<String> names = new ArrayList<String>();
    List<Integer> ages = new ArrayList<Integer>();
    List<String> gender = new ArrayList<String>();
    List<Integer> weights = new ArrayList<Integer>();
    List<Double> heights = new ArrayList<Double>();

    promptAndPrint( console, names, ages, gender, weights, heights );
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need any assistance

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    error on line 107 telling me that else without an if
    Which line is 107?
    Add a comment like: //<<<<<<<<<<<< ERROR HERE
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. In need of assistance!
    By Nexcit in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 11th, 2014, 05:24 AM
  2. [SOLVED] for loop assistance
    By Kseidel in forum Loops & Control Statements
    Replies: 3
    Last Post: September 17th, 2012, 08:10 PM
  3. Need some assistance please
    By JavaPhish in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 25th, 2012, 10:00 AM
  4. New to the complmunity, need some assistance please.
    By nakedtriple in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 7th, 2011, 06:14 AM
  5. FileReader need assistance
    By tazjaime in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: November 8th, 2009, 01:12 AM