Question: 5 2 0 Toll Bridge Write a program that calculates and returns the toll on the 5 2 0 bridge on weekends and holidays with
Toll Bridge
Write a program that calculates and returns the toll on the bridge on weekends and holidays with a Good To Go Pass. The program takes three values: hour, minute and ampm and prints out the toll price. Start coding with TollBridgejava provided. Keep input and output statements without change, add logic that calculated the toll based on the following table:
Weekends and Holidays
Good To Go Pass Toll
Midnight to : am
$
am to : am
$
am to : am
$
am to : pm
$
pm to : pm
$
pm to : pm
$
pm to : pm
$
Sample run #:
Hours
Minutes
am or pm lower case only am
Timestamp: : am
Charge: $
Input validation
Hours value must be in range If the hours value is invalid, an error message containing word ERROR in all caps must appear and the program must quit right away. See sample program run below:
Sample run #:
Hours
ERROR: Hours value is out of range! Quitting...
Minutes value must be in range If the minutes value is invalid, an error message containing word ERROR in all caps must appear and the program must quit right away. See sample program run below:
Sample run #:
Hours
Minutes
ERROR: Minutes value is out of range! Quitting...
am or pm must be correctly spelled in lower case letters. If ampm string is invalid, an error message containing word ERROR in all caps must appear and the program must quit right away. See sample program run below:
Sample run #:
Hours
Minutes
am or pm lower case only Am
ERROR: Invalid string. Must be either am or pm Quitting...
The following chart may be helpful if you are more used to military time and not very confident when converting it into the standard one.
Test cases
import java.ioByteArrayInputStream;
import java.ioByteArrayOutputStream;
import java.ioPrintStream;
import java.ioPrintWriter;
import java.util.regex.Pattern;
public class TestBridgeToll
public static boolean testsPrintWriter outputStream
int count ;
int expectedCount ;
outputStream.printr
Tests for BridgeTollr
;
Test
outputStream.printr
Test r
;
String sep System.lineSeparator;
String userInput String.formatssam", sep, sep;
String expectedOutput siERROR.;
outputStream.printr
Input:r
;
outputStream.printlnuserInput;
outputStream.printr
Expected output must fit RegEx:r
;
outputStream.printlnexpectedOutput;
PrintStream standard System.out;
ByteArrayInputStream bais new ByteArrayInputStreamuserInputgetBytes;
System.setInbais;
ByteArrayOutputStream baos new ByteArrayOutputStream;
PrintStream printStream new PrintStreambaos;
System.setOutprintStream;
BridgeTollmainnull;
String actual baos.toString;
printStream.close;
outputStream.printr
Actual Output:r
;
outputStream.printlnactual;
outputStream.println;
ifPatternmatchesexpectedOutput actual
outputStream.printfssr
"BridgeToll TEST invalid hours value", "PASSED";
count;
else
outputStream.printfssr
"BridgeToll TEST invalid hours value", "FAILED";
Test
outputStream.printr
Test r
;
userInput String.formatssam", sep, sep;
expectedOutput siERROR.;
outputStream.printr
Input:r
;
outputStream.printlnuserInput;
outputStream.printr
Expected output must fit RegEx:r
;
outputStream.printlnexpectedOutput;
bais new ByteArrayInputStreamuserInputgetBytes;
System.setInbais;
baos new ByteArrayOutputStream;
printStream new PrintStreambaos;
System.setOutprintStream;
BridgeTollmainnull;
actual baos.toString;
printStream.close;
outputStream.printr
Actual Output:r
;
outputStream.printlnactual;
outputStream.println;
ifPatternmatchesexpectedOutput actual
outputStream.printfssr
"BridgeToll TEST invalid hours value", "PASSED";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
