Write a java method named checkHistory() that accepts an input string consisting of characters 'A', 'T', and
Question:
Write a java method named checkHistory() that accepts an input string consisting of characters 'A', 'T', and 'S' with meaning as stated in the table below for driving history. The method returns a Boolean value "true" if the driver is eligible for insurance discount based on two conditions stated below, or "false" otherwise.
A | T | S |
represents an accident. | represents a ticket. | represent a safe driving. |
Example 1 input string: "TATSSSSSSSSSTT"
Example 2 input string: "TATSTTTTSSSSSSSSSSSSSSS"
Example 3 input string: "TATSTTSSSSSSSSSSSSASS"
Note: the length of the given string is not fixed, and it could change from one driver to another. Your code should work for all given input that follows the constraint and it is not limited to provide examples. Test cases will cover all possible scenarios and it is not limited to the provide examples. So, the code should not have any hardcoded values.
Two conditions: A driver is eligible for an insurance discount attend if the driver history meets bothof the following conditions:
- The driver has accident ('A') forstrictlyfewer than two times (<2) in total.
- The driver hasnevera history of the record that contains three or moreconsecutivetickets.
The method should return true if the driver is eligible for insurance discount, and false otherwise.
The following is the method signature.
public static boolean checkHistory(String s)
The method should return true if the driver is eligible for the discount otherwise false.
Example 1:
Input: s = "TATSSSSSSSSSTT"
Return value: true
Explanation: The driver has fewer than two accidents and was never received 3 or more consecutive tickets. So, the driver is eligible.
Example 2:
Input: s = "TATSTTTTSSSSSSSSSSSSSSS"
Return value: false
Explanation: The driver has fewer than two accidents but was received 3 or more consecutive tickets. So, the driver is not eligible.
Example 3:
Input: s = "TATSTTSSSSSSSSSSSSASS"
Return value: false
Explanation: The driver has two accidents but was never received 3 or more consecutive tickets. So, the driver is not eligible.
Submission instructions:
Please submit only the java code for the method checkHistory()in the answer textbox by cut/paste or by directly coding in the textbox.
Fundamentals of Investing
ISBN: 978-0133075359
12th edition
Authors: Scott B. Smart, Lawrence J. Gitman, Michael D. Joehnk