Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

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

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

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

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 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