IOO Semester 1 2021 Assignment Part 2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Department of Computer Science and Information Technology

La Trobe University

CSE1IOO/4IOO Semester 1, 2021 30%


Assignment 2
This is an individual Assignment. You are not permitted to work as a Pair Programming partnership or
any other group when writing this assignment.

Due Date
Due : Friday 21st of May 2021 at 10.00 a.m.

Delays caused by computer downtime cannot be accepted as a valid reason for a late submission without
penalty. Students must plan their work to allow for both scheduled and unscheduled downtime.

Copying, Plagiarism
Plagiarism is the submission of somebody else’s work in a manner that gives the impression that the work
is your own. The Department of Computer Science and Information Technology treats academic
misconduct seriously. When it is detected, penalties are strictly imposed. Refer to the subject guide for
further information and strategies you can use to avoid a charge of academic misconduct. All submissions
will be electronically checked for plagiarism.

You may be asked to give an interview through zoom and explain your code, if found suspicious
by the plagiarism checker on the submission server. Failing to demonstrate proper understanding
of your program may result in zero marks awarded for the assignment.

Assessment Objectives
 To learn from feedback
 To practise using Interfaces
 To practise using Recursion
 To practise using Linked Lists

Submission Details and marking


Full instructions on how to submit electronic copies of your source code files from your latcs8 account are
given on page 2. If you have not been able to complete a program that compiles and executes containing
all functionality, then you should submit a program that compiles and executes with as much functionality
as you have completed. (You may comment out code that does not compile.)

Marking summary
This assignment is worth 30% of your final mark in this subject.
Implementation 50%, execution of code 50%

Instant zeros or heavily reduced marks Not submitting code


Not able to explain code that has not been taught yet
Using classes not listed on Page 2
Does not run on latcs8
Uses System.exit()
See Marking Guide for others

Marking Scheme
Provided on LMS in a separate document.

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 1 of 13


Using code not taught in IOO
Please also note carefully that whilst we encourage innovation and exploring java beyond what has been
presented in the subject to date, above all, we encourage understanding.

All of the Tasks that follow can be solved using techniques that have been presented in lectures, lecture /
workshops and labs so far.

These are the techniques and knowledge that we will later be examining in the exam (60 marks).

Code and techniques that are outside the material presented will not be examined, of course.

For demonstrating the knowledge taught in this subject, you can only use the standard classes (and
subclasses of such) below and user defined classes.

String, File, Scanner, Math, Exception, FileOutputStream, ObjectOutputStream


FileInputStream, ObjectInputStream and System

Electronic Submission of the Source Code


 Submit all the Java files that you have developed in the tasks above.
 The code has to run under Unix on the latcs8 machine.
 You submit your files from your latcs8 account. Make sure you are in the same directory as the files
you are submitting. Submit each file separately using the submit command.

submit IOO FileName.java

eg.

submit IOO Adventure2.java

File to submit:

After submitting the files, you can run the following command that lists the files submitted from your
account:

verify

You can submit the same filename as many times as you like before the assignment deadline; the
previously submitted copy will be replaced by the latest one.

Please make sure that you have read page 1 about the submission close off date

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 2 of 13


Note – Working Code
The assignment is designed to do in parts. You should not continue to the next part until you are
satisfied that it is working. This ensures that you maintain working code. This is good practice and will
help to ensure maximal marks. Further each part is separated into weeks, meaning you can start this
assignment and build it as you gain more knowledge.

Background - Task
This program will extend assignment 1. This program introduces monsters. The hero can fight a single
monster or can fight a list of monsters. The program will be menu driven.The menu includes the options:
1. Create Hero, 2. Display Hero, 3. Heal Hero, 4. Single Battle, 5. Battle From List, 6. Save Hero to File,
7. Load Hero From File.

Background – "No information provided"


Where you see "no information provided" you must implement the given method in a professional standard
approach based on what you have been taught in OOF and IOO.

