INFS1609辅导、辅导CS/O 、讲解CS/O设计、辅导CS/O开发,辅导CS/OS编程
- 首页 >> OS编程UNSW Business School
School of Information Systems and
Technology Management
INFS1609 Assignment 2 (10%)
(Updated 04 September 2018)
Assignment Design
§ This assignment is to be undertaken as an individual assignment
§ This assignment is graded upon 10 marks and counts for 10% of your Overall Marks for
this course
§ The assignment is due on Friday September 28, 2018, by 1200hrs (noon)
§ The assignment must be submitted electronically via Ed > Assessments
§ There are three questions in total for this assignment. For each question, you will need to
submit one Java file via Ed > Assessments
§ Test cases might be used to do a first-round marking of your code. You should try to run
your program on Ed to check if they pass the test cases. Test run your code as early as
possible because you might need to make changes to your code.
§ Please use the Ed discussion forum to discuss any issues related to this assignment.
§ The readability of your code is one of the marking criteria. You should take care of your
coding style and include comments in your code (wherever appropriate) to help explain it
Please make sure you have read the information about UNSW Business School protocols,
University policies, student responsibilities and education quality and support on your Course
Outline: https://www.business.unsw.edu.au/degrees-courses/courseoutlines/archives/INFS1609-2018-S2#policies
If you have any questions about interpreting the assignment and its requirements, please
make use of the LICs consultation sessions. To avoid confusion and misunderstanding, we
will not be answering assignment-related questions over email.
2
business.unsw.edu.au
Assignment Questions
Part A: Conversions (6%)
Question 1 (3%): 24 Hour Time
Your MGMT1001 tutor approaches you after class one day and confesses that they are not
very familiar with 24-hour time. They are worried that one day they may misread the scheduled
time of their tutorial and show up late to teach their class. You decide to take this opportunity
to brush up on your Java programming skills and create a program that can help them convert
times between the 12-hour and 24-hour formats.
Write a program that will convert between 12-hour time and 24-hour time, and vice versa.
Your program should ask the user if they wish to convert from 12-hour time to 24-hour time,
or from 24-hour time to 12-hour time. Depending on their input, your program should call the
appropriate method which handles the conversion and returns the result to the main method.
The input of your program should be:
The user’s choice (12-hour à 24-hour, or 24-hour à 12-hour) on one line.
The time to be converted on the next line.
The output of your program should be:
The converted time in the alternate time format.
Below are some test data that may be used to test your code:
Sample Inputs Sample Outputs
12:00PM 1200
3:45PM 1545
2359 11:59PM
0956 9:56AM
1:00AM 0100
9:56AM 956
3
business.unsw.edu.au
Sample Runs
The sample runs below show the expected execution of the program (user’s input in blue;
essential output shown in bold purple).
Sample Run #1
Enter your input time format: 12hr
Enter the time: 12:00PM
12:00PM is 1200
Sample Run #2
Enter your input time format: 12hr
Enter the time: 3:45AM
3:45AM is 0345
Sample Run #3
Enter your input time format: 24hr
Enter the time: 2359
2359 is 11:59PM
Sample Run #4
Enter your input time format: 24hr
Enter the time: 0956
0956 is 9:56AM
4
business.unsw.edu.au
Question 2 (3%): I, for one, like Roman Numerals!
Inspired by your idea to convert between 12-hour and 24-hour time, you turn your attention to
something else that has confused you over the years: Roman numerals. Reading them was
difficult because of the way the numbers came together. You decide to refresh yourself on the
numerals and rules.
Roman Numeral Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
Rules:
1. When a symbol appears after a larger (or equal) symbol, it is added.
a. e.g. VI = V + I = 5 + 1 = 6
b. e.g. LXX = L + X + X = 50 + 10 + 10 = 70
2. When a symbol appears before a larger symbol, it is subtracted.
a. e.g. IV = V – I = 5 – 1 = 4
b. e.g. IX = X – I = 10 – 1 = 9
3. The same symbol cannot appear more than 3 times in a row.
Now that you’ve cleared up the rules for yourself, you decide to make a program much like
the previous one, only this one converts between Roman numerals and our modern day
numbers.
Write a program that will convert between Roman numerals and modern numbers, and vice
versa.
Your program should detect what sort of numeral/number has been input and make the
appropriate conversion. The user should not need to specify what type of numeral/number
they have input.
The input of your program should be:
The numeral or number to be converted.
The output of your program should be:
The converted numeral or number in the alternate format.
5
business.unsw.edu.au
Sample Runs
The sample runs below show the expected execution of the program (user’s input in blue;
essential output shown in bold purple).
Sample Run #1
Enter a number: XLV
XLV is 45
Sample Run #2
Enter a number: MMMCMXCIX
MMMCMXCIX is 3999
Sample Run #3
Enter a number: 1998
1998 is MCMXCVIII
Sample Run #4
Enter a number: 888
888 is DCCCLXXXVIII
6
business.unsw.edu.au
Part B: River Crossing (4%)
Question 1 (4%): River Crossing
A group is on a journey together when they reach a crocodile-infested river. They all want to
cross to the other side of the river, but there is no bridge, and none of the group can swim, nor
are they crocodile-proof. Their only hope is to hop on the rocks on the river, which are
miraculously positioned in a straight line. The position of the rocks are measured from the start
location, assuming that the group starts at location zero. The opposite riverbank can be treated
as the final rock to jump to.
Each member of the group can jump a different maximum distance and will go as far as they
can for each jump. Can the whole group make it to the other side of the river? What is the
smallest number of jumps each member of the group needs to take to reach the other side of
the river?
Your program should output the minimum number of jumps needed for each group member,
or -1 if it is not possible for that member to reach the other side of the river.
The input of your program should be:
A positive integer, n, representing the number of rocks (including the opposite riverbank).
n distinct, positive integers in increasing order that represent the locations of the rocks.
A positive integer, m, representing the number of group members.
m number of input lines, each containing the group member’s full name, and their maximum
jump distance.
The output of your program should be:
Each group member’s name, and the number of jumps needed, or -1 if it is not possible for
that group member to reach the other side of the river. The group members should be output
in input order.
At the end, your program should state whether or not the whole group can make it to the other
side, and list out who needs to improve their jumping skills.
7
business.unsw.edu.au
Sample Runs
The sample runs below show the expected execution of the program (user’s input in blue;
essential output shown in bold purple).
Sample Run #1
Enter n: 7
32 46 70 85 96 123 145
Enter m: 2
Son Goku 50
Vegeta 45
Son Goku: 3
Vegeta: 5
The whole group can make it to the other side!
Sample Run #2
Enter n: 5
40 70 150 160 180
Enter m: 3
Steve the Penguin 80
Alan the Prairie Dog 60
Bob the Meerkat 53
Steve the Penguin: 3
Alan the Prairie Dog: -1
Bob the Meerkat: -1
Not everyone in the group can make it!
Alan the Prairie Dog needs to improve their jumping skills.
Bob the Meerkat needs to improve their jumping skills.
Sample Run #3
Enter n: 11
30 70 75 120 160 170 180 190 200 246 258
Enter m: 1
Bunny 50
Bunny: 7
The whole group can make it to the other side!