辅导案例-SEHS2307

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
1

SEHS2307 Computer Programming Concepts
Assignment Description


This Assignment is worth 30 marks, or 15% of the assessment of this course.
Due: 2200 hrs (10pm), Sunday 1 December 2019


Summary

Create a program that shows a practical use of a collection class, and write your own more
advanced collection class.


Forming Groups

Each group should have 2 students.

If a student is unable to find a group, then the lecturer will assign them to a group. In this
case, the student(s) will not be allowed to choose their group.

Each group member’s individual mark may be adjusted, depending on their contribution to
the group assignment. For example, a student’s mark may be reduced if it is found that they
have contributed a disproportionally small amount of work.


Assignment – Part 0

You need to understand the lecture notes and lab exercises from week 7 (Classes & Objects)
to do Part 0.

Write a simple class representing something (a type of object) that can be inserted into an
ArrayList. The class that you choose must:

 NOT be the Account, Square, Circle, Fish or any other class that has been done in
the previous tutorials or lectures. You must write your own class.
 Have 2 instance variables:
o A unique instance variable. Each object will have a unique value for this instance
variable. E.g. owner or accountNumber in the Account class. You do NOT have
to write code to make sure that each object has a unique value of this variable.
o A quantity instance variable. This has a numeric value, representing some
quantity that can be changed, and can also be used to order the objects. E.g.
balance in the Account class can be used to order account objects from richest to
poorest, and the balance in each account object can be changed
2

 Have at least 1 instance method to modify the numeric instance variable value. E.g.
the deposit method can modify the balance instance variable in the Account class.

Keep this class as simple as possible (as few instance variables and methods) while also
following the above requirements. This class is only worth 1 mark – see the marking scheme
at the end of this assignment description.

Note: In this assignment description, to make some examples clearer to understand, we may
assume that the class written in Part 0 is the Account class. However, this is only to make the
assignment description clearer. In your assignment, you are NOT ALLOWED to write an
Account class – you must come up with your own practical example.


Assignment – Part 1

You need to understand the lecture notes and lab exercises from week 9 (Collection Classes)
to do Part 1. See the sample solutions for these tutorials for help.

Write all your code in Part 1 into a class called CodeCliches and save it into a file called
CodeCliches.java.

Firstly, write 4 code-cliché methods, with one method to perform each of the following. You
must decide on appropriate method names (do NOT call them method1a, etc.), parameters,
return types, and suitable method-header comments:

 Method 1a: Returns the average numeric instance variable value (e.g. the average
balance of all Account objects in a given ArrayList). If the ArrayList is empty, 0
should be returned.
 Method 1b: Returns true or false depending on whether an element with the
specified unique instance variable value exists (e.g. returns true if there is an
Account object in a given ArrayList whose owner is a specified value, such as
“Amy”, and returns false if there is no Account belonging to “Amy”). Your method
should also remove this element from the ArrayList if it exists.
 Method 1c: Returns a reference to the element with the maximum numeric instance
variable value (e.g. returns a reference to an Account object with the highest balance
of all Account objects in a given ArrayList). If there is more than 1 element with the
maximum value, then you can return any one (and only one) of the elements with the
maximum value.
 Method 1d: Returns an ArrayList containing all the elements that have a numeric
instance variable value between (and not equal to) 2 specified numbers (e.g. if the
specified values are $1000 and $2000, the method returns an ArrayList containing
all the Account objects in the given ArrayList with a balance between $1000 and
$2000)

Secondly, perform some very basic testing by using each of your methods and printing some
results on the screen, similar to the week 9 tutorial.
3

Assignment – Part 2

You need to understand the lecture notes and lab exercises from week 10 (Text and File I/O)
to do Part 2. See the sample solutions for this lab for help.

In Part 2 of the Assignment, you need to write a simple but practical program that uses the
class that you wrote in Part 0 of the Assignment. The aim is to create a program so that a
typical user can easily store information about the class type from Part 0 into a list, perform
actions that affect the list, and perform queries on the list.

Please note:

 The emphasis is NOT on a very complex or realistic program. Rather, the emphasis is
on a simple but useful program that behaves sensibly
 There is a fair bit of flexibility in this assignment. Recommendations are given in this
assignment description, as well as in the lectures. However, many specific details are
not mentioned here, so you can decide yourself specifically how you will approach
them, but keep in mind the marking scheme. If you are unsure, ask your lecturer.
 Your program must read text user input. Do NOT use a Graphical User Interface
(GUI).
 Do NOT write a design document, test report or class diagram.
 Do NOT write testing code for this part of your assignment.


Program Capabilities

At the start, when the user of your program can enter their first command, your program
should have an empty ArrayList. At this main menu, which shows up again after each user
command (except after the user wants to quit), the user of your program must be able to do
any of the following things:

 Basics actions:
o Quit the program. The program should end, and the main menu should not appear
again.
o Print out details (instance variable values) of all elements in the list
o Create an empty list (ignoring whatever was in the list previously)

 Inserting elements into and removing elements from a list:
o Insert an element into the list. The user will then be asked to enter the values of the
instance variables of the object to be inserted into the list. If there is already another
object with the same unique instance variable value, then the attempted insert should
fail, and an appropriate message should appear.
o Remove a particular element from the list with a certain unique instance variable
value (specified by the user). If such an element does not exist, then an appropriate
error message should be printed. Use method 1b from Part 1.

4

 Reading from and writing to files:
o Read text data from file (the filename is specified by the user), representing the
objects in a list. After this action, those objects are stored into the list, and whatever
was in the list before reading from file should no longer be in the list. However, if the
given filename does not exist, an appropriate message should appear, and the list
should remain unchanged.
o Write the current list to text file (filename specified by the user)

 Using code cliches:
o Print out the average numeric instance variable value. Use method 1a from Part 1.
o Print out the maximum numeric instance variable value, as well as the details of the
element with this maximum value. If there is more than 1 element with the maximum
value, then you can just print out the details of any one (and only one) of the elements
with the maximum value. Use method 1c from Part 1.
o Print out details of all elements in the list with a numeric instance variable value that
is between 2 values (specified by the user). Use method 1d from Part 1.
o Change the numeric instance variable value of an element with a given unique
instance variable value (specified by the user) to a new value (also specified by the
user). For example, if the ArrayList contains Account objects, then the user should
be able to deposit or withdraw money from any Account object in the list. If there is
no such element with the specified unique instance variable value, then an
appropriate message should be printed.

For some of the points above, you should use the code written in the CodeCliches class. That
means that you should not re-write the code in Part 1 – you should simply call those methods
in the CodeCliches class.

Note that your program must be able to work in the general case, for any values the user
would like to use. For example, if the user wants to find all accounts that have between two
amounts of money, the user must be able to type in any 2 values they wish. Therefore, in
cases like this, there should not be a menu where they have to choose from a specific set of
values.


File Format

To keep the assignment as simple as possible, it is recommended that the required file format
for your program should be as follows (however, you can choose any format you wish). Each
instance variable value should be written on a separate line, with blank lines separating each
object. For example, if we had 3 bank accounts belonging to Adam, Betty and Charlie, and
they had $100, $400 and $200 respectively, and they were in this order in the ArrayList
(Adam’s account at index 0, Betty’s account at index 1, and Charlie’s account at index 2),
then the file would look like this:


5

Adam
100.0

Betty
400.0

Charlie
200.0

If your program tries to read from a file, and it is not in the correct format, then you should of
course print an error message, and the ArrayList in the program should remain unchanged.


Assignment – Part 3

You need to understand the lecture notes and lab exercises from weeks 11-12 (Arrays and
Assignment Help) to do Part 3. See also the sample solutions for these tutorials. More help
will be given during these tutorials.

Consider a collection class that is similar to the ArrayList class, except that elements are
ordered. We will call this class OrderedList. This class has many of the same simple
features that the ArrayList class has, but it also has some new features that are different to
the ArrayList class.

