Write a java program called tramjava that firstly prompts


Assignment

Objectives:

• To practise using the String class.
• To practise using if, if-else statements.
• To practise reading from and writing to the console and reading from a text file.

Task 1 - Tram.java

Write a Java program called Tram.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records. A record in this file is a single line of text in the following format:

Suburb[Tracker Id[Stop Number[Cross Street[Road

where

Suburb is the name of the suburb through which the tram is travelling at the location indicated by the information in the last part of the record.

This is a String (text) and may contain more than one word.

The Suburb is followed by a '[' character, there are no spaces between the end of the Suburb, the '[' and the start of the Tracker Id.

Tracker Id is the Tram Tracker Id of the Tram stop. Tracker Id's are unique. Tracker Id's are always 4 digits (integers). The Tracker Id is followed by a '[' character, there are no spaces between the end of the Tracker Id, the '[' and the start of the Stop Number.

Stop Number is the number of the Tram stop, this is an integer and may consist of one or two digits. The Stop Number is followed by a '[' character, there are no spaces between the end of the Stop Number, the '[' and the start of the Cross Street.

Cross Street is the name of the nearest cross street to a Tram stop. This is a String (text) and may contain more than one word.

This Cross Street is followed by a '[' character, there are no spaces between the end of the Cross Street, the '[' and the start of the Road

Road is the name of the road along which the tram is currently traveling. This is a String (text) and may contain more than one word.

This is the end of the record (line), there are no blank spaces after the Road.

An example of some of the lines of this file might be:

Thornbury[1373[33[Hutton Street[St Georges Road Thornbury[1372[32[Normanby Avenue[St Georges Road Northcote[1371[31[Gadd Street[St Georges Road

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.

Also, your program must work with any file name of the correct format.

(Do not hard code the file name.)

Once this file has been opened, the user is then prompted for a Stop Number.

The program then reads through the file. If a matching Stop Number is found in the file, all the information for that Tram stop (the complete record) is displayed to the screen. The order of display is shown in the example runs below.

Stop Number's are unique in the file, so there will be at most only one match.

If the entire contents of the file has been read and no match is found, then an appropriate message is displayed to the screen.

Some sample runs of the program are included below (user input is in bold): (Note that the sample runs do not necessarily show all the functionality required)

> java Tram
Enter file name >> route11.dat
Enter stop number >> 40
Stop number: 40 Suburb: Preston Road: Gilbert Road
Cross street: Bell Street Tracker Id: 1380

> java Tram
Enter file name >> route11.dat
Enter stop number >> 50
Stop number 50 was not found on this route

> java Tram
Enter file name >> e.dat
File "e.dat" is an empty file, closing the program

Task 2 - Street.java

Write a Java program called Street.java that, firstly, prompts (asks) the user to enter an input file name. This is the name of a text file that can contain any number of records (lines).

Each record has the same format as Task 1

The input file may have 0 to any number of records. The format of the input file is guaranteed to be correct. Your program does not have to check the format.

Also, your program must work with any file name of the correct format.
(Do not hard code the file name.)

Once this file has been opened, the program checks if this file is empty (you may assume that the user always enters a valid file name). If the file is empty the program displays an appropriate message to the screen and closes, without using System.exit( ).

If the file is not empty, then the user is prompted (asked) to enter a starting road and a starting cross street. Then the user is prompted to enter an ending road and an ending cross street.

The user entry for both starting and ending road's and starting and ending cross street's must be case insensitive. That is, Brunswick Street and BRunswIcK strEET must produce the same result.

The program then displays to the screen all the details of Tram stops (the complete record) that match between the starting road, starting cross street, and the ending road, ending cross street, as entered by the user. This includes the starting and ending road/cross street stops.

To do this, your program will need to read the entire contents of the file, line by line. Unlike Task 1, there may be more than one Tram stop that meets the starting/ending road and cross street requirements.

If there is no matching start road/start cross street, as entered by the user, then an appropriate message is displayed to the screen.

If there is no matching ending road/ending cross street, as entered by the user, but there is a matching start road/start cross street, the program displays all the Tram stop records from the starting road/starting cross street to the end of file.

Then the program displays an appropriate message to indicate that it could not find the ending road/ending cross street.

Note the output format is different to Task 1, in particular, there needs to be " " around the values for the keys and the output needs to be on one line.

Some sample runs of the program are included below (user input is in bold): (Note that the sample runs do not necessarily show all the functionality required).

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write a java program called tramjava that firstly prompts
Reference No:- TGS02722008

Expected delivery within 24 Hours