Class ConditionalsLab
Object
ConditionalsLab
Conditionals lab. All methods in this lab are static methods, and the code is provided in most cases.
Make sure to follow the steps provided in the lab writeup (Readme.md) using the description of each method
to help you with the lab steps.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
laneCheck
(int value) Checks the speed of a car and returns the appropriate lane.static void
The following main method is the entry point to your program.static String
streetLight1
(String color) Checks which color a street light is and returns the appropriate car action.static String
streetLight2A
(String color) Checks which color a street light is, ignoring case, and returns the appropriate car instruction.static String
streetLight2B
(String color) Checks which color a street light is, ignoring case, and returns the appropriate car instruction.static String
streetLight3
(String color) Extra Practice Method This checks which color a street light is, ignoring case, and returns the appropriate car instruction.private static void
Runs test for laneCheck().private static void
Tests the three stop light colors and a fourth color.static void
Tests that run the various tests for bothstreetLight2A(String)
andstreetLight2B(String)
.
-
Constructor Details
-
ConditionalsLab
public ConditionalsLab()
-
-
Method Details
-
laneCheck
Checks the speed of a car and returns the appropriate lane.
The based on the following speed of the car (value of value), the matching values are returned.- if the value is less than or equal to 50:
"Slow Lane" is returned - if the value is greater than 100:
"Jail Lane" is returned - else: fast lane is returned (note you don't need an else statement)
- Parameters:
value
- speed of car- Returns:
- a string describing the lane
- if the value is less than or equal to 50:
-
testLaneCheck
private static void testLaneCheck()Runs test for laneCheck(). Notice the tests are looking at the "bounds" of the if statement. Looking at the provided codem, what conditions did we not check for in this method? -
streetLight1
Checks which color a street light is and returns the appropriate car action.- red returns "Stop"
- yellow returns "Slow"
- green returns "Go"
- Anything else returns ERROR
- Parameters:
color
- street light color- Returns:
- string designating car action
- See Also:
-
testStreetLight1
private static void testStreetLight1()Tests the three stop light colors and a fourth color. -
streetLight2A
Checks which color a street light is, ignoring case, and returns the appropriate car instruction.- red (ignoring case) returns "Stop"
- yellow (ignoring case) returns "Slow"
- anything else, returns "Go".
- Parameters:
color
- street light color- Returns:
- string designating car instruction
-
streetLight2B
Checks which color a street light is, ignoring case, and returns the appropriate car instruction.- red (ignoring case) returns "Stop"
- yellow (ignoring case) returns "Slow"
- anything else, returns "Go".
String.equalsIgnoreCase(String)
is changed toString.contains(CharSequence)
- Parameters:
color
- street light color- Returns:
- String designating car instruction
- See Also:
-
testStreetLight2AB
public static void testStreetLight2AB()Tests that run the various tests for bothstreetLight2A(String)
andstreetLight2B(String)
. To be developed by the student. Look attestStreetLight1()
for example tests, and code to write. -
streetLight3
Extra Practice Method This checks which color a street light is, ignoring case, and returns the appropriate car instruction.- Parameters:
color
- street light color- Returns:
- string designating car instruction
-
main
The following main method is the entry point to your program. We are using the main method simply to 'test' the code in this file. A very common technique.- Parameters:
args
- - unused
-