The main difference is that each element (which can be of any class type) that is added into
the OrderedList also has a corresponding priority, which is a number. All elements in the
OrderedList need to be sorted in descending order (highest priority comes first) according to
their priorities at all times.

For example, if there is a list of String objects, with values “A”, “B”, “C” and “D”, and their
corresponding priorities are 62, 13, 71 and 38, then the strings should appear in the
OrderedList in this order:

“C” (with priority 71), “A” (62), “D” (38), “B” (13)

In Part 3 of the Assignment, your task is to write the entire OrderedList class (its instance
variables, constructor and instance methods).

You should download OrderedList.java from the course website to help you get started.

 It already contains the headers of the methods (including the constructor) that you
must write. Each method is described with a comment above the method header; you
have to write the code inside the methods to perform according to the comment. Do
NOT change any of the method headers nor the method header comments.
 You should write more (helper) methods to improve coding style (worth marks).
6

 There is already 1 instance variable declared. You should not change or remove this
instance variable declaration.
 You may need to include more instance / static variables to properly write the
OrderedList class.


How the OrderedList class stores many elements

Your OrderedList class can use an Object[] (Object array) to store elements of any class
type. This is already declared for you in the OrderedList.java file. However, you must NOT
use the ArrayList class, or any other collection class.

At all times, the array inside the OrderedList should have exactly the same length as the
number of elements that are stored. For example, if there are 3 elements being stored, then
the array should have a length of 3.


Inserting elements into the OrderedList

When an element is added into the OrderedList, it should automatically be placed at the
correct position, so that all elements inside the OrderedList will still be sorted by their
priority. For example, if we already had the following OrderedList of strings (with
corresponding priorities in brackets) in the following order:

“A” (91), “B” (57), “C” (13)

and then the string “D” with priority 74 is added, the OrderedList should now look like this:

“A” (91), “D” (74), “B” (57), “C” (13)

And the array should now have a length of 4, not 3.

Note that elements are not allowed to have the same priority. To properly insert an element,
you need to do a number of things:

 Make sure that there isn’t already an element in the OrderedList with the same
priority as the element to be inserted.
 Determine where the correct position is to insert the new element.
 Make the array big enough so that the new element can be inserted.
 Shift some elements over so that there is room for the new element that is being
added, and so that no element that was previously in the OrderedList is deleted.

See the lecture in Week 12 and attend the Week 12 Tutorial, which will help you solve the
above problems and write the add method to correctly insert elements into the OrderedList.


7

Removing elements from the OrderedList

When an element is removed from the OrderedList, some of the other elements inside the
OrderedList may need to be shifted so that there is no hole inside the array. For example, if
we already had the following OrderedList of strings (with corresponding priorities in
brackets) in the following order:

“A” (91), “B” (57), “C” (13), “D” (6)

and then the string “B” is removed, the OrderedList should now look like this:

“A” (91), “C” (13), “D” (6)

And the array should now have a length of 3, not 4.

To properly remove an element, you need to do a number of things:

 Remove the correct element from the OrderedList
 Shift some elements over so that there is no “hole”
 Make the array smaller so that the length of the new array is the same as the number
of elements in the OrderedList.

See the lecture in Week 12 and attend the Week 12 Tutorial, which will help you solve the
above problems and write both the remove methods, as well as the removeHighestPriority
method to correctly delete elements from the OrderedList.


Differences between the OrderedList and ArrayList

It should be possible to add, get and remove any kind of object to or from your OrderedList.
However, it will not possible to directly add, get or remove primitive data like with an
ArrayList.

When getting or removing objects from an OrderedList, it is necessary to cast them into the
specific class type that they are, because when we write the get or remove methods, they will
have a return type of Object. We will learn much more about this in week 12, but for now,
just follow this example. If we have already created an ArrayList or OrderedList called list,
it contains Account objects, and we are getting elements from the list, we can write code like
this if it was an ArrayList, but not if it is an OrderedList:

Account a = list.get(i);

