联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> Java编程Java编程

日期:2020-08-27 10:54

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 1 of 14

Department of Computer Science and Information Technology

La Trobe University

CSE1OOF Semester 2, 2020

Assignment Part A

Due Date: Tuesday, 25th August, at 12:00pm.

First and Final date for SUBMISSION Tuesday at 12:00pm

Delays caused by computer downtime cannot be accepted as a valid reason for a late

submission without penalty. Students must plan their work to allow for both scheduled and

unscheduled downtime. There are no days late or extensions on this assignment as

execution test marking will begin on Wednesday 26th August – in your normal lab

(Week 6)

This is an individual Assignment. You are not permitted to work as a Pair

Programming partnership or any other group when writing this assignment.

Copying, Plagiarism: Plagiarism is the submission of somebody else’s work in a manner

that gives the impression that the work is your own. The Department of Computer Science

and Information Technology treats academic misconduct seriously. When it is detected,

penalties are strictly imposed. Refer to the subject guide for further information and

strategies you can use to avoid a charge of academic misconduct.

Assessment Objectives:

? To practise using the String class. (Lecture/Workshop 2)

? To practise using if, if-else statements (Lecture 5 and 6, Lecture/Workshop 3)

? To practise reading from and writing to the console and reading from a text file.

Submission Details: Full instructions on how to submit electronic copies of your source

code files from your latcs8 account are given at the end. If you have not been able to

complete a program that compiles and executes containing all functionality, then you should

submit a program that compiles and executes with as much functionality as you have

completed. (You may comment out code that does not compile.)

Note you must submit electronic copies of your source code files using the submit

command on latcs8. Ensure you submit all required files, one file at a time. For example,

the file Ticket.java would be submitted with the command:

submit OOF Ticket.java

Do NOT use the LMS to submit your files, use latcs8 only

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 2 of 14

PLEASE NOTE: While you are free to develop the code for assignment on any operating system, your

solution must run on the latcs8 system.

Marking Scheme: This assignment is worth 10% of your final mark in this subject.

Implementation (Execution of code) 90%, explanation of code 10%

You may be required to attend a viva voce (verbal) assessment (to

be used as a weighting factor on the final mark).

Return of Mark sheets:

The face to face execution test marking through zoom in the lab (Week 6) constitutes a return

of the assignment mark, subject to the conditions on page 10.

Please note carefully:

The submit server will close at 12:00 pm on Tuesday Aug 25th

After the submit server has closed, NO assignments can be accepted.

Please make sure that you have submitted all your assignment files

before the submit server closes. (see page 10)

There can be NO extensions or exceptions.

Your assignment will be marked in your normal lab, starting week 6,

Wednesday Aug 26th.

You must attend the lab you have signed up for on the allocate plus

to have your assignment marked. If you have not signed up for a lab

yet, your assignment will not be marked, and it will be awarded

0. Non-attendance at the week 6 lab you have signed up for will

also result in your assignment being awarded 0, except as detailed

below.

If you cannot attend the lab you have signed up for, please email me

(r.kalaria@latrobe.edu.au) to arrange another time.

Marking scheme:

90% for the code executing correctly

10%, you will be asked to explain (and / or alter) parts of your code.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 3 of 14

Using code not taught in OOF - READ THIS

Please also note carefully that whilst we encourage innovation and exploring java beyond

what has been presented in the subject to date, above all, we encourage understanding.

All of the Tasks that follow can be solved using techniques that have been presented in

lectures, lecture / workshops and labs so far.

These are the techniques and knowledge that we will later be examining in the Real Time

Test and the exam.

Code and techniques that are outside the material presented will not be examined, of course.

You are free to solve the Tasks below in any way, with one exception and one condition.

Any assignment that uses code that is outside what has been presented to this point must be

fully explained at the marking execution test. Not being able to fully explain code outside

what has been presented in the subject so far will result in the assignment being awarded

a mark of 0, regardless of the correctness of the program.

Submitting an assignment with code outside what has been presented so far and not

attending the marking execution test will result in an automatic mark of 0, regardless of the

correctness of the submission.

An example would be the split() method in the String class. The reason being that this

method returns an array and we haven't studied arrays yet. So using the split() method

would require you to be prepared to explain to the marker how arrays worked in Java.

Another example is the use of BufferedReader and Integer.parseInt( ).

BufferedReader is not being taught at all, so it won't be on the exam and

Integer.parseInt( ) we touch only briefly, but not yet. Double.parseDouble( ) is not

to be used.

How this assignment is marked

All assignments in OOF are marked, face to face through zoom, in the

lab, in an execution test. This means that we mark running code. Your

code must compile and display a result to the screen. Regrettably, we

