程序代写代做代考 Java scheme algorithm Microsoft Word – coursework1(JAVA)副本.docx

Microsoft Word – coursework1(JAVA)副本.docx

AE1PGP Coursework 1 – Stock Exchange

(Java)

Introduction

This is the first AE1PGP Coursework. It is worth 15% of the module

mark for this module. It requires you to use Object-Oriented

Programming and the Java programming language to design and write

a program that will function as a simple stock exchange, reading

orders from a file, processing them, and then writing the results

to another file. The deadline for this exercise is16:00 on

Wednesday 29th March 2017.

Read the entire document before beginning the exercise.

Version History

• Version 1.0 – 2017-03-15 – Original version.

• Version 1.1 – 2017-03-17 – Current version.

o Expanded description of limit price in the input file

format to mention the type of value.

o Modified offer compatibility description – should

also include limit prices which are equal; added rule

if multiple offers both have the same price and

timestamps.

Submission

You must submit a single zip file containing Java source code

file(s) containing all your code for this exercise. The zip file

must be named after your student ID number (ie, 6512345.zip) and

must not require any other files outside of the standard Java

platform classes which are always available. The first line of

each file should be a comment which contains your student ID number,

username, and full name, of the form:

// 6512345 zy12345 Joe Blogs

I will unzip your zip file into a new directory. Your program must

then compile without warnings or errors when I use the command

javac -d . *.java

This command will be run on our Linux server cs-linux.

As cs-linux runs Java 1.8, this means your program must compile

with Java 1.8 and must not use features or classes only available

in later versions of Java. If it does not compile, for any reason,

then you will lose all the marks for testing (common reasons in

the past have been submitting a file with the wrong filename, or

developing your solution on your personal computer without having

tested it on our Linux server). If the file compiles but has

warnings then you will lose some marks for not correcting the

warnings.

All your source files must be part of a package. That package

should be called unnc.cs.zy12345where zy12345 should be

replaced with your username. You must also have a public class

calledStockExchange (note the capitalization) in that package

which contains your program’s main method. Your program will

be run with the command (with the appropriate username

substituted),

java unnc.cs.zy12345.StockExchange inputfilename outputfilename

followed by any command-line arguments specified by the question.

If your program does not run with this command then you will lose

all testing marks as specified above.

The completed source code file should be uploaded to the

Coursework 1 Submission link on the AE1PGP Moodle page. You may

submit as many times as you wish before the deadline (the last

submission before the deadline will be used). After the deadline

has passed, if you have already submitted your exercise then you

will not be able to submit again. If you have not already submitted

then you will be allowed to submit once.

Remember that you can only access the Linux server from the

designated labs in SEB and SSB and that these labs are also heavily

booked for teaching. Do not wait until the last moment to submit

as you may find you cannot get into any of the rooms to access

your source code files. Not being able to access the machine due

to lack of planning is not an extenuating circumstance.

Late submissions: AE1PGP late submission policy

is different from the standard university policy. Late

submissions will lose 5 percentage points per hour, rounded up

to the next whole hour. This is to better represent the large

benefit a small amount of extra time can give at the end of a

programming exercise. No late submissions will be accepted more

than 24 hours after the exercise deadline. If you have extenuating

circumstances you should file them before the deadline.

Plagiarism

You should complete this coursework on your own. Anyone suspected

of plagiarism will be investigated and punished in accordance with

the university policy on plagiarism (see your student handbook

and the University Quality Manual). This may include a mark of

zero for this coursework.

You should write the source code required for this assignment

yourself. If you use code from other sources (books, web pages,

etc), you should use comments to acknowledge this (and marks will

be heavily adjusted down according to the amount of original

work).

You must not copy or share source code with other students. You

must not work together on your solution. You can informally talk

about higher-level ideas but not to a level of detail that would

allow you all to create the same source code.

Remember, it is quite easy for experienced lecturers to spot

plagiarism in source code. If you are having problems you should

ask questions rather then plagiarize. If you are not able to

complete the exercise then you should still submit your incomplete

program as that will still get you some of the marks for the parts

you have done (but make sure your incomplete solution compiles

and partially runs!).

Marking

The marking scheme will be as follows:

• Tests (50%): Your program should correctly implement the

task requirements. A number of tests will be run against your

program with different input data designed to test if this

is the case for each individual requirement. The tests

themselves are secret but general examples of the tests

might be:

o Does the program work with the example I/O in the

question?

o Does the program work with typical valid input?

o Does the program correctly deal with input around

boundary values?

o Does the program correctly deal with invalid values?

o Does the program handle errors with resources not

being available (eg, a filename being wrong)?

o Does the program output match the required format?

o Does the program perform any specified calculations

correctly?

As noted in the submission section, if your program does

not compile then you will lose all testing marks.

• Appropriate use of language features (40%): Your program

should use the appropriate Java language features in your

solution. You can use any language features or techniques

that you have seen in the course, or you have learned on your

own, as long as they are appropriate to your solution.

Examples of this might be:

o Is your program an Object-Oriented design?

o Are you making appropriate uses of classes,

inheritance, and interfaces?

o Are you dealing with errors appropriately?

o Are you using appropriate levels of access protection?

o If you have many similar values, are you using arrays

(or equivalent) instead of many individual variables?

Are you using appropriate Generics features to ensure

type-safety?

o Are you avoiding deprecated classes and methods?

o Have you broken your program down into separate

functions?

o Are all your function arguments being used?

o If your functions return values, are they being used?

o Are you using loops to avoid repeating many lines of

code?

o Are your if/switch statements making a difference, or

is the conditions always true or false making the

statement pointless?

• Source code formatting (10%): Your program should be

correctly formatted and easy to understand by a competent

