Uploaded by allendavid267

AmuseIfPractice Use for Lab Fall 2021

advertisement
Practice With If-Statements, Part 1: Code a Solution
1. Complete an application program to determine if a customer is eligible to go on an amusement park
ride or not, and if so, how much the ticket would cost.
2. Prompt the user to enter the following information:
 first name
 age (whole number)
 height in inches (floating point number)
 category of ride desired (a single character: one of ‘A’, ‘C’, or ‘E’)
3. Use this information to determine: a) whether the customer may go on the ride, and b) if so, how
much the ticket would cost.
4. Display a message stating whether the customer may ride, and if so, how much the ticket will cost.
5. As a special incentive, customers with your first name may ride free today on any category ‘A’ or ‘C’
ride!
The rules are as follows:
Category of Ride
Rules
‘A’ , ‘C’
No restrictions on age or height. Tickets are $1.00 for everyone,
unless the customer’s name matches yours and the ticket is free.
‘E’
The following rules apply:
Any other letter

If the customer is at least 5 and less than 16, then the
customer’s height is used to determine eligibility to ride,
as follows:
o If height is at least 46 inches, the customer can
ride, and the ticket is $2.00.
o If height is less than 46 inches, the customer
cannot ride.

If the customer is 16 years old or older, the customer can
always ride, regardless of height, and the ticket price is
$3.00 .

If the customer is less than 5 years old, the customer
cannot ride, regardless of height.
Invalid ride category.
Helpful tips:
1. Develop incrementally. Declare variables, prompt and read in. Develop outside level of ifstatement with categories first.
2. Then develop the nested if-statement under the ‘E’ category.
import java.util.Scanner;
public class AmuseParkApp
{
public static void main(String [] args)
{
Scanner terminal = new Scanner(System.in);
Practice With If-Statements, Part 2: Developing a Test Plan
A complete test plan for your program would need to include test cases (individual tests) with all possible
combinations of ride category, age, height, and name match, to make sure that all logic paths execute
correctly. The plan would become quite large.
Let’s consider the test cases for a small part of the code-- the age test. The rule states:
“ If the customer is at least 5 and less than 16, then the customer’s height is used to determine
eligibility to ride”
To test if age is at least 5 and less than 16, what would be the testing guidelines? When a range is
involved, the following cases should be tested:
Testing guidelines for ranges:
1. Test boundary values
2.
3.
4.
5.
6.
Example values for testing age:
Test using ____
Test using ____
Test value inside of range
Test using ____
Test reasonable values outside of range, Test using less than 5, for example: _____
just below lower boundary and just above Test using greater than 16, for example: ____
higher boundary
Test extreme values well outside the
Test using a very large age value, such as: ____
range
Test using a very small age value (can be handled
by values in #4 below)
Test potentially troublesome values, such Test using 0
as 0, 1, or negative numbers (does your
Test using 1
code still execute correctly, or are there
Testing using a negative number, such as: _____
weaknesses, such as a potential division
by zero?)
Test a value selected at random
?
Download