Background – Additional Methods, Attributes and Classes

You can only add public static methods or private methods to the classes given. (Including
those from Assignment 1) (except instructed methods)

You can only add private final attributes to the classes given (Including those from
Assignment 1). (except instructed attributes)

You can add other classes if you find it necessary.

You cannot use public or protected attributes anywhere

You cannot change the signature of methods if given. (Including those from Assignment 1)

You cannot use System.exit()

Background – Additional Features


This is YOUR assignment, make it YOURS

You are very welcome and encouraged to design the user interface however you like as long as it conforms to
the marking criteria of assignment 1 and 2, and is clear, usable and contains the same features.

You are very welcome and encouraged to design the user prompts however you like.
Including extra information in the battle is fine. Eg. Health bar.

You are very welcome to change the number of save files.

If you want to add a feature and are not sure if it will interfere with the marking, just ask.

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 3 of 13


Part 1 – Learning from feedback
1.1 – Follow below instructions
No solution is given for assignment 1, rather marks will be awarded for the implementation of the parts from
assignment 1. This is to gain knowledge from feedback. This is essential for assignment 2 and need to be fixed
before continuing. (See marking guide)

Part 2 – Small Changes for Assignment 2 and backing up


2.1 – Follow below instructions

Make a new directory for assignment 2 and copy assignment 1 solution into this folder.

Rename the Adventure.java file to Adventure2.java, make the necessary changes inside the file to reflect
the new class name Adventure2

Change the menu in the Adventure2 class as shown below

Create two methods in the Adventure2 class, and leave the body empty for now

private void singleBattle()


private void battleFromList()

Update process to reflect the changes.

The program should still compile!!! Don't continue if it doesn't!

2.2 – Follow below instructions

In the Inventory class

Add the method


public void addPotions(Inventory otherInventory)
that adds the amount of potions in otherInventory into the objects potions

In the Hero class and subclasses,

Add a new attribute, the attribute is an int, named 'nextLevelExperience'

This needs to be added to the constructors (including in the subclasses)


It should be set to 100 in the default constructor.

You must also create an accessor for this attribute.

Modify, incrementLevel such that when it is called nextLevelExperience is doubled.

Modify, gainExperience in both Archer and Hero, to use nextLevelExperience instead of


1000 (used in previous assignment)

Add a method void addPotions(Inventory otherInventory) that calls addPotions from the inventory
attribute and passes otherInventory into the method

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 4 of 13


In the Adventure2 class,
Modify saveHero and loadHero to include this new attribute

The program should compile at this point, and the hero should be able to be saved and loaded! Double
check!

Part 3 – Interfaces (Week 8)


3.1 - Create the Interfaces as described below.

Damageable – has one abstract method named takeDamage that returns a boolean and accepts an int
Fightable – has one abstract method named attack that returns an int
BattleReady - that extends both Damageable and Fightable, and has two abstract methods, getHealth that
returns an int and getName that returns a String

3.2 – Modify Hero as described below

Hero should now implement BattleReady


Add the appropriate methods:
takeDamage and getHealth should already be implemented. (See assignment 1)

attack – all Heros use the same attack method, it should return:
Math.Random multiplied by 100 multiplied by level and the result cast to an int
getName – this should return 'Archer' if the Hero is an Archer, 'Mage' if the Hero is a Mage or 'Warrior' if
the Hero is a Warrior. Think carefully about how you implement this (Should this be an abstract method or
not in Hero class?)

3.3 – Create the Class as described below.

Create the class named Monster that implements BattleReady

It has three attributes, name, health and level, with types String, int and int respectively.

The name and level should be able to be passed to the constructor. The health should be set as
100*level when constructed

Create appropriate accessors.

You will need a mutator for health

takeDamage should be the same implementation as in Hero

attack should return:


(Math.Random multiplied by 100 multiplied by level) then divided by 3 and the result cast to an int

Two other methods are to be created:


rewardExperience that should return level multiplied by 25

