Java program- displays all the details of stations

Assignment Help JAVA Programming
Reference no: EM131004107

Task 1- Codes.java

Write a Java program called codes. 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

Station name: Station code Line:distance

where
Station name is the unique name of a railway station. This is a String (text) and may contain more than 0110 word. This name is followed by a ':' character, there are no spaces.

Station code is a 3 character code that identifies the station. This code is also unique and is followed by a ':' character, there are no spaces.

Line is the name of railway line with which the Station name is associated. This is a String (text) and may be more than one word, followed by a ':' character, there are no spaces.

Distance is the distance in kilometres from an arbitrary central point. The format of this distance is always dd.dd, meaning that if the distance is less than 10 kms, a 0 is placed at the start of the distance, for example 05.67

There are always 2 digits to the left of the decimal point, then the decimal point, then 2 more digits to the right of the decimal point.

No distances are greater than 99.99 kms

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

Preston: PRE: South Morang:12.47
Showgrounds: SGS: Flemington Racecourse:05.70
South Morang: SMG: South Morang:25.99

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 station name. The program then reads through the file. If a matching station name is found in the file, all the information for that station is displayed to the screen. The order of display is shown in the example runs below. Note that the information from the file must be enclosed in " ", except the distance.

Station names are unique in the file, so there will be at most only one match. User entered Station names must be case insensitive, that is, any combination of uppercase and lowercase letters must give the same result.

If the entire contents of the file has been read and no match is found then an 10 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 Codas
Enter file, name, >> stationsMaster.txt
Enter station name >>, Keen Park
Station code: "KPK" name: "Keon Park"
distance: 17.54 kms, is on the "South Morang" line

> java Codes
Enter file name >> stationsMaster.txt
Enter station name >> Bundoora
No information was found for station "Bundoora"

> java Codes
Enter file name >> e dat
e.dat is an empty file

An example input file for Task 1 and 2 may be copied from the csilib area

cp /home/student/csilib/cseloof/assignA/s.dat .

Task 2 - Stations.java

Write a Java program called stations.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 distance (double).

The program then displays to the screen all the details of Stations (the complete record) of all Stations that are less than or equal to the distance entered by the user.

To do this, your program will need to read the entire contents of the, line by line. Unlike Task 1, there may be more than one Station less than or equal to the user entered distance.

If there are no Stations less than or equal to the distance entered by the user, then an appropriate message is displayed to the screen.

Your program must work with any input file in the correct format. Also, do not assume Input file has a Station at distance 0.0 km or any minimum distance i or example, the input file may contain only Stations that are more than 15.0 kilometres distance and the user may request all Stations less than 8.5 kilometres. In that case there would be no matches.

Your program needs to convert the distance in the input file line into a double. The use of Double.parseDouble is not allowed for this Task (using Double . parseDouble will result in this Task being awarded 0, regardless of the correctness of the result).

This assignment is to consolidate the String class and basic selection (if, if - else, switch)

Consider that when we enter 3 what we are really entering is the character '3' with ASCII/Unicode number 51. We need to convert the character 3 to the integer 3 by subtracting character '0'.

Given that the format of the distance is fixed in the input String, this allows us to assemble the double from the String
As mentioned above the characters are converted to digits by subtracting '0'

If the first digit is multiplied by 10 and added to the second converted digit, we have assembled the number part on the left of the decimal point.

If the third converted digit is divided by 10.0 then added to the first 2, we have the total up to the first decimal place. The fourth converted digit is divided by 100.0 and added to the total, then we have assembled the distance as a double.

Once we have the distance as a double then, of course, we can compare this figure with the double entered by the user and either display the file line if it meets the requirements, or move on to the next line and do the same thing, until the end of file is reached.

Note the output format is slightly different to Task 1

As a final note on this question, consider how you could get your program to only print the heading (Stations within distance kms) if there is at least one Station that meets the distance
requirement.

Task 3 - Ticket.java

Write a Java program called Ticket.java that prompts (asks) the user to enter a ticket number. The format of a valid ticket is [C]DD.DDD[D]

where D = a required digit and . is the required decimal point.

(C] means that the character at this position is optional and [D] means the digit at this position is optional.

The DD.DD represents the base price of a ticket. As in Task 2, this must be converted from characters into a double. Since the Ticket may have a character, it is necessary to take in the input as a String.

The cost of the ticket is the base price multiplied by 0.25.

The last required digit at the end of the basic user entered ticket can be either a 1 or a 2. If this digit is 1, then there is no change to the cost of the ticket. If this digit is 2 then the final cost is the basic cost increased by 15% (This is the case where there is no optional extra digit, if the optional extra digit is present, then the next paragraph below applies, not this paragraph)