Instead, if list is an OrderedList, we have to write code like this:

Account a = (Account) list.get(i);

8

That is, we have to tell Java that specifically, the thing that is inside the list is an Account.


Illegal Operations

The following operations are illegal, and must throw an exception when they occur:

 The get method is called with an index parameter that does not exist. For example, if
there are only 3 elements in the OrderedList, then only elements at indices 0 to 2 can
be accessed; all other indices do not exist.
 The getPriority method is called with an index parameter that does not exist.
 The remove method is called with an index parameter that does not exist.

If the OrderedList is empty, then calling any of the following methods should throw an
Exception:

 getHighestPriorityElement()
 removeHighestPriorityElement()
 getHighestPriority()

If any of the above illegal operations occur, then your OrderedList class must throw an
exception, just like how the ArrayList class would in the same situation. In other words, you
should NOT have any try or catch blocks in the OrderedList class. Therefore, your code
will throw an exception anyway when trying to access an element at an index that does not
exist.

However, for all other operations (which are legal), your code should never throw an
exception.


Assumptions to make Part 3 Easier

To make Part 3 of the Assignment easier and clearer, you can make the following
assumptions. Therefore, when your code is marked and tested, these assumptions will also be
made:

 A particular element (object) will never be inserted into an OrderedList if it is
already in there. That is, an OrderedList will not have more than 1 of its elements
being the same copy of an element. Therefore, when you write the add method, you
don’t have to check to see if the element already exists in the OrderedList. Also,
when the remove(Object) and changePriority(Object, double) methods are called,
you may assume that there can never be more than 1 such element in the
OrderedList.
 null will never be inserted into an OrderedList. Therefore, there should never be
‘holes’ in your array as described in the lectures in week 12.

9

Marking Scheme

The combination of Parts 0, 1, 2 and 3 of the Assignment is worth a total of 30 marks, or
15% of the assessment of this course. This marking scheme will be followed strictly, and will
emphasize accuracy and correctness, as well as clarity. Therefore, marks will be deducted
even for small errors. In addition to the marking scheme below, marks may be deducted if
students fail to follow the simple instructions in the assignment description.


Comments and Coding Style [7 marks total]

These marks may be limited depending on how much of the assignment is completed. For
example, if a student does not complete Part 3 of the assignment, then of course they cannot
score 7 out of 7 marks in this section.

 [7 marks]
o Clear and unambiguous comments. Comments should be written for:
 All classes (class-header comments)
 All non-accessor methods (write method-header comments)
 For each instance and static variable
o Comments are descriptive. Most lines of code are well explained so that they
can be understood immediately.
o Complex pieces of code are easily understood without any possibility for
confusion. See sample solutions for tutorial exercises and attend the Week 12
Tutorial for more specific perfect examples.
o Simple and good programming style (other than comments)
o No code repetition
o No large methods with too many lines of code
o Consistent and clear indentation and layout (e.g. blank lines above comments)
o Clear and meaningful variable, method and class names
o Following of Java naming conventions
o Appropriate usage of variables (excessive and unnecessary variables are not
used), etc.
o The code is written as simple as possible so that each part of the code can be
quickly and easily understood. See sample solutions for tutorial exercises and
attend the Week 12 Tutorial for more specific perfect examples.


Part 0 of the Assignment only [2 marks total]

 [2 marks] The class is correctly and logically implemented. It follows the rules as
given in the assignment description. It makes sense to create objects of that type to
represent that type of thing. The class is simple and makes sense.


10

Part 1 of the Assignment only [7 marks total]

 [5 marks] The code-cliché methods are written correctly. Loss of at least 1 mark for
each code cliché that is not perfect (does not work for all scenarios).
 [2 marks] The code-cliché methods are used correctly in basic testing.


Part 2 of the Assignment only [7 marks total]

 [3 marks] The program works as it should, as described above. The user can perform
the necessary operations and find out the necessary information. The code clichés are
used correctly.
 [3 marks] Exceptions are handled correctly, so that the program never crashes, no