rewardPotions that should return an Inventory


The Inventory should have
small potions equal to (int)(level-Math.random()*level/6)
medium potions equal to (int)(level-Math.random()*level/2)
large potions equal to (int)((level-level/2)-Math.random()*(level-level/2))

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 5 of 13


Part 4 – Recursion (Week 7)
4.1 – Create the Method in Adventure2 class as described below

The signature for the method MUST be as follows (0 marks for this section if it is not)

private boolean battle(BattleReady fighter1, BattleReady fighter2)

This method MUST use recursion (0 marks for this section if it is not)

Each fighter (fighter1 and fighter2) attacks in turns.


fighter1 always attacks first
The amount of damage must be shown for each attack (include the name of the fighter)
And the health remaining must be shown after each attack (if the fighter does not faint)
If the fighter does not have any health remaining then it must show that they fainted

The fight continues until one fighter faints (both should not faint!)

If figher1 faints false is returned, else if fighter2 faints then true is returned.

You are welcome to use either Indirect or Direct recursion. (For indirect create two more methods and call
from this method)

There should be no more than 2 'fights' in the method if using direct, and no more than 1 in each method
if using indirect.

4.2 – Implement the Method in Adventure2 class as described below

Write the singleBattle method, such that if no hero exists the user is informed.
The monsters name and level is read from the user(range of level between 1-20,
use readInt created in assignment1)
The function should exit after 5 invalid entries. (You do not have to validate the name, just the level)
Instantiate the monster using values entered.

Using your battle method,


if the heros level is less than the monsters level then
battle(hero, monster)
else
battle(monster, hero)

Don't forget to store the result of the battle.

If the hero losses the battle, hero is set to null, and the user is informed they will need a new hero

Else the reward expierence is given to the hero (use gain experience) and is shown on screen (show also
if they levelled up) (You do not have to show the bonus expierence)

And the reward potions is given to the hero (use addPotions) and shown on screen

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 6 of 13


Example Executions:

You may want to use keyboard.nextLine() to make the user press enter between turns

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 7 of 13


Part 5 – Linked Lists (Week 9)

5.1 – Create the Classes described below

Create a MonsterNode class, that stores a Monster, and the next MonsterNode
(You should not have name, health or level attributes in the MonsterNode class!)

Create a MonsterList class, that stores the MonsterNode head

Create the following methods in the MonsterList class:


A constructor – to initialize head
insertAtFront – takes a Monster and inserts in the front of the list
void insertAtFront(Monster monster)
removeEnd – returns the Monster from the last node of the list and removes it from the list
Monster removeEnd()
getHead – returns the node at the start of the list
MonsterNode getHead()

5.2 – Create the method battleFromList in the Adventure2 class

If no hero exists the user is informed.


Else Create a new MonsterList
DoWhile (Not a for loop) Ask the user for the monsters name and level (include integer validation) and add
the monster to the list. Ask the user if they would like to enter another monster, if Y continue, else stopping
looping.
DoWhile (Not a for loop) The hero battles the monster at the end of the list, if the hero is a lower level they go
first else the monster goes first (order of arguments in call to battle). If the hero wins, experience and potions
are awarded as in Section 4, and keep looping until the list is empty OR if the hero faints.

Example Executions:

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 8 of 13


IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 9 of 13
IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 10 of 13
Some More Execution Examples
Note – Menu is hidden in the following examples to improve clarity. Menu should appear as shown below:

This examples are only examples and do not show all execution, you should test on many different test cases

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 11 of 13


IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 12 of 13
Final notes
Do a little bit every night; before you know it you will be finished. The assignment is marked with running
code, so you are better to have 1 or 2 Tasks completed that actually compile and run, rather than a whole
lot of code that doesn't compile.

The execution test is done on latcs8 so please make sure that your code runs on latcs8 before you
submit.

IOO Assignment 1 - due: Friday 21st of May 2021 at 10.00 a.m p. 13 of 13

You might also like