首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写CS5002、代做 java 设计程序
项目预算:
开发周期:
发布时间:
要求地区:
Assessed Exercise II
CS5002 Advanced Programming
• Deadline: 16:30 on 19th March 2024
• Contribution to final course mark: 25% • Solo or Group: Solo work
• Anticipated duration: 3 hours
Introduction
From the course Moodle page, download the files CommandRunner.java and SlowCalculator.java. The latter contains a class SlowCalculator implement- ing Runnable. Its constructor takes a number N as input and stores it. Method run performs a long, slow calculation on this number, then prints the result. You do not need to consider (or even understand) the mathematical details of what is being calculated!
In this exercise, you will write a class implementing the interface CommandRunner, that runs certain commands passed as strings. These are inputs from a user, requesting the calculation be performed for particular numbers. The inputs and outputs are read/written by a separate part of the program – you just have to use the passed string, and return a string.
As the calculation is slow, you will run it on background threads, so the user can continue to interact with the system while tasks are running. To take advantage of modern multi-core CPUs, the user may request several calculations be run in parallel. Each calculation will still run on one single thread – your goal is to let the user run multiple calculations in parallel, not to make the individual calculations faster.
Task
You will write a class called Solution that implements the CommandRunner interface. The runCommand method of this class will be passed a string, cor- responding to a command the user entered. It should perform the relevant command (see below), and return the specified output string. You should not modify the interface CommandRunner in any way. Your Solution class should have a public constructor taking no parameters.
1
The following table lists the commands the user may enter (i.e. that may be passed as the command argument to your Solution.runCommand method), and the required behaviour of your runCommand method (note N and M are long integers chosen by the user):
start N
cancel N
running
get N
after N M
finish
abort
start calculating with input N, by calling SlowCalculator.run on a new thread; imme- diately return the message “started N”
immediately cancel the calculation with input N that is currently running (do nothing if it already completed or if it was never started); when it has stopped (which should be within 0.1s) return mes- sage “cancelled N”
return a message indicating the total number of calculations currently running (i.e. exclud- ing those already completed/cancelled), and their inputs N (in any order), in the form “3 calculations running: 83476 1000 176544”. If no calculations are running, return the string “no calculations running”.
if the calculation for N is finished, return message “result is M” where M is the integer result; if the calculation is not yet finished, return message “calculating”. If the calculation was started but already cancelled, return message “cancelled”
assuming the calculation for N is already running, schedule the calculation for M to start when that for N finishes (or is cancelled). Return the message “M will start after N” immediately (without wait- ing for either calculation). The calculation for M should not appear in running until it is actually run- ning (i.e. N has completed)
wait for all calculations previously requested by the user (including those scheduled with after) to fin- ish, and then after they are all completed, return message “finished”
immediately stop all running calculations (and dis- card any scheduled using after), and then when they are stopped (which should be within 0.1s) re- turn message “aborted”
For any command not given above (including malformed commands, e.g. N is not an integer), the method should return message “Invalid command”.
2
Note that the provided code for SlowCalculator prints the answer at the end of run(). You must remove this print statement, and replace it with a suitable mechanism to return the result so your Solution class can retrieve it. You should not modify the mathematical calculations performed by either SlowCalculator.calculateNumFactors or SlowCalculator.isPrime, but you will need to add support for interruption. You may change other parts of this class if you want (e.g. adding new fields or constructor parameters). You must not change the names of the existing methods.
Here is an example of what should happen when your program runs; the highlighted lines are commands passed to runCommand, and the remaining lines
are the messages it returns:
start 10456060
started 10456060
running
1 calculations running: 10456060
get 10456060
result is 3
start 72345680
started 72345680
start 534912560
started 534912560
get 534912560
calculating
running
2 calculations running: 72345680 534912560
cancel 72345680
Cancelled 72345680
running
1 calculations running: 534912560
finish
finished
Notes
• We will not test on pathological inputs for which the behaviour is not defined, i.e. not specified above. Please do not ask questions about any special cases you may think of (e.g. starting a calculation that is already running, or cancelling a calculation scheduled with after but not yet started). It does not matter what your program does in such cases
• Do ensure you return “Invalid command” (as mentioned above) if you receive a command that is not of the required form (e.g. N is missing or not an integer, or a command is misspelt)
• Your program should not limit the number of calculations/threads that can be run in parallel
3
• Your program should not print any output directly, nor read from the console
• Do not use any deprecated methods, such as Thread.stop() (such meth- ods are typically deprecated because they are dangerous, and so it is bad practice to use them)
• Remember the goal of this exercise is not to make each individual calcu- lation parallel, but to run several independent calculations for different N in parallel!
Submission
• You must implement a class Solution in file Solution.java, inheriting from CommandRunner. Do not put your code in a Java package (i.e. do not use the package keyword in any files).
• You will submit a single .zip file (not a tar, or a rar, or anything else), named 1234567.zip where 1234567 is replaced by your 7-digit numeric student ID
• This .zip file shall contain no folders, (e.g. src/), but only the .java files containing your code, including SlowCalculator.java and Solution.java, and maybe others if you wish
• Do not include CommandRunner.java in your submission
• Do not include a main method anywhere
• Upload your .zip file to Moodle before the deadline!
Mark Scheme
Your submission will be marked out of 50 points, broken down as follows: • Code is provided in the correct form and compiles successfully [5]
• start, running, get and cancel commands work as expected [20] • finish and abort commands work as expected [15]
• after command works as expected [10]
If you do not follow the exercise specification precisely, you will lose marks (your submission will be processed by a computer program; it will assume you’ve followed the instructions).
4
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!