matter what the user types, or what unusual circumstances occur (e.g. user tries to
read from a file that does not exist, or user tries to change the priority of an element
that is not in the list, etc.)
 [1 mark] The program is easy to use and understand for a person who knows nothing
about programming. It is intuitive to use, simple and clear. Appropriate messages
appear when necessary, so that the user understands what has happened without
having to make any assumptions. For example, if an operation succeeds or fails, the
user is notified.


Part 3 of the Assignment only [7 marks total]

 [6 marks] The methods are correctly implemented. 6 marks will be awarded for code
that works properly for all cases, including unusual cases. 0 marks will be awarded if
very few methods are correctly implemented. Objects of any type can be stored in the
OrderedList without modifying the code. Code in the OrderedList class never
throws an exception (causes the program to crash) except in these circumstances
(when they must throw an exception):
o The get method is called with an index parameter that does not exist
o The remove method is called with an index parameter that does not exist
o The getHighestPriorityElement method is called when the OrderedList is
empty
o The removeHighestPriorityElement method is called when the OrderedList
is empty
o The getHighestPriority method is called when the OrderedList is empty
 [1 mark] Appropriate choice of instance variables and static variables. Redundant
variables are not used. Constants are used to make the code easier to read.


11

Submission Instructions

You must do ALL of the following, in this order:

1) Save your work. Make sure all of your .java files are saved.

2) Make a zip file containing all your work:
 Click on and go inside the folder where your work is saved
 Select the files that you want to submit:
o Hold down CTRL on the keyboard, then click on each file that you want to
submit
o Only select files that say “JAVA File” in the “Type” column;
so do not select any .class files or any other files
o All your work should be in one folder, and not in subfolders;
e.g. do not have one smaller folder for each part of the assignment
o Right-click on the files you selected, select 7-Zip, then select the second-last
option Add to “ass.zip” (assuming that you are in a folder called ass)
o A new .zip file should be created in your folder, which will end in .zip
o Right-click on this .zip file, then select Rename, then change the name to be
the same as the student ID numbers of the group members. E.g. if your student
ID numbers of the students in your group are 19012345S and 19067890S,
then your filename should be 19012345S_19067890S.zip

3) Only after you have done step 2 above, open a web browser, and login to Moodle
 Only 1 person in the group should submit the assignment
 Click on SEHS2307 Computer Programming Concepts
 In the middle of screen, click on Assignment
 Continue following the instructions, including selecting your zip file to upload

4) Only after you have done step 3 above, send an email to [email protected]
 Again, only 1 person in the group should send this email with the project attached
 Use your SPEED email account
 Attach your zip file to the email (as a copy, not using an online cloud / drive)
 In the subject of the email, as well as in the body of the email, write the full names
(with family name in capital letters) of each student in the group. Do not write
anything else in the email body (it will not be read). For example, in both the subject
as well as the body of the email, just type:

Jason CHAN
Santa CLAUS

Continued on next page →

12

5) Each person in the group should then go somewhere privately (where other group
members cannot see) and write a separate email to [email protected] (use your
SPEED email account). Your email should contain the following information:
 The subject of the email should be your full name, with your family name in capital
letters, e.g. Jason CHAN
 In the body of the email, give the full name of each group member, including yourself
 For each group member (including yourself), give a score out of 100, which indicates
in your opinion, how much work that group member did in the project
o 100 means that no one else did more work than this person
o 50 means that this person did about half the amount of work of the person
who did the most work
o 0 means that this person did no work at all
o You can use any number from 0 to 100 for each group member, and you can
use different numbers for each group member
 For each group member (including yourself), describe generally what that group
member did in the group project, e.g. “Did Part 1, wrote class ABC, was often late to
meetings, etc.”
This information will be used to decide the marks that should be received by each group
member.

6) Save a copy of your work for yourself (e.g. on your USB, or email to yourself). Do not
modify it ever again, because the feedback that you will receive with your marks will refer to
line numbers in your code, etc. Do not modify it ever again or give it to anyone else outside
of the group.

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468