Java programmer, using the standard shown in the lectures

and textbook. This includes, but is not limited to,

indentation, bracketing, class/variable/method naming, and

use of comments. See the lecture notes, and the example

programs for examples of correctly formatting programs.

Late Submissions: see submission section above.

Task

You have to write a program that will act as a stock exchange by

loading in a list of buy and sell offers from a file, and matching

them together to decide which offers execute with each other

according to an algorithm given below. Once it has processed all

the offers, it will write a log of the completed trades to another

file.

This program must be non-interactive. It should take two

command-line arguments. The first is the filename of the input

file of offers. The second is the filename that the output log

file of completed trades should be written to. If a file already

exists with that filename then it should be overwritten with the

new log file. If the program cannot read the input file or write

the output file, the program should print an error message either

“Cannot read input file” or “Cannot write output file” and exit

with return code 1. If it can read the input file but it’s format

is incorrect, it should print a different error message (see

later). The main method must be in a public class

called StockExchange class.

The input file lists all the offers that are being submitted to

the stock exchange. The format of the input file is as below:

• It is a text file, lines are separated by a single ‘

character.

• Blank lines should be ignored anywhere in the file.

• Each offer is one line of text.

• The format of each offer line is:

o A number representing the offer ID. The number will

be a non-negative number which can be represented as

a long value.

o A timestamp for the offer. The number will be a

non-negative number which can be represented as

a long value. Higher numbers represent later

offers.

o The character ‘B’ is it is a BUY offer, ‘S’ if it is

a sell order.

o The limit price for the offer. If it is a BUY order,

this represents the maximum price the offer is willing

to pay. If it is a SELL order, this represents the

minimum price the offer is willing to sell at. The

number will be a non-negative integer which can be

represented as an int value.

o Each of the fields above are separated by exactly 1

space character.

• If the format of the file is invalid, the program should

print the error message “Invalid input file” and exit with

code 2.

Your program must have a class called OfferFile that represents

the input file. This class should have a constructor which takes

1 argument, the input filename. It should also have a way for other

objects to access each offer in the file, one-by-one (for example,

by a nextOffer method, or using the Iterator design pattern).

Offers must be represented in your program by a class called Offer.

You should get instances of this class from OfferFile in some

way you have decided above. The class should encapsulate the data

for an individual offer.

Your program should also have a class called Exchange which

represents the stock exchange state and behaviour. The stock

exchange has two books, a BUY book and a SELL book, representing

all the waiting buy and sell offers which have not been completed.

Each book is sorted by price and time. The BUY book is ordered

by highest price first, the SELL book by lowest price first, as

described by priority below. The exchange should have a method

to take a new offer and try and execute that order. If it is

executed then it should store a Trade object representing a

record of the details of the trade. If it is not executed then

the new offer should be added to the appropriate waiting book in

the appropriate place.

A new offer executes if there is a compatible offer waiting

in the exchange. A offer is compatible if,

• For a new BUY offer, there is a SELL offer which has a limit

price equal or below the BUY offer limit price.

• For a new SELL offer, there is a BUY offer which has a limit

price equal or above the SELL offer limit price.

When 1 or more compatible offers exist, the waiting offer with

the highest priority is selected. Priority is ordered by limit

price (lowest compatible sell price is highest priority for

waiting SELL offers, highest compatible buy price is highest

priority for waiting BUY offers). If there are multiple offers

at the same price, the priority goes in order of the offer

timestamps. If the timestamps are also the same, the program can

arbitrarily select which offer to match.

When the offer executes, the price of the trade is equal to the

price of the waiting order it was matched with. For example, if

a BUY at 100 offer is received and there is a waiting SELL at 70

offer, then the trade executes at the price of 70 because that

is the price of the offer waiting on the book.

As noted above, when a trade executes, you should store

a Trade object representing details of the trade. Those details

should be the BUY order ID, the SELL order ID, and the price the

order actually executed at.

Once the program has gone through all the offers in the input file

and tried to execute them, it should write the output file

containing a log of all the trades that happened. The format of

the output file is as below:

• It is a text file, lines should be separated by a single ‘

character.

• Each completed trade is one line of text.

• Trades should appear in the file in the order they were

executed, with the first trade at the top of the file, the

last at the bottom of the file.

• The format of each trade line is:

o The BUY offer ID

o The SELL offer ID

o The price the trade was executed at.

o Each of the fields above are separated by exactly 1

space character.

Remember the submission notes at the top – each of your classes

and interfaces must be in a separate file, and written inside a

package with the correct name, and zipped together in the correct

way. You should submit all the classes specified above and any

others you decided to write in your solution. Your zip file should

not contain any “.java” files that are not part of your final

submission. If you are unsure you have done it correctly, try

downloading your submission from Moodle, unzipping it in a new

location, and trying to compile and run it with the given commands.

If you are still unsure, ask in the labs.

Example input/output

A proportion of test cases for marking will be released on 22nd

March 2016. You program should produce the expected answer for

all those test cases. There will be additional test cases used

in marking that are not released.

Hints

• You will need to learn about some new classes for this

exercise. The textbook and the Java API documentation will

be useful references.

• Where possible, use existing classes and interfaces in your

program. In particular, consider the classes and interfaces

in the Collections framework when you need to store multiple

objects.

• The task specifies some of the classes, constructors,

methods, and state that must exist for each class. You are

likely to need to add extra methods, state, and have other

classes as well in your solution. You may add whatever else

you need for your design, as long as you use the classes

specified in the task with it.

• Make sure not to accidentally store/write the buy and sell

offer IDs in the wrong order! You will need to test your

program with a variety of orders, calculating the output by

hand to compare against your program.

END

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *