Write a method for reading in the sections of a track

Assignment Help JAVA Programming
Reference no: EM131044844

Goal: The goal of this assignment is to gain practical experience with procedural abstraction - how complex functionality can be broken up between different methods and different classes.

Task Overview: In brief, you will write a method for reading in the sections of a track from a file, and you will write a method for allocating routes to trains (so that they don't collide). More specifically, you must code method read from the TrackReader class and method allocate from the Allocator class that are available in the zip file that accompanies this handout, according to their specifications in those files.

You must complete these methods and classes as if other programmers were, at the same time, implementing classes that use it. Hence:

- Don't change the class names, specifications, or alter the method names, parameter types, return types, exceptions thrown or the packages to which the files belong.

- You are encouraged to use Java 8 SE API classes, but no third party libraries should be used. (It is not necessary, and makes marking hard.)Don't write any code that is operating-system specific (e.g. by hard-coding in newline characters etc.), since we will batch test your code on a Unix machine.

- Any new methods or fields that you add to TrackReader or Allocator must be private (i.e. don't change the specification of these classes.)

- Your source file should be written using ASCII characters only. Implement the classes as if other programmers are going to be using and maintaining them. Hence:

- Your code should follow accepted Java naming conventions, be consistently indented, readable, and use embedded whitespace consistently. Line length should not be over 80 characters. (Hint: if you are using Eclipse you might want to consider getting it to automatically format your code.)

- Any additional methods that you write, and fields that you introduce should be private to hide implementation details and protect invariants.

- Private methods that you write must be commented using preconditions and postconditions (require and ensures clauses). Informal description is OK.

- Fields and local variables (except for-loop variables) should have appropriate comments. Comments should also be used to describe any particularly tricky sections of code. However, you should also strive to make your code understandable without reference to comments; e.g. by choosing sensible method and variable names, and by coding in a straightforward way.

- Any exceptions that are created and thrown should have appropriate messages to help the user understand why the exception was thrown. This is particularly important for the read method in TrackReader, since if there is an error with the file format, then the user will want to know what is wrong with it when a FormatException is thrown. Each FormatException thrown should have a meaningful message that accurately describes the problem with the input file format, including the line of the file where the problem was detected. (You can create a new FormatException with a message using the constructor that takes a string parameter.)

- The methods that you have to write must be decomposed into a clear and not overly complicated solution, using private methods to prevent any individual method from doing too much. I recommend that you attempt to write loop invariants for all non-trivial while-loops in your code, but this is not compulsory. The Zip file for the assignment also includes some other code that you will need to compile your classes as well as some junit4 test classes to help you get started with testing your code. Do not modify any of the files in package railway other than TrackReader and Allocator, since we will test your code using our original versions of these other files. Do not add any new files that your code for these classes depends upon, since you won't submit them and we won't be testing your code using them. The JUnit4 test classes as provided in the package railway.test are not intended to be an exhaustive test for your code. Part of your task will be to expand on these tests to ensure that your code behaves as required by the javadoc comments. (not required to submit your test file TrackReaderTest.java.) We will test your code using our own extensive suite of JUnit test cases. (Once again, this is intended to mirror what happens in real life. You write your code according to the "spec", and test it, and then hand it over to other people ... who test and / or use it in ways that you may not have thought of.)

- More about the allocate method from the Allocator class: In this section we explain some of the terminology used in the specification of the allocate method.

- A route describes a path through a track. A route is a list of zero or more (non-null) segments.

- A segment, implemented as the class Segment from the railway package, is a part of route. A segment is located on one section of track, and it has a direction of travel along that section, and a first and last location that are on that section.

The direction of travel is specified with respect to the end-points of the section: one of the section end-points is designated as the departing end-point and the other as the approaching end-point. The direction of travel is away from the departing end-point towards the approaching end-point.

Let startOffset and endOffset be the offset of the segment's first location and last location (respectively) with respect to the departing end-point of the segment. We must have that startOffset < endOffset. For every offset x satisfying startOffset <= x <= endOffset, the segment of track contains every location at distance x from the segment's departing end-point.

The location at distance startOffset from the departing end-point is referred to as the first location on the segment, the location at distance startOffset+1 from the departing end-point is the second location on the segment, etc. The length of the segment is endOffset - startOffset, and it contains (1 + endOffset - startOffset) locations. Since startOffset < endOffset, this length must be greater than or equal to one.

Attachment:- assignment.zip

Verified Expert

The program was to define a Railway Track Allocation System. 1st part was to read the details of a track from a file and create it. 2nd part was to allocate route to trains such that they won't collide.

Reference no: EM131044844

Questions Cloud

What interest rate did the he receive on this investment : An investor was afraid that he would become like King Lear in his retirement and beg hospitality from his children, so he purchased grain "tithes," or shares in farm output, for 540 pounds. The tithes paid him 65 pounds per year for 31 years. What in..
Consider a neural network for a quantitative outcome : Suppose that the weights αm from the input to hidden layer are nearly zero. Show that the resulting model is nearly linear in the inputs.
Cards from an ordinary deck : Five-card stud is a poker game, in which a player is dealt 5 cards from an ordinary deck of 52 playing cards. How many distinct poker hands could be dealt?
What is the value at year seven of perpetual stream : Given an interest rate of 7.1 percent per year, what is the value at Year 7 of a perpetual stream of $3,850 payments that begin at Year 17?
Write a method for reading in the sections of a track : The goal of this assignment is to gain practical experience with procedural abstraction - how complex functionality can be broken up between different methods and different classes.
Discuss the concept of fair value : BAO2202 Financial Accounting Assignment. Required: Discuss the concept of fair value (AASB 13) and evaluate how it has either increased or decreased decision useful information for the users of financial statements (Use at least three research arti..
Consider a neural network for a k class outcome : If the network has no hidden layer, show that the model is equivalent to the multinomial logistic model described in Chapter 4.
Identify the current mission statement and short term goals : Identify the current mission statement, short term, and long term goals. Recommend potential additions/deletions to each. Strategic implications of organizational objectives, structure and processes.
A constant growth stock just paid a dividend : A constant growth stock just paid a dividend of $1.9 and has a growth rate of 4.6%. The required rate of return on the stock is 12.6%. The stock's dividend yield in the current year is _______%. (answer in two decimal numbers)

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  Implement a java program that generates the receipt

Create a Receipt class that could be used by an automobile parts store. Items to include as data members are receipt number date of purchase, customer number, customer name and address, customer phone number, item number, description, unit price, ..

  What would be classes of the following objects

What types of values do the following modules/methods return, and what type of arguments do they take?

  The fileiohelper class provides 2 class methods

1.int FileIOHelper.getNumberofStudents(String fileName): takes a String parameter which is the name of an input file in the format described above, and returns the number of students in the file

  Assignment related to java programming

Question 1: Write a java program to compute the squares of the numbers in the array list like 1, 2, 3, 4... up to 50. Question 2: Write a java program to compute the sum of numbers and average in the array list up to 50.

  Working with numeric variables

Create a Java program for the following application. (it is in the second chapter of my Intro to "Java Programming" book (Murach 4th Edition)It involves1. working with numeric variables2.using the System.out object to print output to console

  Create a class named blooddata

Create a class named BloodData that includes fields that hold a blood type (the four blood types are O, A, B, and AB) and an Rh factor

  Program that simulates the rolling of a single die1000 times

Write a program that simulates the rolling of a single die 1000 times. The program must use an array of size 6 and not 1000 to store the occurrences of each side or face on the six-sided die. The program should output the particular die face and the ..

  Die class that can hold an integer

Design a die class that can hold an integer from 1 to 6. use the dice class to create a dice game. in this game, the user chooses a number between 2 and 12 inclusive

  Outline a test plan for a substantial real-life system

Describe how you would approach the design and testing process to ensure success and quality in the result and where are the risks? How are you going to address them?

  Write java code to read integers from an input file

write java code to read integers from an input file and write only the odd numbers to an output file. the two file names will be provided on the command line as the input file followed by the output file.

  Convert the following expression to postfix

Convert the following expression to postfix. ( 5 * ( ( 9 * 8 ) + ( 7 * ( 4 + 6 ) ) ) )

  Develop a reservation system program for specific flights.

develop a reservation system program for specific flights. A customer should be able to select from one of four categories of seats on flights from RDU to any of at least three other destinations. Based on the user input of seat type and destination,..

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