If there are 2 digits at the end of the Ticket (the required digit plus the extra optional digit) then these 2 digits must be 12 in that order. If the 2 digits are 12 then the basic cost of the ticket is increased by 10%

If there is an optional character at the start of the Ticket, that character can only be one of 'J', 'P' or 'R'

If the optional character is 'J', then the final cost of the Ticket (after working out the basic cost and applying the modifier for the last digit or digits, if applicable) is reduced by 33%

If the optional character is 'P', then the final cost of the Ticket (after working out the basic cost and applying the modifier for the last digit or digits, if applicable) is reduced by 10%

If the optional character is 'R', then the final cost of the Ticket (after working out the basic cost and applying the modifier for the last digit or digits, if applicable) is reduced by 20%

So an example of a valid ticket could be: r45.7812

The user may enter a ticket String of any length. The valid length of a ticket is between 6 and 8 depending on the conditions above. Any ticket that is not in this length range is automatically invalid. A ticket that is invalid for any reason will result in a message being displayed to the screen saying that the ticket is invalid, and no processing will be done with that ticket. This includes not showing any cost.

There are many reasons why a user Ticket may be invalid, even if it is within the correct length range.

Every effort should be made to give the exact reason why the ticket is invalid. For example, wrong length, starts with an invalid character, does not have digits and the decimal point in the correct order, the end required digit is not 1 or 2, if there are 2 digits at the end (after the double) thy are not 12 in that order. These are not the only reasons why a ticket is invalid, pad of your task is to list all the conditions that make at ticket invalid and write code to cover those cases.

User input that has the optional character at the beginning should be accepted in both upper and lower case.

At first, this Task can seem quite complex. Here is a suggested strategy to break the problem down into smaller parts, to "eat the dragon in little bits".

Start by checking the length of the user input. If the length is not between 6 and 8 inclusive, then the Ticket is invalid, nothing further needs to be done except to display the appropriate error message. Note: assume that the user enters a 0 in the first position of the double if the double is less than 10.0, in a valid ticket.

If the length is correct, solve the problem assuming that the user enters a correct set of just digits, that is, the double and just one digit at the end.

Once you have this working correctly, solve the problem assuming the user correctly enters just digits, that is, the double, the required last digit and the optional extra digit, in the correct format.

Then extend the program to solve the problem for the user entering a correct optional character at the start of the Ticket, followed by the double, the required last digit and the optional digit.

Once these are working, then start working on testing for user input errors and build up your program bit by bit to detect these errors and display the appropriate error messages.

Note that the result, if valid, must have a $ sign before the amount.

Some sample runs of the program are shown below (user input is in bold):

NOTE: the samples DO NOT cover all of reasons a ticket can be invalid, that is, they do not cover all test cases. Identifying and covering all of the cases is part of your

Task.

The samples do not always display appropriate invalid messages in most cases, your assignment submission will display the appropriate messages.

> java Ticket
Enter ticket >> 10.001
The cost of the ticket 10.001 is $2.5

> Java Ticket
Enter ticket >> 100001
Invalid ticket, must be a at third position

Note: System. exit () is not be used anywhere in any of the Tasks. (Marks will be deducted if it is used anywhere in this assignment.)

Reference no: EM131004107

Questions Cloud

Postretirement commitments retirement restoration plan : The Retirement Restoration Plan provides death benefits and supplemental income payments for senior executives after retirement. The Company recognized expense of $5.2 million in 2006, $6.4 million in 2005 and $7.1 million in 2004.
When is a profitability index used : How can we compare projects in the case where they have different life-spans?
Consolidated statement of earnings of anonymous corporation : The consolidated statement of earnings of Anonymous Corporation for the year ended December 31, 2007, is as follows:
How would you resolve this ethical dilemma : Using the theories of ethics presented in this module, how would you resolve this ethical dilemma? Include in your response how this issue might be addressed according to either utilitarianism or Kantian ethics. Cite correctly the information in t..
Java program- displays all the details of stations : Write a Java program called codes. 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.
Share a key clip or moment of reflection : Could you please share a key clip or moment of reflection you think will generate some discussion; this must not be a ready-made preview for the film. It must be a relative "clip" to demonstrate a point from the same movies " the mask you live in"
Plot the marginal revenue per increase in the subsidy : Rice farmers find that for each $.05 increase in the gov- ernment mandated price, each farmer's revenues increase by $50,000.The lobbying cost per farmer for each $.05 increment in price support is increasing, as illustrated in the table below, be..
What challenges does the organization face : What challenges does the organization face? Explain why these challenges have arisen. Again, think about the leadership frameworks and their characteristics, such as: Cultural issues and Funding issues
Determine which of the costing systems best for your company : Develop a list of inputs along with their associated costs, such as labor, materials, and overhead. You can research this information, make it up, or do a combination of both. Be specific as to costs.

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