don't have the time or resources to look at code. The smallest amount

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 4 of 14

of code that produces and displays a correct result will gain more

marks than lots of code that doesn't compile, run or display something

to the screen.

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:

Cross Street[Stop Number[Tracker Id[Road[Suburb

where

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

Road is the name of the road along which the tram travels. This is a String

(text) and may contain more than one word. The Road is followed by a '['

character, there are no spaces between the end of the Road, the '[' and the

start of the Suburb

Suburb is the name of the suburb through which the tram is travelling at the

location indicated by the information in the first part of the record.

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

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

Southern Cross Station[1[3501[Spencer Street[Melbourne

William Street[3[3503[Collins Street[Melbourne

Elizabeth Street[5[3505[Collins Street[Melbourne

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.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 5 of 14

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 Tram Tracker Id.

The program then reads through the file. If a matching Tram Tracker Id 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.

Tram Tracker Id'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: a.dat

Enter tram tracker id: 1371

Tracker ID: 1371

Stop number: 31

Road: St Georges Road

Cross Street: Gadd Street

Suburb: Northcote

> java Tram

Enter file name: a.dat

Enter tram tracker id: 4433

That tracker id was not found.

> java Tram

Enter file name: e.dat

"e.dat" is an empty file

An example input file (a.dat) for Task 1, 2 and 3 may be copied from the same folder as

assignment specification

Task 2 – StreetA.java

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

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 6 of 14

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 road and a suburb.

The user entry for road and suburb 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 the road and the suburb, as entered by the user.

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 road and suburb

requirements.

If there are no Tram stops with the road and the suburb, as entered by the user, then an

appropriate message is displayed to the screen.

Note the output format is different to Task 1, in particular, there needs to be " " around

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)

Note: the output for each record is shown across 2 lines, just to fit onto the page, your output

on screen will be one line per record.

> java Street

Enter file name >> a.dat

Enter road name >> Brunswick Street

Enter suburb >> Fitzroy

"Suburb": Fitzroy "road": Brunswick Street "cross street": Gertrude

Street "stop": 13 "tracker id": 1353

"Suburb": Fitzroy "road": Brunswick Street "cross street": King

William Street "stop": 14 "tracker id": 1354

"Suburb": Fitzroy "road": Brunswick Street "cross street": St David

Street "stop": 15 "tracker id": 1355

"Suburb": Fitzroy "road": Brunswick Street "cross street": Jonhston

Street "stop": 16 "tracker id": 1356

"Suburb": Fitzroy "road": Brunswick Street "cross street": Leicester

Street "stop": 17 "tracker id": 1357

> java Street

Enter file name >> e.dat

"e.dat" is an empty file

> java Street

Enter file name >> a.dat

Enter road name >> Brunswick Street

Enter suburb >> Reservoir

No information for the requested road and suburb was found

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 7 of 14

Task 3 – StreetB.java

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

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)

Note: the output for each record is shown across 2 lines, just to fit onto the page, your output

on screen will be one line per record.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 8 of 14

> java Street

Enter file name >> a.dat

Enter start road >> miller street

Enter start cross street >> st georges road

Enter end road >> gilbert ROad

Enter end cross street >> oakOVER road

Stop Number: "35" Cross Street: "St Georges Road" Road: "Miller

Street" Suburb: "Preston" Tracker Id: "1010"

Stop Number: "36" Cross Street: "Devon Street" Road: "Miller Street"

Suburb: "Preston" Tracker Id: "1376"

Stop Number: "37" Cross Street: "Miller Street Shopping Centre"

Road: "Gilbert Road" Suburb: "Preston" Tracker Id: "1377"

Stop Number: "38" Cross Street: "Oakover Road" Road: "Gilbert Road"

Suburb: "Preston" Tracker Id: "1378"

> java Street

Enter file name >> a.dat

Enter start road >> gilbert road

Enter start cross street >> murray road

Enter end road >> st georges road

Enter end cross street >> part street

Stop Number: "43" Cross Street: "Murray Road" Road: "Gilbert Road"

Suburb: "Preston" Tracker Id: "1383"

Stop Number: "44" Cross Street: "Cooper Street" Road: "Gilbert Road"

Suburb: "Preston" Tracker Id: "1384"

Stop Number: "45" Cross Street: "Jacka Street" Road: "Gilbert Road"

Suburb: "Preston" Tracker Id: "1385"

Stop Number: "46" Cross Street: "McNamara Street" Road: "Gilbert

Road" Suburb: "Preston" Tracker Id: "1386"

Stop Number: "47" Cross Street: "Regent Street" Road: "Gilbert Road"

Suburb: "Preston" Tracker Id: "1387"

No information was found for the ending road and/or ending cross

street

> java Street

Enter file name >> e.dat

The file "e.dat" is an empty file, closing the program

> java Street

Enter file name >> a.dat

Enter start road >> plenty road

Enter start cross street >> dunne street

Enter end road >> collins street

Enter end cross street >> elizabeth street

No information was found for the starting road and/or starting cross

street

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 9 of 14

Task 4 – Ticket.java

Write a Java program called Ticket.java that prompts (asks) the user to enter a ticket.

The format of a valid ticket is D[D][D]CD[D][D]

where D means a required digit and C means a required character. [D] means the digit at this

position is optional.

The idea of this ticket is that, as a String, it will contain 2 integers and an operation between

the 2 integers.

The required character is the operation. The required character can only be one of 'A', 'a',

'S', 's', 'M', 'm', 'D' or 'd'.

'A' or 'a' is the operation addition.

'S' or 's' is the operation subtraction.

'M' or 'm' is the operation multiplication.

'D' or 'd' is the operation division.

So, the final result of a valid ticket will be an integer.

Please note, input must be a single String. Any program that does not take in the input

in a single String will be awarded 0, regardless of the correctness of the program.

Based on the above, some examples of valid tickets could be

2m3

12A4

68D32

123s101

3m267

114d7

Given the specification above, any ticket entered by the user that has a length of less than 3

or greater than 7, must automatically be invalid.

If the ticket is outside the minimum or maximum lengths, an appropriate message must be

displayed to the screen and no further processing is done.

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, doesn't start with valid digit(s), doesn't have a valid character in the right

required place, doesn't have an optional digit(s) in the right place. Part of your task is to list

all the conditions that make a ticket invalid and write code to cover those cases.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 10 of 14

User input that should be accepted in both upper and lower case. That is the ticket input

must be case insensitive.

Everything below assumes that you have already checked that the user entered ticket

is a valid length.

Every ticket must start with at least one digit, but have no more than a total of three digits

before the required character, followed by at least one digit and no more than a total of three

digits.

As we are not allowed to use any methods from the Integer or Double class, we need to

convert digit characters in the String into a single integer (int). We need to do this for both

the first and second integer in the String.

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

When we enter a digit from the keyboard, what we are really entering is the character for that

digit.

For example, if we enter 3, what we are really entering is the character '3'

If we look up the ASCII/Unicode value for the character '3', we see that it is 51, not 3 We can

convert digits as characters to integers by subtracting the character '0'

In ASCII/Unicode, then '3' - '0' = 51 - 48 = 3

As we do this conversion, we can start to assemble the final integer result.

We need two local int variables, one to store the first number and one to store the second

number. There are other local variables that you can use to keep track of if the processing of

the String is still valid, how many digits you've already counted, what index you are up to in

the String. Feel free to use any local variables you like.

Lecture/Workshop 2 covered how to get a single character from a String

If the first character is not a digit, then the program displays an appropriate message to the

screen and no more processing is done.

If the first character is a digit, then it is converted to an integer and added to the first number

local variable.

The next character can be either a character, one of 'A', 'a', 'S', 's', 'D', 'd', 'M' or 'm', OR

another digit.

If the next character is a digit, convert the character into an integer, multiply the current

number local variable by 10 and then add the digit you just converted.

You also need to keep a count of the number of digits that you are converting. Remember

the maximum number of digits in a row is 3. There can be 1, 2 or 3 digits, but no more than 3.

If there are more than 3 digits in a row, then the program displays an appropriate error

message and no more processing is done.

If the first group of digits are valid, that is, they make an integer, then it is time to check that

they are followed by a character, which, as shown above, must be one of 'A', 'a', 'S', 's', 'D',

'd', 'M' or 'm'.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 11 of 14

If the character is not of these, then the program displays an appropriate error message and

no more processing is done.

If the character is one of the allowed characters, then save that into a char local variable,

we will need that at the end of the program if the second number proves to be valid.

Now, obtaining the start of the second number is just a little bit harder.

We really need to know the index in the Ticket String of the first digit after the operation

character.

Recall that the first number may consist of 1, 2, or 3 digits.

It might be an idea to keep an index local variable to let you know where you are up to in the

Ticket String.

That way, you can use the value of the index variable to get the next digit after the operation

character.

Apart from this, getting the second number is a bit easier because we only have to consider

that there must be a maximum of 3 digits after the operation character.

Take the digit(s) one be one and assign them to the second local int number variable.

If one of the characters is not a digit, or there are more than 3 digits/characters after the

operation character, then the program displays an appropriate error message and no more

processing is done.

If we get all the way to the end of the Ticket String and everything is still valid, then we can

finally display the result.

If the operation character is 'A' or 'a', then the 2 numbers are added together

If the operation character is 'S' or 's', then the second number is subtracted from the first

number.

If the operation character is 'M' or 'm', then the 2 numbers are multiplied together.

If the operation character is 'D' or 'd', then the first number is divided by the second

number.

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 3 and 7 inclusive,

then the Ticket is invalid, nothing further needs to be done except to display the appropriate

error message.

If the length is correct, solve the problem assuming that the user enters a correct set of digits

and the operation character. Just one digit, one operation character followed by one digit.

Gradually extend the program to solve the problem for the user entering 2 digits, the

operation character then another digit. Then 2 digits, the operation character, followed by 2

digits and so on. Keep doing this until your program can deal with 3 digits, the operation

character then 3 digits.

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 12 of 14

So far your program is working for correct inputs, this is a good start.

Now start working on the program so that it can take a variable number of digits in the first

and second numbers. Say 2 digits for the first number and just 1 digit for the second number.

Then, say, 1 digit for the first number and 2 digits for the second number. Keep going through

the combinations, "eating the dragon in little bits"

Once all this is 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.

Remember that it is better to have some parts of the program working correctly than

none of the program compiling.

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.

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

> java Ticket

Enter ticket >> 1

Not a valid ticket, minimum length of a valid ticket is 3

> java Ticket

Enter ticket >> 123456789

Not a valid ticket, maximum length of a valid ticket is 7

> java Ticket

Enter ticket >> 2m3

2*3=6

> java Ticket

Enter ticket >> 44s15

44 - 15 = 29

> java Ticket

Enter ticket >> 120A304

120 + 304 = 424

> java Ticket

Enter ticket >> 12d5

12 / 5 = 2

OOF Assignment Part A - due: 12:00 pm Tue 25th Aug this is the first and final hand in date p. 13 of 14

> java Ticket

Enter ticket >> 2S26

2 - 26 = -24

> java Ticket

Enter ticket >> 100m4

100 * 4 = 400

> java Ticket

Enter ticket >> 1234d23

Fourth character, after three digits, must be one of 'm', 'd', 's'

or 'a'

> java Ticket

Enter ticket >> 12x45

Third character must be a digit or one of 'm', 'd', 's' or 'a'

> java Ticket

Enter ticket >> 1a2345

There are more than 3 digits/characters after the operation

java Ticket

Enter ticket >> 12d34f

Character at position 6 must be a digit

> java Ticket

Enter ticket >> a22m55

The first character must be a digit

See Lecture/Workshop 2 for revision on the String class and Lectures 5 and 6 and

Lecture/Workshop 3 for if, if-else statements.

There are quite a number of different conditions to cover in this task. It might help to "think

first, code second". One way to do this is write out a list of test cases. Try to think of all the

different ways that this Ticket can be entered and write a test case. That way, when you

actually come to write your program, you will have a definite goal to aim at, write the code,

run the test case and check that the actual output is what you expected.

OOF Assignment Part A - due: 12:00 pm Tues 25th Aug this is the first and final hand in date 14 of 14

Electronic Submission of the Source Code

? Submit all the Java files that you have developed in the tasks above.

? The code has to run under Unix on the latcs8 machine.

? You submit your files from your latcs8 account. Make sure you are in the same directory

as the files you are submitting. Submit each file separately using the submit command.

submit OOF Tram.java

submit OOF StreetA.java

submit OOF StreetB.java

submit OOF Ticket.java

After submitting the files, you can run the following command that lists the files submitted

from your account:

verify

You can submit the same filename as many times as you like before the assignment

deadline; the previously submitted copy will be replaced by the latest one.

Please make sure that you have read page 2 about the submission close off date and

time and the compulsory requirement to attend the execution test in Week 6

Failure to do both of these things will result in your assignment be awarded a mark of

0, regardless of the correctness of the program.

Execution test marks are provisional and subject to final plagiarism checks and

checks on the compliance of your code to this assignment document.

As such final assignment marks may be lower or withdrawn completely.

Final, final notes

Don't let anyone look at your code and definitely don't give anyone a copy of your code. The

plagiarism checker will pick up that the assignments are the same and you will both get 0 (it

doesn't matter if you can explain all your code).

And a final, final, final note, "eat the dragon in little bits". Do a little bit every night; before you

know it you will be finished. The assignment is marked with running code, so you are better to

have 1 or 2 Tasks completed that actually compile and run, rather than a whole lot of code

that doesn't compile.

The execution test is done on latcs8 so please make sure that your

code runs on latcs8 before you submit.


版权所有:编程辅导网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。