Sei sulla pagina 1di 8

Programming Fundamentals (48023) Spring 2014 Assignment 1Page 1

Programming Fundamentals (48023)


Combined Assignment 1 Part B / Assignment 2
STUDENTS ARE MEMINDED THAT THIS ASSIGNMENT HAS NO INFLUENCE ON
WHETHER THEY PASS OR FAIL THIS SUBJECT. PASSING AND FAILING IS
SOLELY DETERMINED BY THE MASTERY TESTS.
In this assignment, you will finish the game that you started building in Assignment 1 Part A.
The specification and a sample solution of Part A is available in UTSOnline at
Assignments Assignment1 Part A Specification and Sample Solution (Spring 2014).
Students are welcome to do this assignment even if they did not do Part A. Conditions
specified in part A still apply to this assignment, so students MUST read part A if they did not
do part A.
Students had a lot more trouble with Assignment 1 Part A than had been anticipated. It was
therefore decided to cut back on the subsequent assignment load. Hence, students who do this
assignment will receive EXACTLY THE SAME MARK for BOTH Assignment 1 Part B AND
Assignment 2. For example, suppose you do Assignment 1 Part B and score 100%. You will
receive 100% for BOTH Assignment 1 Part B AND Assignment 2. Suppose instead you
do Assignment 1 Part B and score 50%. You will receive 50% for BOTH Assignment 1 Part B
AND Assignment 2.
Due date: Friday, 7th November 2014, 5:00pm.
Value: 15% for Assignment 1B and 15% for Assignment 2 (i.e. 30% of your final total mark)
Topics: Data flow, OO programming basics, Control flow.
Objectives: This assignment supports objectives 1-5.
NOTE: In the remainder of semester, many lab sessions will be devoted to providing help with
this assignment. The ONLY place where students may ask for help from the 48023 teaching
staff is at those lab sessions and also at the week 12 and 13 lectures (the week 14 is reserved
for the individual project presentations). Questions about the assignment will NOT be
answered by email. Students are advised to start working on the assignment early, to take
maximum advantage of the lab and lecture sessions.
Introduction
You may use either your solution to Part A as a starting point, or you may use our provided
solution to Part A as a starting point. This solution is available at UTSOnline Assignments
Assignment1 Part A Specification and Sample Solution (Spring 2014).
Note!! Your solution to this assignment should be submitted on PLATE under the link
Assignment 1 Part B. Be careful not to submit under the link Assignment 1 Part A.
Programming Fundamentals (48023) Spring 2014 Assignment 1Page 2
In your completed game, each player will have alternating turns until one player has dominated
the world (i.e. is the owner of all territories). The first turn of each player involves only one
step:
Place armies
However, any turn after the first turn will have more steps:
1. Place armies
2. Attack territories owned by other players
3. Transfer armies between the player's own territories
After completing a turn, if no player has won, control transfers to the next player.
Tasks
Some of the following tasks are divided into a basic feature which is necessary to complete
before continuing to the next task, and an advanced feature which will give you extra marks
but is not necessary to complete before continuing to the next task. It is possible to skip an
advanced feature and come back to it later.
Task 1: place armies
Basic feature
Remove your existing World.placeArmies code. In class World, define a procedure called
placeArmies taking only a player as a parameter. This procedure should operate according to
the following input/output (with user input shown underlined and in bold):
You have 3 armies to place.
[0,0]null(0) [1,0]null(0) [0,1]null(0) [1,1]null(0)
Select a territory: 0 0
[0,0]Joe(1) [1,0]null(0) [0,1]null(0) [1,1]null(0)
Select a territory: 0 1
[0,0]Joe(1) [1,0]null(0) [0,1]Joe(1) [1,1]null(0)
Select a territory: 0 0
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(1) [1,1]null(0)

It is possible to read two integers typed on the same line by simply using two successive
invocations of the nextInt() method:
int variable1 = keyboard.nextInt();
int variable2 = keyboard.nextInt();
Note: do not name your variables variable1 and variable2!! Always choose meaningful
names.
Programming Fundamentals (48023) Spring 2014 Assignment 1Page 3
Depending on what position the user types, your program should place an army into the
specified territory. For example, if the user types 0 0, your program should place 1 army into
the top-left territory.
At this point, submit your solution to PLATE to receive partial marks for this task. Then
continue reading to earn the remainder of the marks.
Advanced feature
In the above example, the number of unplacedArmies is 3. Because of this, the program asks
the user to select a territory 3 times. Your code should be written so that it will work for
different numbers of unplacedArmies. For example, if unplacedArmies were 4, then your code
would need to ask the user to select a territory 4 times.
If a player attempts to place armies on a territory that is already owned by another player, then
no armies will be placed there. For example, if Joe has placed 3 armies in the example above,
and Sam tries to place an army on one of Joe's territories, the following may happen:

