Class ConditionalsLab

Object
ConditionalsLab

public class ConditionalsLab extends Object
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 Details

    • ConditionalsLab

      public ConditionalsLab()
  • Method Details

    • laneCheck

      public static String laneCheck(int value)

      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)
      When you did the self-explaination of the code provided to you, did it match the conditions above? If not, how do you need to modify your code to match those conditions?
      Parameters:
      value - speed of car
      Returns:
      a string describing the lane
    • 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

      public static String streetLight1(String color)
      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
      This method is not null safe, meaning if color is null, it will crash.
      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

      public static String streetLight2A(String color)
      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".
      This method is not null safe, meaning if color is null, it will crash.
      Parameters:
      color - street light color
      Returns:
      string designating car instruction
    • streetLight2B

      public static String streetLight2B(String color)
      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".
      What happens if String.equalsIgnoreCase(String) is changed to String.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 both streetLight2A(String) and streetLight2B(String). To be developed by the student. Look at testStreetLight1() for example tests, and code to write.
    • streetLight3

      public static String streetLight3(String color)
      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

      public static void main(String[] args)
      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