Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will pass this junit test case import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Scanner; import org.junit.jupiter.api.Test; class RouteRecommenderTest { private static String

Write a program that will pass this junit test case

import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Scanner; import org.junit.jupiter.api.Test; class RouteRecommenderTest { private static String testInput1 = "route 2 15 " + "A3 4 " + "B3 3 " + "C3 5 " + "D3 2 " + "end " + "route 4 10 " + "B1 3 " + "B2 1 " + "B3 6 " + "B4 3 " + "end " + "route 3 20 " + "D3 3 " + "D4 1 " + "C4 6 " + "B4 4 " + "A4 3 " + "end " + "end " + "A3 A4 1 " + "B1 C4 2 " + "end " + ""; private static String [] testOutput1 = { "At stop A3 take bus #2", "At stop B3 switch to bus #4", "At stop B4 switch to bus #3", "Get off at stop A4", "At stop B1 take bus #4", "At stop B3 switch to bus #2", "At stop D3 switch to bus #3", "Get off at stop C4" }; private static Scanner mkTest( String input ) { return new Scanner( input ); } private static ArrayList mkOutput( String [] output ) { ArrayList al = new ArrayList(); for( String s : output ) { al.add( s ); } return al; } private static boolean doTest( String input, String [] output ) { Tester t = new RouteRecommender(); ArrayList al = t.compute( mkTest( input ) ); System.out.println( "Input: " ); System.out.println( input ); System.out.println( "Generated output" ); for( String s : al ) { System.out.println( s ); } System.out.println( "Expected output" ); for( String s : output ) { System.out.println( s ); } System.out.println( "---------------------------------------------------" ); return al != null && al.equals( mkOutput( output ) ); } @Test void test1() { assertTrue( doTest( testInput1, testOutput1 ), "Multiple queries" ); } }

JAVA PROGRAMMING

Write a program called RouteRecommender.java that reads in a bus network and one or more trip queries from the console (System.in) and outputs a trip recommendation for each query. Your RouteRecommender class must implement the provided Tester interface and also contain the main() method where your program starts running. This is because your program will be tested via this interface. The interface contains a single method: public ArrayList compute( Scanner input ); This method must perform the required computation.

Input The compute() method takes a Scanner object, which contains the input. The input is divided into two parts: a bus network portion and a query portion. The bus network part consists of one or more bus routes followed by a line with a single end. Each bus route begins with the line: route R F where R is the route number and F denotes the frequency of the busses on this route, and will be one of 10, 15, 20, or 30, meaning the bus runs every 10, 15, 20, or 30 minutes. This line is followed by one or more lines specifying bus stops on the route. Each bus stop is specied by a name and the time it takes the bus to arrive from the previous bus stop. S T where S is a single word with no spaces, and T is an integer, denoting the time it takes for the bus to travel from the previous bus stop. For the rst bus stop in a route, the number is interpreted as the number of minutes after the hour that the bus arrives. A bus route is ended by a single line containing the end key word. After all bus routes are done, a second line containing the end keyword occurs. The second portion of the input consist of one or more queries for route recommendations. Each query is a triple of the form Orig Dest t where Orig is where the rider will start and Dest is where the rider is trying to get to. The third value, t, is an integer, between 0 and 60, indicating the time in minutes past the hour when the rider will arrive at the starting bus stop. The last line of the queries section contains the end keyword.

Output The method compute( Scanner input ) should return an ArrayList of Strings denoting the route recommendations, one per query. Each route recommendation consists of two or more lines. The rst line of a recommendation is of the form: At stop S take bus #B where S is where rider is to board bus and B is the route number. For each stop where the rider needs to switch busses, output a line of the form: At stop S switch to bus #B where S and B are the same bus stop and route number, just as before. The last line of the recommendation should be of the form: Get off at stop S where S is the destination stop.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions

Question

(5) What is the regression matrix (A) for this example? Pg45

Answered: 1 week ago

Question

Persuading Your Audience Strategies for

Answered: 1 week ago