You have 3 armies to place.
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(1) [1,1]null(0)
Select a territory: 1 0
[0,0]Joe(2) [1,0]Sam(1) [0,1]Joe(1) [1,1]null(0)
Select a territory: 1 1
[0,0]Joe(2) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(1)
Select a territory: 0 0
[0,0]Joe(2) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(1)
Select a territory: 1 1
[0,0]Joe(2) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)

In this scenario, Sam had 3 armies to place, but on the third input, Sam attempted to place an
army on one of Joe's territories and nothing happened. Therefore, Sam still had one more army
to place and the program continued asking Sam to select another territory until all armies had
successfully been placed. It is not possible to predict how many times it will be necessary to re-
ask the player to select a territory (think: is this a for-loop or a while-loop or a do/while loop?)
Task 2: Transfer
Basic feature
In class World, define a procedure called transfer that takes only a player as a parameter.
This procedure should operate according to the following input/output (with user input shown
underlined and in bold):
Select source/target territories for a transfer.
[0,0]Joe(3) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 0 0
Select a territory: 0 1
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(2) [1,1]Sam(2)
Select a territory: -1

Programming Fundamentals (48023) Spring 2014 Assignment 1Page 4
The first input selects the territory that an army will be transferred from (the source). The
second input selects the territory that an army will be transferred to (the target). The third input
of -1 indicates that the transfer procedure should be terminated. In the basic feature, you can
assume that the user will always type -1 as the third input. Note: if the user enters -1, you
should use keyboard.nextInt() only once, not twice.
At this point, submit your solution to PLATE to receive partial marks for this task. Then
continue reading to earn the remainder of the marks.
Advanced feature
It should also be possible for the player to perform more than one transfer, typing -1 at the end
only when the user wishes to perform no more transfers, as illustrated by the following
input/output scenario:
Select source/target territories for a transfer.
[0,0]Joe(2) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 0 0
Select a territory: 0 1
[0,0]Joe(1) [1,0]null(0) [0,1]Joe(2) [1,1]Sam(2)
Select a territory: 0 0
Select a territory: 0 1
[0,0]null(0) [1,0]null(0) [0,1]Joe(3) [1,1]Sam(2)
Select a territory: 0 1
Select a territory: 0 0
[0,0]Joe(1) [1,0]null(0) [0,1]Joe(2) [1,1]Sam(2)
Select a territory: -1

Note that after the second transfer, Joe has no more armies on [0,0] and its owner is set to null.
Furthermore, if the player selects a source or target that is not owned by themselves, your
program should ignore that selection and prompt for another selection:

Select source/target territories for a transfer.
[0,0]Joe(3) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)

Select a territory: 1 0
Select a territory: 1 0
Select a territory: 1 1
Select a territory: 0 0
Select a territory: 0 1
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(2) [1,1]Sam(2)
Select a territory: -1

In this scenario, Joe fails to select one of his own territories 3 times. On the 4th input, he
finally selects one of his own territories, and the program proceeds to selecting the target
territory and then performs the transfer from [0,0] to [0,1].

Programming Fundamentals (48023) Spring 2014 Assignment 1Page 5
Task 3: Attack
Basic feature
In class World, define a procedure called attack that takes only a player as a parameter. This
procedure should operate according to the following input/output (with user input shown in
underlined and bold):
Select source/target territories for an attack.
[0,0]Joe(3) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 0 0
Select a territory: 1 0
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 1 1
[0,0]Joe(1) [1,0]null(0) [0,1]Joe(1) [1,1]Sam(1)
Select a territory: -1

The first input selects the territory that will initiate the attacks (the source). Every subsequent
input selects a territory that will be attacked by the first territory (the target), until the
sentinal input of -1 is entered, which indicates that the attack procedure should end. If the user
enters -1, you should use keyboard.nextInt() only once, not twice.
Each time a territory attacks another territory, both of the two territories involved will lose one
army. If a territory loses all of its armies, the owner of that territory is also set to null.
At this point, submit your solution to PLATE to receive partial marks for this task. Then
continue reading to earn the remainder of the marks.
Advanced feature
It should also be possible for a player to select a new source during the attack procedure.
Consider the following alternative scenario:
Select source/target territories for an attack.
[0,0]Joe(3) [1,0]Sam(1) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 0 0
Select a territory: 1 0
[0,0]Joe(2) [1,0]null(0) [0,1]Joe(1) [1,1]Sam(2)
Select a territory: 1 1
[0,0]Joe(1) [1,0]null(0) [0,1]Joe(1) [1,1]Sam(1)
Select a territory: 0 1
Select a territory: 1 1
[0,0]Joe(1) [1,0]null(0) [0,1]null(0) [1,1]null(0)
Select a territory: -1
On the 4th input, Joe selects one of his own territories, and this sets a new source territory.
Then on the 5th input, Joe selects Sam's [1,1] territory and attacks it from the now current
source of [0,1].
In addition to the above behaviour, if the very first territory that a player attempts to select is
not one of their own, your program should ignore the selection and display again the prompt
Select a territory: .
Programming Fundamentals (48023) Spring 2014 Assignment 1Page 6
Task 4: Player turn
Define a procedure in class World called turn that takes only a player as a parameter, and
executes that player's turn by invoking all of the previous methods. At the beginning of the
turn, print a line in the following format:

