Assignment title: Information
COSC2315 – Programming Fundamentals
1
Semester (2017 semester 1)
Programming Fundamentals (COSC2315)
Assignment 1 – Robot (Simulation) Version 1
Staged Assessment (Total 20 marks)
First Demo – Week starting 20th March ( 5 marks )
Second Demo – Week starting 3rd April ( 5 marks )
Final Submission before 11.59pm Friday 21st April (10 marks)
_________________________________________________________
Assignment Objective
The objective of this assignment is to develop your programming and problem solving
skills in a step-by-step manner, assisted with visualization.
Visualization helps you to easily identify any problems with your algorithm. Students
are expected to devise a strategy before attempting to code any part (trial and error will
cause you to go in circles).
Students will be awarded partial marks for explaining a valid strategy, even if the
program is not working.
The different stages of this assignment are also designed to gradually introduce
different concepts such as loops, arrays, selection, methods and recursion.
You are expected to spend about 30 – 40 hours over a period of five weeks.
Assessment
The assignment is designed to test multiple competencies required for successful software
development. Therefore the assessment evaluates all skills required not just the code itself.
You will be assessed on your ability to comply with requirements as set out in this document
which include developing capabilities in:
1. Programming Style: Adherence to a standard naming convention, documentation of
your program and consistency in your style.
2. Refactoring Design and Code: Refining your code making it easier to maintain and
understand.
3. Incorporating other Parts of Software Development Lifecycle: Incorporating
practices such as test case development covering various configurations and test
execution.
4. Algorithm Development: Demonstrate your ability to come up with an efficient
strategy. The code should closely resemble your logical solution.COSC2315 – Programming Fundamentals
2
Progress Marks and Submission
There will be two progress assessment points during the semester each carrying 5 marks.
Each assessment will be conducted during your scheduled lab session. You are expected to
attend your regular scheduled lab for the progress assessments. Your final submission
through WebLearn should include your code, reports and test cases and test results
highlighting the number of moves for specific configurations (to be released later). Where
you are unable to complete the code please submit a brief description of problems
encountered and lessons learnt.
Assessment Task Date Due Marks
Progress Assessment 1
Part A/B Explanation/Demo
(strategy/code/demo)
Week Starting 20th
March (scheduled Lab)
5 marks
Progress Assessment 2
Part C/D Explanation/Demo
(strategy/code/demo)
Week starting 3rd April
(Scheduled Lab)
5 marks
Code Submission (to be assessed on)
• Correctness / Test cases & results
• Code quality / Documentation
• Modularity / Use of methods & arguments
• Clear Logic / Strategy explained
• Reflection / Lessons learnt
Submit before 21st April
through WebLearn
10 marks
Assignment Overview ( What you need to do)
Write a program to move the stack of blocks from source to target with specific order and
constraints (Some of these constraints will be automatically imposed by the Robot object).
Movement of Robot arms, picking and dropping are controlled using the Robot methods
described below.
The methods of Robot class:
up(), down(), extend(), contract(), raise(), lower(), pick(), drop(),speedUp(), slowDown()
• The height (h) of the main arm can be changed by 1 unit using methods up() and
down(). The height (h) of the this arm must lie in the range 2 to 14, and is initially set
to 2.
• The second arm can be moved horizontally by 1 unit using extend() or contract(). The
width (w) must lie in the range 1 to 10, and is initially set to 1.
• The depth (d) of the third arm can be changed by 1 unit using lower() or raise(). The
depth cannot be less than 0 but must be less than the height of the main arm ( d < h ).
In the initial position depth d is set to 0 (it is not visible).
• The target column for all blocks is in column 1 while source is in column 10. The
column 9 can be used as a temporary location for parts D and E.
• An item can be picked from the top of the stack of blocks at source using pick().COSC2315 – Programming Fundamentals
3
• It can be dropped at the top of the stack of blocks using drop() (subject to specific
constraints in parts D and E). The height of blocks can be between 1 and 4.
• Robot class has two other methods slowDown(int factor) and speedUp(int factor) to
adjust the time between moves by the specified factor.
Other Features
• Collisions with other blocks or bars will cause the program to be aborted immediately
with an appropriate error message.
The Assessment Tasks
The specification for each task is set out below. Note these are requirements B to D are
inclusive , i.e., the requirement set for Part D automatically meets all previous requirements
from Parts A – C.
Standard Tasks
Part A The height of bars are pre-determined and set at 4.The height of the blocks are
predetermined and set at 2.
Part B The user provides the heights of bars at runtime, but values supplied must be in the range
1 – 8.
Part C The user also provides the heights of blocks at runtime, but values supplied must be in the
range 1 – 4. In addition the total height of all the blocks cannot exceed 12.
Part D The user can also specify and order in which the blocks should be placed at the destination.
Additional Task (Bonus marks)
Part E Part E requires you to specify the blocks in descending order of heights at the source.
These blocks should be moved to the target with the limitation that a larger block cannot
be placed on top of a smaller block.
The following page also provides examples with screenshots to clarify the requirements.COSC2315 – Programming Fundamentals
4
Program Screenshots for Parts A to D
Part A: All blocks at source are of size 2 and all bars are of size 4.
Part B: All blocks at source are of height 2 as before but the bar heights may vary.
Part C: Block sizes can be specified in the range 1-4 Bar sizes can be specified in the range 1 to 8.
Example Input: java Robot 543623 34121
Part D: This part allows user to specify the bar heights and block heights as well the order in which
blocks must be placed in the Target. Example Input: java Robot 23456 2341 1234
Note the required order in the target must be a permutation of the block heights specified.COSC2315 – Programming Fundamentals
5
Part E: This part specifies an additional ordering constraint which prevents a larger block being
placed over a smaller block. Example Input: java Robot 543623 43321 ordered
Note this part requires block heights to be in descending order.
Standard Requirements (20 marks in total)
A. Assume all the bars are of height 4 units and the blocks are of height 2 units respectively.
Complete the control() method of the RobotControl class to move all the blocks to the
respective targets.
(No input needed).
B. Allow the user to supply the heights of the 6 bars as command line arguments where the
heights of the bars may vary from 1 to 8.
Complete the control() method of the RobotControl class to move all the blocks to the
respective targets.
Sample input (bar heights): 734561. Based on these inputs, int array barHeights[] will be
automatically set as in: barHeights[0] = 7; barHeights[1] = 3; …. barHeights[5] = 1;
C. Allow the user to supply the heights of the 6 obstacles as well as the height of the four blocks
as command line arguments. Complete the control() method of the RobotControl class to
move all the blocks to the respective targets.
Sample Input bar heights and block heights : 876054 2312.
Based on these inputs int arrays barHeights[], blockHeights[]) will be automatically set as in .
barHeights[0] = 8; barHeights[1] = 7; …. barHeights[5] = 4;
blockHeights[0] = 2; blockHeights[1] = 3; … blockHeights[3] = 2;
D. Allow the blocks to be placed in the specified order. The required order will be passed as the
array argument required[] which you can make use in the program.
Sample Input bar heights and block heights : 876054 2312 3221
barHeights[0] = 8; barHeights[1] = 7; …. barHeights[5] = 4;
blockHeights[0] = 2; blockHeights[1] = 3; … blockHeights[3] = 2;
required[0] = 3; required[1] = 2; … required[3] = 1;
Bonus (5 Marks)
E. Allow the blocks to be moved such that a block cannot be placed over a smaller block. The
block heights input therefore must therefore be in descending order.
Sample Input bar heights and block heights : 876054 3221 ordered
Up to half the marks can be earned by explaining the strategy for solving each section.COSC2315 – Programming Fundamentals
6
The code you need to write to control the Robot moves
For all four sections you are required to complete the control() method of the RobotControl class
shown below. The control() method will be automatically called when the program is run.
RobotControl class has a reference r set to refer to the Robot object. You are free to make use of
other methods of your own.
class RobotControl
{ private Robot r;
public RobotControl(Robot r)
{ this.r = r;
}
public void control(int barHeights[], int blockHeights[],int required[], boolean ordered)
{ // write your code and comments here
// to control robot using r.up(); r.extend() …
}
}
Arguments Passed to the control method
This method is also passed three arrays containing the heights of the bars (barHeights), the blocks
(blockHeights) and the required order (required) (based on user input or default values). If the
instructions you specify for the Robot result in hitting an obstacle or going beyond the limits,
program will terminate immediately with an appropriate Error Message. The ordered variable
(required only for part E) is set to true if the restriction requiring block to be placed to be smaller
than the one underneath is to be enforced. COSC2315 – Programming Fundamentals
7
Startup notes
1. Eclipse Installation instructions
a. Download the archive file PFAssign1.zip.
b. Choose import option in file menu item. Expand the General tab and select Existing
project into workspace option. Selection the button Select-archive-file and navigate
to the downloaded file PFAssign1.zip, and press Finish. Ensure that in the Run
menu Run-Configuration option, under Java Application, in the Main tab, that Robot is
specified as the Main class. You can now run the project.
c. The control method in RobotControl.java has some code to get you started.
d. You can specify the bar and block heights (for sections B to E) by selecting "Run" →
"Run Configurations" from the menu, then clicking on the "Arguments" tab and
typing in your arguments in the text box (for example, 734561 231231 for section C)
Coding style / structure
You are required to adhere to all standard java coding conventions, which include correct and
consistent indentation of code, use of appropriate identifiers for variables and comments
describing the main logic program. However, avoid commenting code that is obvious to the
reader (for example, x = 5; // assigning 5 to x). You can also make the program structure
clearer by subdividing your code into blocks or methods.
When awarding marks, the clarity of code and efficiency of code will also be considered.
Once, you have made your code to work you are expected to refactor your code removing
any duplicated, redundant or misleading code and improving the efficiency by removing
unwanted moves.
Note: You are expected to use loops and nested loops to avoid repeating the code for
moving each single block for requirements B and C (for requirement A we will accept any
working solution that demonstrates the use of loops, even if nested loops have not been
utilized). You are also encouraged to use methods for parts (D) and (E).
What you need to do
Students are advised to tackle each of the requirements in turn – when you have completed
the code for one stage of the assignment (eg. Requirement A) then you can comment that
section out and proceed to the next stage.
You should leave the last FUNCTIONAL stage you have completed uncommented and
comment out previously completed stages (don't delete them just in case). If you have made
an attempt at a later section (B, C, D) but without successful completion, then comment that
section out. In your report highlight your problems and lessons learnt. This will allow the
marker to award marks for working code based on code execution, and marks for partial
completion based on code inspection.