KXO151 Programming & Problem Solving
AIEN-SOU - 2020
Assignment 2
Deadline for Submission: 10pm (Shanghai) Wednesday, Week 9, 29 April, 2020
Maximum Marks Available: 15 (15% of the total assessment for KXO151)
Submission: Via MyLO
NOTE: All assignments will be checked for plagiarism by a specialist Java program that checks
your assignment against other student’s assignments as well as the Internet (including help
sites). For more information see:
www.ics.heacademy.ac.uk/resources/assessment/plagiarism/demo_jplag.html
Assignment Type: Individual
Requirements:
PLEASE NOTE: This assignment is to be completed by Students individually. If you need help, please
look at the textbook or ask your lecturer. Students who have been working through the tutorial
exercises should not have much difficulty in completing this assignment.
PLEASE NOTE: The submitted Java code must be able to be compiled from the command line using
Javac the Java programming language compiler command, or from a basic editor such as jGrasp. Be
aware that development programs such as Eclipse often use features only available when run using
their system, meaning that their code may not run on a system without their development program.
Programs that do not run from the command line using javac (to compile) and java (to run) because
of a missing development program feature will fail the assignment.
You are required to perform the following tasks:
You are to write a Java application program named Asst2.java which is a game for calculating a
user’s happiness level -- their HI (Happy Index) where 0.0% represents completely unhappy and
100.0% represents completely happy. This figure is calculated based on input from the user. The
details (specifications) of this task are given below. Note that the correctness marks you receive for
your program will depend on how well it matches this specification.
To determine a user’s HI, the user will be asked four questions:
• Their full name (which may contain spaces).
• Their gender ('M'/'m' for male, 'F'/'f' for female).
• Their age in months (as a whole number).
• Whether or not they feel like committing an act of violence (true or false).
The answers to these questions will be used to determine the user's Happy Index which will be
displayed on the screen. The user will always see at least one Happy Index when they run the
program.
The following are the specific details about the assignment requirements:
• The user will be asked to enter their name. (Their entry may contain spaces and upper- and
lower-case letters.)
V1.0
Page 2 of 6
• The user will be asked to enter their gender. (Their entry may be an upper- or lower-case
'm' or 'f'.)
• The user will be asked to enter their age in months. (Their entry may be any positive whole
number between 0 and 1320.)
• The user will be asked to enter true/false as to whether they're feeling violent.
• All the above information should then be displayed to the user in the form (with sample
data of "Donald Duck", 'm', 720, true) of:
Donald Duck (male, aged 60 years, feeling violent) has a HI of:
• The program will then work out the user's Happy Index. An algorithm to do this follows.
• Starting with a HI of 1.0:
o If the user feels violent then the HI is multiplied by 7.
o If the user is male then the HI is multiplied by 10, otherwise the HI is divided by 2.
o If the age is less than 180 months or greater than 960 months then the HI is multiplied
by 0. Otherwise,
▪ if the age is between 180 and 420 months inclusive then the HI is multiplied by
5
▪ if the age is between 660 and 960 months inclusive then the HI is multiplied by
3
▪ Otherwise, nothing is done.
o The HI is then scaled (by dividing it by 700.0 and multiplying by 100.0) to a value
between 0.0 and 100.0.
• The user’s Happy Index is then appended to the line of output on the screen, i.e. the user
would see:
Donald Duck (male, aged 60 years, feeling violent) has a HI of: 30.0
• After the HI has been displayed, the user is asked whether they want to determine another.
To determine another HI they must enter the character 'y' or 'Y' (for yes). They will then be
asked for another name, gender, age, and feeling-of-violence and will see another HI. If they
enter any letter other than 'y' or 'Y' the program will stop.
• The user will be shown a message saying how many HIs were displayed.
A sample output of the program is attached to the end of this document.
Program Style
The program you write for this assignment must be a single class called Asst2 with the code in a file
called Asst2.java. There should be a single method (the main() method) in this class.
Your program should follow the coding conventions introduced in this unit and shown in the
textbook, especially:
• Variable identifiers should start with a lower case letter
• Final variable identifiers should be written all in upper case and should be declared before
all other variables
• Every if-else statement should have a block of code for both the if part and the else part (if
used)
• Every loop should have a block of code (if used)
• The program should use final variables as much as possible
• The keyword continue should not be used
• The keyword break should only be used as part of a switch statement (if required)
Page 3 of 6
• Opening and closing braces of a block should be aligned
• All code within a block should be aligned and indented 1 tab stop (approximately 4 spaces)
from the braces marking this block
Commenting:
• There should be a block of header comment which includes at least
o file name
o your name (in pinyin)
o student UTas id number
o a statement of the purpose of the program
• Each variable declaration should be commented.
• There should be a comment identifying groups of statements that do various parts of the
task.
• There should not be a comment stating what every (or nearly every) line of the code does -
as in:
num1 = num1 + 1; // add 1 to num1
Save the Output
Run your program entering data via the keyboard and save the output of your program to a text file
using your UTas student id number as the name of the file, for example, 159900.txt (in jGrasp, right
mouse-click in the ‘Run I/O’ window and select ‘Save As Text File’).
Important Notes:
• Changing a few variable names, adding different data and / or adding your name to the top
of someone else’s code does not make it your own work. See the section on ‘Plagiarism’
below.
• You need to submit 2 files:
o your Asst2.java
o a text file containing the output of your program using your UTas id number as the
name of the file, for example, 159900.txt.
o See the section on ‘Submission’ below for more information.
• Before you submit your assignment through the KXO151 MyLO website, it is suggested that
you make sure the final version of your Java program file compiles and runs as expected –
do not change the names of the java file – submit it exactly as you last compiled and ran it.
Programs that do not compile and / or run will fail the assignment. If in doubt, you can
click on the submitted files, download them from MyLO, and check that they are the files
you think they should be.
NOTE: The higher marks are reserved for solutions that are highly distinguished from the rest and
show an understanding and ability to program using Java that is well above the average.
Page 4 of 6
Guide to Assessment and Expectations:
The assessment of Assignment 2 is based on the following criteria:
Criteria High Distinction Distinction Credit Pass Fail
Working Java
Program
Fully working set of
Java classes that
satisfy the
requirements stated
in the assignment
requirements.
Fully working set of
Java classes that
satisfy the
requirements stated
in the assignment
requirements.
Fully working set of
Java classes that
satisfy the
requirements stated
in the assignment
requirements.
Fully working set of
Java classes that
satisfy the
requirements stated
in the assignment
requirements.
A set of Java classes
that fail to satisfy the
requirements stated
in the assignment
requirements & / or
fail to compile & / or
run
Documentation
Complete
documentation of all
significant & relevant
aspects of those
classes.
Reasonably complete
documentation of
significant & relevant
aspects of those
classes.
Good documentation
of significant &
relevant aspects of
those classes.
Some documentation
of significant &
relevant aspects of
those classes.
No documentation of
significant & relevant
aspects of those
classes.
Program
Correctness
Evidence of thorough
testing of the revised
& written classes.
Evidence of thorough
testing of the revised
& written classes.
Evidence of some
testing of the revised
& written classes.
Evidence of some
testing of the revised
& written classes.
No evidence of
testing of the revised
& written classes.
Understanding
of Java
Demonstrated clear
understanding of the
nature of Java classes,
of Java class methods,
of data variables, & of
the use of the main
method.
Demonstrated good
understanding of the
nature of Java classes,
of Java class methods,
of data variables, & of
the use of the main
method.
Demonstrated
reasonable
understanding of the
nature of Java classes,
of Java class methods,
of data variables, & of
the use of the main
method.
Demonstrated basic
understanding of the
nature of Java classes,
of Java class methods,
of data variables, & of
the use of the main
method.
Failure to
demonstrate
adequate
understanding of the
nature of Java classes,
of Java class methods,
of data variables, &
/or of the use of the
main method.
Note The High Distinction grade is reserved for solutions that fully meet the requirements & are highly distinguished from
other assignments by their high quality work & their attention to detail (usually only 10% of students).
PLEASE NOTE: The assignment will receive a single composite mark. The assignment will be
accessed from the point of view of the requirements: “Does it meet the requirements, and how well
does it do it?” Where there is some inconsistency in that the work does not completely match every
sub-criteria within a particular criteria, then the grade reflects the value of the work ‘on average’.
Submission:
Your completed solution (your Asst2.java file, plus a text file containing the output of your
program using your UTas id number as the name of the file, for example, 159900.txt) must be
submitted by the deadline. Assignments must be submitted electronically via KXO151 MyLO
website as files that can be read by a text editor such as Microsoft Notepad (submit the *.java file -
not the *.class file). Follow the following steps to create a package for your assignment files and
then submit your package file:
1. On your computer desktop, create a new folder using your name and UTAS ID number. For
example, if you name is Jianwen CHEN and your UTAS ID number is 159900, then the new folder
must be named Chen_Jianwen_159900;
2. Copy your 2 assignment files into the new folder;
3. Use the WinRAR application to compress the new folder and name it as *.rar. For example,
Jianwen CHEN would name it as Chen_Jianwen_159900.rar.
4. Submit your *.rar file to the unit MyLO “Assignments” folder.
Details of the actual submission procedure are available through the MyLO webpages.
Page 5 of 6
Students who believe that this method of submission is unsuitable given their personal
circumstances must make alternative arrangements with their Lecturer prior to the submission
date.
Extensions will only be granted under exceptional conditions, and must be requested with
adequate notice on the Request for Extension forms.
In submitting your assignment you are agreeing that you have read the ‘Plagiarism’ section below,
and that your assignment submission complies with the assignment requirement that it is your own
work.
Plagiarism
While students are encouraged to discuss the assignments in this unit and to engage in active
learning from each other, it is important that they are also aware of the University’s policy on
plagiarism. Plagiarism is taking and using someone else's thoughts, writings or inventions and
representing them as your own; for example downloading an essay wholly or in part from the
internet, copying another student’s work or using an author’s words or ideas without citing the
source.
It is important that you understand this statement on plagiarism. Should you require clarification
please see your unit coordinator or lecturer. Useful resources on academic integrity, including
what it is and how to maintain it, are also available at: www.academicintegrity.utas.edu.au/.
Acknowledgement
This assignment has been adapted from a programming project developed by Dr Julian Dermoudy. The assignment template
was written by Dr Dean Steer.
Plagiarism is a form of cheating. It is taking and using someone else's thoughts,
writings or inventions and representing them as your own; for example, using an
author's words without putting them in quotation marks and citing the source, using
an author's ideas without proper acknowledgment and citation or copying another
student’s work.
If you have any doubts about how to refer to the work of others in your assignments,
please consult your lecturer or tutor for relevant referencing guidelines, and the
academic integrity resources on the web at: www.academicintegrity.utas.edu.au/.
The intentional copying of someone else’s work as one’s own is a serious offence
punishable by penalties that may range from a fine or deduction/cancellation of marks
and, in the most serious of cases, to exclusion from a unit, a course or the University.
Details of penalties that can be imposed are available in the Ordinance of Student
Discipline – Part 3 Academic Misconduct, see:
www.utas.edu.au/universitycouncil/legislation/
The University reserves the right to submit assignments to plagiarism detection
software, and might then retain a copy of the assignment on its database for the
purpose of future plagiarism checking.
Page 6 of 6
Sample Outputs of Assignment 2, 2020
C:\KXO151>java Asst2
This program will provide Happy Indices
Please enter your name: Sally Smith
Please enter your gender (m/f): f
Please enter your age in months: 980
True or false -- do you feel violent: false
Sally Smith (female, aged 81 years, not feeling violent) has a HI of: