代写COM160 Spring Semester 2023-4 The Assignment代做留学生Java程序
- 首页 >> Matlab编程COM160
Spring Semester 2023-4
The Assignment
Introduction
The purpose of this assignment is to give you an opportunity to demonstrate that you can write clear, reusable Java code that conforms to a specification.
20% of the total marks are for program style and the rest for sticking to the specification and getting it to work. That means you must submit a program that compiles and runs to get more than 20% so do not make any last minute changes to your code without checking it still compiles before you submit it.
If there are aspects of the tasks below you don’t understand you should email me to ask for clarification rather than guessing. I have already set up an FAQ page and will populate it as questions come in. It is a good idea to check this page just before you submit in case you have misunderstood something without being aware of it. If you ask me a question I have already answered on the FAQs I will refer you to that page in case there is, as well as the answer to your question, the answer to a question you should have asked had you thought of it.
You will have four tasks to perform. Each will build on the previous one and each will bring you more marks. So get the first task to work and save your program before going on to the second and so on. You can do this by uploading your work to Blackboard if you like because Blackboard is set up to accept an unlimited number of submissions. I will mark the last version submitted before the deadline. See below in the Submission section for what to do.
This is an individual assignment and the usual rules on use of unfair means apply so everyone’s work will compared by a plagiarism checker program.
The Scenario
You have created some experimental equipment to test the bubble point of different compounds, or rather you have created four different versions with various adaptions that may or may not make them more accurate. You need to test this set up to identify which, if any, of your experiments are reasonably accurate and which is the best. To do so you need to test all four versions with a sufficiently large number of compounds to ensure the results are statistically significant.
Your program will need to test the results against those derived using the Antonine Constant table provided by Dr Vernuccio. You have this both in pdf form. (to be readable) and as a class called Compound. You will not need to change Compound, it is just provided as a toolkit class.
To avoid any bias, your experiments will be run multiple times on compounds chosen at random and at random temperatures. The nature of your experiment is that the length of time it takes to run each experiment is variable but you can at least run all four variations of the experiment in parallel.
The outcome of this is that your experimental set up will be generating possibly thousands of results at an unpredictable speed and in an unpredictable order. You will need a program to analyse these result which are generated in the form of files of a single line of data.
You have been given a package called assignment to deal with this problem but some of the code has been omitted.
Getting Started
You have been given two zipped directories; assignment.zip and data.zip download them both and store them somewhere where you can find them again.
Create a new project on Netbeans. Its name doesn’t matter as long as it is not the same as an existing project. The file assignment.zip contains the incomplete assignment package; move it to your new project following the instructions for downloading and running my programs you should have been using all along. Move rather than copy it so there is no danger of you having two versions and uploading the wrong one to be marked.
Set your working directory in Netbeans. The file data.zip contains some experimental data to practice with but do not make this your working directory.
The package assignment has a class Assignment whose main method pro- cesses the raw results and turns them into something useful. It does this calling a method called processAllWaiting() that finds all the results files waiting to be read, saves their information in a Queue (see Week 8’s lectures) and deletes the actual files before processing the queue. Having done this the main method of Assignment asks the user if they want to wait in case more results turn up and, if the user says yes, waits and tries again. Otherwise it runs a method called findAndDisplayResult(). The length of the wait which can be adjusted, it is a constant in the class Assignment called WAIT.
You can run the class Assignment in the skeleton program you have been given but it won’t do much until you fill in the gaps in the code. There are four of gaps and each of them is worth a quarter of the marks for this assignment.
You can only change the four method bodies specified below, nothing else. This is part of the specification and if you ignore it you may get no marks at all. Tasks One and Two involve changing the bodies of two methods in the class Result and Tasks Three and Four involve changing the bodies of two methods in the class Analyser. All methods that throw any exceptions should throw them in the form of useful error messages using the MyException class provided. This
class has an extra constructor with the signature
public MyException (String s, Path file)
which you will probably find helpful.
Task One
The main method of Assignment calls processAllWaiting() in the class Analyser. This in turn calls findThoseWaiting() in the class Result. This method should
return a Queue (see Week 8’s lectures) of Result objects, one for each file in the working directory with a .csv suffix but currently returns an empty Queue. The first task involves replacing line 70 of the class Result by code that will find all the .csv files waiting to be read, create a Result object from each, add the new Result to the Queue and delete the actual file. To create a new Result object from a .csv file you should call another method in the Result class, newResultFrom(), which takes the Path of the .csv file as a paramenter. Currently this method just returns a null Result object because making it work is the next task but, as it stands, it can still be used to test your code for Task One.
The class Result has a test harness in the form of a main method. To test your code for Task One copy a few of the data files into your working directory and run the main method of Result . If it works the .csv files will have vanished and “Found and deleted X files” will be printed out where X is the number of data files you copied into your working directory.
If you do this task well and your code is clear, well laid out and readable you will get 25% of the marks.
Task Two
Task Two consists of replacing lines 56 and 57 of the Result class with code for the newResultFrom() method. This method should create and return a new Result object from the Path to a .csv file provided in the parameter. A result object contains two Strings, the name of the file and the single line message it contains.
So your program needs to open the file, read its contents and close it. That provides scope for plenty of Exceptions. The Assignment package contains a class called MyException with a couple of useful methods. The only exceptions your code should throw are MyExceptions with meaningful messages. This is part of the specification.
Once you have completed this task you can run the same test as for Task One but this time it will print out details of the result as well as a count of how many were deleted. So the output might look like this
Found and deleted 7 files The files turned into Result objects are: File Test3B . csv contained the line - 13, -5.968241637 File Test3C . csv contained the line - 12, 98.60689694 File Test3D . csv contained the line - 68, 30.48667518 File Test4A . csv contained the line - 67, 122.7385549 File Test4B . csv contained the line - 77, 116.4549648 File Test4C . csv contained the line - 13, -5.975078984 File Test4D . csv contained the line - 55, 71.44025553 |
If you do this task well and your code is clear, well laid out and readable you will get an additional 25% of the marks, so 50% in all.
Task Three
The method processAllWaiting() in the class Analyser calls, as well as the findThoseWaiting() method you modified for Task One, a method called processOne() in the Analyser class. This is the method you have to modify for Task Three; it processes results by summarizing them in a two dimensional array called totalScores.
The method called processOne() takes a Result as its parameter and scores its quality. Each Result contains a file name (which identifies the version of the tests, A to D, that generated it) and a String. The String contains two numbers separated by a comma; an integer (1-87) identifying the compound being tested by its position in the Antonine Compounds table and a real number which is what the test calculated as the compound’s bubble point at sea level. To score its quality the bubble point in the result has to be compared to the bubble point for the compound as determined by the Antonine constant table in the form of the Compound class. If the absolute difference is within 2% it scores 2, if it is within 5% it scores 1 and if it is further away it scores -4. You have been provided with a method (called score()) to work this out. The score for each result must then be recorded in to the array totalScores.
Not all compounds will be tested at all but those that have been tested will have been through all four test and will mostly have been tested many times. When everything has been analysed totalScores will contain the sum of the scores for each compound/test combination in the data files.
Like Result, the Analyser class has a test harness and if you run its main method it will provide you with some indication of whether you are on the right lines before you move on to the final task.
For Task Three you must replace line 47 in Analyser by your code for processOne() but change nothing else. If you do this task well and your pro- gram is clear, well laid out and readable you will get another 25% of the marks so upto 75% in total.
Task Four
For the final task you need to modify the body of the method findAndDisplayResult()
in the Analyser class. This method needs to sum the four columns of the totalScores matrix, work out which has the largest sum and print out the result.
Using all the data I provided the output will be
Test A - - 370 Test B - - 702 Test C - - 226 Test D - - -977 The best test was Test B |
but I will not necessarily test your programs with the same data although it will have the same format. The wording here is important. Your working code will be checked by a program so stick to wording and layout meticulously because computer marking is not as forgiving of typographical and spelling mistakes as human markers. In real life programs interact with other systems as result ignoring the specification can be a catastrophic error and in this exercise it can damage your marks.
If you replace line 38 in Analyser by your code for findAndDisplayResult() but change nothing else and do this task well with clear, well laid out and read- able Java you will get another 25% of the marks so upto 100% in total.
The package assignment contains five Java files but you don’t need to sumbit them all, you should only submit the file(s) you have changed. If you don’t get as far as Task Three you just need to upload Result.java. If you do Task Three and possibly Task Four you must include Analyser.java as well.
To upload your answer click on the Assignment Submission Point in Black- board and you will be able to choose the files you want to upload.
The easiest way to find these files is to navigate to the Netbeans directory you moved the original versions to. Do not submit anything else, in particular do not submit a directory in any form because its contents will not be marked. Don’t worry if the indention of your uploaded file looks wrong; that is an artefact of Blackboard but I will be marking the actual file.
You can submit your .java files as many times as you like and I will mark the last submission before the deadline but a submission must consist of the full set of files even if one is the same as an earlier version because Blackboard only gives me the last submission.
The deadline is 3pm on Friday 17th May.
I will stick to the rule that programs which don’t compile and run will get at most 20% because a program is an artefact designed to do a task and if it doesn’t do anything it is useless. However I will test compile everyone’s program straight after the deadline and I will allow students with compilation errors to resubmit once even though, normally, anything submitted after the deadline (except a late first submission) would be ignored. So check your email soon after the deadline.
You can ask for a small amount of help from the demonstrators at the practical classes but direct help will be limited to answering questions like “What does this error message mean?” not questions like “How do I answer this part?” . But if you have a problem you can recreate with one of the earlier exercises then you can certainly ask the demonstrators for help with that. You can also email me questions which, if they relate to what I amasking you to do, I will both reply to and put (anonymously) in the FAQs. My help is also limited because I will not answer “How do I do...” questions either. If I refuse to answer your question consider rephrasing it to refer to your solutions to the practical exercises because I will answer question about the exercises. But be careful about asking questions on line. In the past students have posted their solution on a website asking for help only to find they are accused of use of unfair means when someone else finds it and submits it as their own.