Joe's turn.

At the beginning of a player's turn, give the player an additional N unplacedArmies if the
player owns N territories.
If this is the player's first turn, just invoke the placeArmies procedure next. Otherwise, if the
player has already past the first turn, then invoke the placeArmies, attack and transfer methods
in sequence. However, if the player lost all of his/her territories during the attack procedure, do
not execute the transfer procedure.
In order to complete this task, you will need to define two additional fields:
Each Player has a current turn. This begins at zero. It is incremented to 1 when the
player has his/her first turn, and is then incremented to 2 when the player has his/her
second turn, and so on.
Each Player has a number of territories. This begins at zero. Each time a player
becomes the owner of another territory, the territories field is increased by 1, and
each time a player loses ownership of a territory, the territories field is decreased by
1.
Task 5: Main method
Write a class called Main containing a public static void main() method with appropriate
parameters. This method should cause the entire program to run according to the procedure
outlined in the introduction section of Part B of this assignment. That is, each player will have
alternating turns until one player has dominated the world (i.e. is the owner of all territories).
At the end of the game, your program should print the message XYZ wins! where XYZ is
the name of the player who won.
When implementing this task, be careful that you do not break the specification for any of the
earlier tasks. For example, after completing Task 4, your program must still satisfy the
requirements for Task 1, otherwise you will lose marks for Task 1.
Marking scheme for part B
Your solution will be marked according to the following scheme:

Task 1: Place enemies


20 marks
- basic (10)
- advanced (10)
Programming Fundamentals (48023) Spring 2014 Assignment 1Page 7
Task 2: Transfer


Task 3: Attack


Task 4: Player turn
Task 5: Main method
Correct indentation
Design
10 marks
- basic (5)
- advanced (5)
20 marks
- basic (10)
- advanced (10)
15 marks
10 marks
5 marks
20 marks
Remember you will be given the same mark for Assignment 1 part B and Assignment 2. So, if
you score 75 marks out of 100 on the above scheme, you will receive 0.75*15 = 11.25 marks
for Assignment 1 part B and 11.25 marks for Assignment 2, a total of 22.5 marks.
Correct indentation means that code should be shifted right by one tab between { and } and
within nested control structures such as if statements, switch statements and loop statements. In
a switch statement, the code within each case should also be indented. NOTE: You are
responsible for your own indentation. Do not rely on BlueJ to indent code for you. BlueJ does
not always indent code in the way that is required.
Design refers to how well you have eliminated repeated code, and how well you have
structured your program in terms of coupling and cohesion.
Please note instructions and the rules below.
Individual assessment
This assignment must be done by yourself and not with anyone else. Group work is not
allowed and will be considered as academic misconduct.
Academic misconduct
Working with another person on this assignment is not allowed and is considered as academic
misconduct. Do not show other people your code, or look at other people's code, or discuss
assignment code with other people; it is an offence to have a copy of someone else's
assignment (before the submission date). Do not post your assignment on the web. Posting
your assignment on the web and getting help through blogs, forums or other websites is
considered to be an academic misconduct.

To detect plagiarism, the subject uses an online system called PLATE available at
http://plate.it.uts.edu.au

Students may find it useful to consult The UTS Coursework Assessment Policy & Procedure
Manual, at http://www.gsu.uts.edu.au/policies/assessment-coursework.html
Programming Fundamentals (48023) Spring 2014 Assignment 1Page 8
Expected work load
It is expected that this assignment will take about 4 to 10 hours of work. A well-designed
solution is expected to use approximately 150-200 lines of code, while a badly-designed
solution may reach up to 300 lines of code. Some people may complete the task in 5 hours, and
some may need 30 hours or more; there is a huge variation in students' experience and abilities.
Assignment submission and return
Your assignment must be submitted as a JAR file through the PLATE system, online, at
http://plate.it.uts.edu.au/. You may submit and resubmit as many times as you wish, before the
due date, and PLATE will update your mark.
Instructions for submitting to PLATE are displayed online at the PLATE website.
WARNING! PLATE may become overloaded on or near the due date when many students
load and test their solution at the last minute. This will not be considered as a valid reason for
an extension. To be safe, you should aim to submit your solution well before the due date.
Your marks for the assignment will be available through PLATE within 2 weeks after the due
date.
Late submission
For late assignment submissions, each 24 hour period after the due date and time is considered
to be an extra day late. For example, a submission one minute after the deadline is considered 1
day late, while a submission 24 hours plus 1 minute after the deadline is considered 2 days late.
Late Part B submissions will lose 20% of its original mark per day late, unless permission has
been given by the subject co-ordinator before the due date.
If your performance in an assessment item or items has been affected by extenuating or special
circumstances beyond your control you may apply for Special Consideration. Information on
how to apply can be found at http://www.sau.uts.edu.au/assessment/consideration.html
Model solution
A model solution can be copied from UTSOnline one week after the due date.

Potrebbero piacerti anche