Write program that prompts user to enter an input file name

Assignment Help JAVA Programming
Reference no: EM131926533

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).

Reference no: EM131926533

Questions Cloud

Evaluate her 2015 financial performance : Income statement preparation On December 31, 2015, Cathy Chen, a self-employed terrified public accountant (CPA), completed.
Definitions and concepts : A) Define osmolality. B) What are the routes of body water loss, and how much is lost by each per day?
Identify which of these describe a nurse you know : Taking the competences of the AONE as a reference, identify which of these describe a nurse you know what qualities/competencies
Organisms over a relatively short period of time : We are focused on microevolution, or small changes within a species/population of organisms over a relatively short period of time.
Write program that prompts user to enter an input file name : Write a Java program called Tram.java that, firstly, prompts the user to enter an input file name. To practise reading from and writing to the console.
The importance of knowing the terms of bond issues : The importance of knowing the terms of bond issues, especially those relating to redemption, cannot be overemphasized.
Compare the gymnosperm life cycle : Combine your own diagrams and discussion to compare the gymnosperm life cycle (from unit 1) with the angiosperm life cycle.
Success of angiosperms in their life cycle : List and describe two unique evolutionary adaptations that have occurred to further the success of angiosperms in their life cycle.
What is the overnight mark to market profit : Now, assume that a call option on stock XYZ had a delta of 0.8. A market maker created a delta hedging position against a 100 short call position.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd