Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92765192

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As