FIT9131 Semester 1 2020 FIT9131 XXXXXXXXXXSemester 1 2020 1 XXXXXXXXXX11/05/2020 Assignment 2 Koala Rescue Introduction This assignment is due by 10pm AEST Friday of Week XXXXXXXXXXJune, 2020). This...

1 answer below »
I want to get this assignment done on BlueJ. I have attached the specification file. i want it to be done exactly as specified in the document.


FIT9131 Semester 1 2020 FIT9131 Semester 1 2020 1 11/05/2020 Assignment 2 Koala Rescue Introduction This assignment is due by 10pm AEST Friday of Week 12 (12 June, 2020). This assignment is worth 25% of the marks for your final assessment in this unit. Heavy penalties will apply for late submission. This is an individual assignment and must be your own work. Please note the section on plagiarism in this document. In preparing your assignment please note the following: o The assignment must be done using the BlueJ environment. o The Java source code for the assignment must be implemented according to the FIT9131 Java Coding Standards. o You must acknowledge all code in your assignment that you have taken from other sources. o Only a text interface is to be used for this program, there is to be no GUI. More marks will be gained for a game that is easy to follow with clear information/error messages. Any points needing clarification may be discussed with your tutor in the lab classes. You should not make any assumptions about the program without consulting your tutor. Completion of this assignment contributes towards the following FIT9131 learning outcomes: 1. design, construct, test and document small computer programs using Java; 2. interpret and demonstrate software engineering principles of maintainability, readability, and modularisation; 3. explain and apply the concepts of the "object-oriented" style of programming. Specification For this assignment you will simulate the work of a koala rescue team. This section specifies the required functionality of the program. Background The koala is a marsupial and is native to Australia. Koalas typically live in open eucalyptus (gum tree) forests. Koalas live mainly in trees and eat up to 1 kg of leaves per day. Their diet is restricted to a few varieties of gum trees (e.g., Manna Gum, Swamp Gum, Blue Gum, and River https://www.google.com.au/url?sa=i&url=https%3A%2F%2Funsplash.com%2Fs%2Fphotos%2Fkoala&psig=AOvVaw0S5kA9ceCvQxlFsw8JlJ3R&ust=1588322055116000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCPi3m_rej-kCFQAAAAAdAAAAABAD FIT9131 Semester 1 2020 Assignment 2 ________________________________________________________________________ 2 11/05/2020 Red Gum). Koalas use some other varieties of trees (e.g. Wattle) for shelter on hot days. Only one koala at a time will occupy a shelter tree. Whilst moving on the ground between trees, koalas are exposed to attacks from predators. After bushfires in January 2020, several koala reserves were left devastated when forest habitat burnt leaving many koalas dead or injured and without sufficient food. The koala rescue team’s work is to inspect the reserves and provide help to the koalas. Unfortunately, the team operates within a restricted budget and sometimes has to make difficult decisions. The aim of the rescue team is to save as many koalas as possible within a limited budget. The koala reserve consists of a series of observation points where the rescue team pauses, observes the koala population, the trees, and the predators, and decides how the koalas can be helped. The help may be to move a koala to a safe haven if it is injured or there is not enough food or shelter. Koala Rescue Team simulation The Koala Rescue Team simulation begins with a welcome message and an invitation to the rescue team leader to enter his/her name. The name cannot be blank but must be less than 16 alphabetic characters. The leader is then asked to enter the budget for the rescue. This is an amount from $100 to $200, inclusive. The program then sets up the numbers of trees, koalas and predators in each of the 10 observation points as follows: 1. The numbers of trees in the reserve are read from a text file trees.txt. The numbers of each type of tree (Manna Gum, Swamp Gum, Blue Gum, River Red Gum, Wattle) at each observation point are read in from the file. The file has 10 lines, with 5 comma separated numbers on each line. Each line represents the tree numbers at each observation point. There is no other reading from the file during the actual running of the program. Each tree is either used for shelter or food. Each shelter tree can hold a maximum of one koala. The food trees can produce a certain weight of leaves per day that can be eaten by the koalas (see Table 1). The weight is used to calculate the total food available for the koalas at any observation point. The food available is calculated by multiplying the number of each tree type by the weight of leaves it produces and summing these to get the total food available. Each koala, whether healthy or injured, can eat 1 kg of leaves per day. . Table 1 Types of gum trees and weight in Kg of leaves that can be eaten by one koala per day Type of tree Usage Kg of edible leaves per day Manna Gum Food 1.00 Swamp Gum Food 0.34 Blue Gum Food 0.90 River Red Gum Food 0.40 Wattle Shelter 0 2. There is a random number of koalas at each observation point as follows: • 0-9 healthy koalas. • 0-2 injured koalas. Each koala will have a randomly allocated age of 1-18 years. FIT9131 Semester 1 2020 Assignment 2 ________________________________________________________________________ 3 11/05/2020 3. There is a random number of 0-4 predators at each observation point. 4. There are no koalas in safe haven at the start of the rescue. The rescue team visits each of 10 observation points in turn. At each observation point the rescue team considers the number of trees, the number and condition of the koalas (some of which may be injured) and the number of predators. The team takes actions to help the koalas at each point. If the budget runs out at any point then the rescue mission continues but no actions can be taken that involve cost. The rescue mission is considered successful when all areas have been observed and all koalas have survived. Specific observation point actions At each observation point the following actions are performed. 1. The trees are assessed for damage. For each type of tree there is 5% chance that one tree of that type has been burnt or has fallen over. If this happens then the number of trees at the observation point is updated. Note this must happen before the available food and shelter are calculated. (Hint: to calculate a probability of 5% generate a random number from 1 to 20. There will be a 5% chance of any of these numbers being generated. So, you can nominate one number, say 20, and test for that to give you the 5%). 2. The program then displays the status of the observation point and available budget as follows: • the number of injured koalas • the number of healthy koalas • the weight of available food (Each koala eats 1 kg of leaves per day, whether healthy or injured). • the number of shelter trees • the number of predators • the available budget 3. The rescue team assesses the situation and decides what actions to take to aid the koalas’ survival within the available budget. Note that if the rescue budget runs out at any stage then no further actions can be carried out that involve a cost. The following menu options are displayed: A. Move an injured koala to the safe haven – an injured koala can be sent to the safe haven where it can be treated. If an injured koala is not taken to the safe haven then it does not survive. The cost of moving each injured
Answered Same DayJun 04, 2021FIT9131Monash University

Answer To: FIT9131 Semester 1 2020 FIT9131 XXXXXXXXXXSemester 1 2020 1 XXXXXXXXXX11/05/2020 Assignment 2 Koala...

Akriti answered on Jun 09 2021
130 Votes
main/KoalaRescue.class
package main;
public synchronized class KoalaRescue {
public void KoalaRescue();
public static void main(String[]) throws java.io.FileNotFoundException;
private static void initRescue(java.util.Scanner, int) throws java.io.FileNotFoundException;
private static void writeUpdateCountOfTreesToFile(int[][]);
private static int[] toIntArray(String);
}
main/KoalaRescue.ctxt
#BlueJ class context
comment0.target=KoalaRescue
comment0.text=\r\n\ KoalaRescue\r\n\r\n\ @version\ 1.0\r\n\ @since\ 06-Jun-2020\r\n
comment1.params=args
comment1.target=void\ main(java.lang.String[])
comment2.params=in\ budget
comment2.target=void\ initRescue(java.util.Scanner,\ int)
comment3.params=updatedTreesCounts
comment3.target=void\ writeUpdateCountOfTreesToFile(int[][])
comment4.params=line
comment4.target=int[]\ toIntArray(java.lang.String)
numComments=5
main/KoalaRescue.java
main/KoalaRescue.java
package main;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import
 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import rescue.exceptions.BudgetExceededException;
import rescue.exceptions.InvalidOptionException;
import rescue.reserve.Reserve;
/**
 * KoalaRescue
 *
 * @version 1.0
 * @since 06-Jun-2020
 */
public class KoalaRescue {
    public static void main( String[] args ) throws FileNotFoundException {
        System.out.println("Welcome to koala rescue program.");
        System.out.println("Enter rescue team leader name:");
        Scanner in = new Scanner(System.in);
        boolean isNameValid = false;
        String name;
        while (!isNameValid) {
            name = in.nextLine();
            if (name.isEmpty()) {
                isNameValid = false;
                System.out.println("Invalid name.\nEnter name again:");
            }
            else if (name.length() > 16) {
                isNameValid = false;
                System.out.println("Name must be 16 char at max.\nEnter name again:");
            }
            else {
                isNameValid = true;
            }
        }
        System.out.println("Enter budget for rescue:");
        boolean isBudgetValid = false;
        Integer budget = null;
        while (!isBudgetValid) {
            budget = in.nextInt();
            if (budget < 100) {
                isBudgetValid = false;
                System.out.println("Budget not enough to start rescue program.\nEnter a different budget:");
            }
            else if (budget > 200) {
                isBudgetValid = false;
                System.out.println("Too much budget for rescue program.\nEnter a different budget:");
            }
            else {
                isBudgetValid = true;
            }
        }
        in.nextLine();
        initRescue(in, budget);
    }
    private static void initRescue(Scanner in, int budget) throws FileNotFoundException {
        Reserve reserve = new Reserve(budget);
        File observationsFile = new File("main/trees-uj0vkyhe-bupqfoec.txt");
        Scanner reader = new Scanner(observationsFile);
        List observations = new ArrayList<>();
        while (reader.hasNextLine()) {
            observations.add(reader.nextLine());
        }
        reader.close();
        for(int i = 0; i < observations.size(); i++) {
            String observation = observations.get(i);
            reserve.setNewObservationPoint(i, toIntArray(observation));
            // Actions for an observation continues as far as this is active observation is there
            System.out.println("\nObservation No. " + (i + 1));
            while (reserve.getActiveObservationPoint() != null) {
                System.out.println();
                reserve.showObservationRescueStatus();
                reserve.showInstructions();
                String command = in.nextLine();
                try {
                    reserve.command(command);
                }
                catch(InvalidOptionException e) {
                    System.out.println("Only A, B, C & D are valid options. Please try Again.");
                }
                catch (BudgetExceededException e) {
                    System.out.println("Not enough money left for this option.");
                }
            }
        }
        reserve.showRescueMissionResult();
        writeUpdateCountOfTreesToFile(reserve.getUpdatedTrees());
    }
    private static void writeUpdateCountOfTreesToFile(int [][] updatedTreesCounts) {
        try {
            File out = new File("main/updatedTrees.txt");
            if (out.createNewFile()) {
                FileWriter writer = new FileWriter(out);
                for(int[] treeCounts : updatedTreesCounts) {
                    StringBuilder data = new StringBuilder();
                    for(int count : treeCounts) {
                        data.append(count).append(",");
                    }
                    String line = data.toString();
                    writer.write(line.substring(0, line.length() -1));
                    writer.write("\n");
                }
                writer.close();
            }
        } catch (IOException e) {
            System.out.println("An error occurred.");
            e.printStackTrace();
        }
    }
    private static int[] toIntArray(String line) {
        line = line.trim();
        String[] tokens = line.split(",");
        if (tokens.length != 5) {
            throw new IllegalArgumentException("entries of trees in input file for a observations must be 5.");
        }
        else {
            int[] noOfTreesEachType = new int[5];
            for (int i = 0; i < tokens.length; i++) {
                noOfTreesEachType[i] = Integer.parseInt(tokens[i].trim());
            }
            return noOfTreesEachType;
        }
    }
}
main/package.bluej
#BlueJ package file
objectbench.height=92
objectbench.width=761
package.divider.horizontal=0.6
package.divider.vertical=0.8014354066985646
package.editor.height=396
package.editor.width=674
package.editor.x=12
package.editor.y=12
package.frame.height=600
package.frame.width=800
package.numDependencies=0
package.numTargets=1
package.showExtends=true
package.showUses=true
readme.height=58
readme.name=@README
readme.width=47
readme.x=10
readme.y=10
target1.height=70
target1.name=KoalaRescue
target1.showInterface=false
target1.type=ClassTarget
target1.width=100
target1.x=160
target1.y=10
main/trees-uj0vkyhe-bupqfoec.txt
2,4,5,0,6
4,2,1,5,10
3,0,2,6,9
2,1,5,2,8
2,6,5,0,7
0,12,1,2,8
4,2,0,5,4
7,8,10,5,9
2,1,5,2,5
2,3,5,0,4
main/updatedTrees.txt
2,4,5,0,6
4,2,1,5,9
3,0,2,6,9
2,1,4,2,8
2,6,4,0,7
0,11,1,1,8
4,1,0,4,3
7,7,10,4,9
2,0,5,2,5
2,3,4,0,4
package.bluej
#BlueJ package file
editor.fx.0.height=838
editor.fx.0.width=1550
editor.fx.0.x=-7
editor.fx.0.y=-7
objectbench.height=218
objectbench.width=1512
package.divider.horizontal=0.6
package.divider.vertical=0.6953463203463203
package.editor.height=508
package.editor.width=1424
package.editor.x=0
package.editor.y=0
package.frame.height=838
package.frame.width=1550
package.numDependencies=0
package.numTargets=2
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.height=58
readme.name=@README
readme.width=47
readme.x=10
readme.y=10
target1.height=62
target1.name=main
target1.type=PackageTarget
target1.width=80
target1.x=70
target1.y=10
target2.height=62
target2.name=rescue
target2.type=PackageTarget
target2.width=80
target2.x=160
target2.y=10
README.TXT
------------------------------------------------------------------------
This is the project README file. Here, you should describe your project.
Tell the reader (someone who does not know anything about this project)
all he/she needs to know. The comments should usually include at least:
------------------------------------------------------------------------
PROJECT TITLE: Koala rescue
PURPOSE OF PROJECT: To save koalas
VERSION or DATE: 1
HOW TO START THIS PROJECT: Run file main/KoalaRescue.java
AUTHORS:
USER INSTRUCTIONS:
rescue/exceptions/BudgetExceededException.class
package rescue.exceptions;
public synchronized class BudgetExceededException extends Exception {
public void BudgetExceededException();
}
rescue/exceptions/BudgetExceededException.ctxt
#BlueJ class context
comment0.target=BudgetExceededException
comment0.text=\r\n\

\r\n\ BudgetExceededException\r\n\

\r\n\ @version\ 1.0\r\n\ @since\ 06-Jun-2020\r\n
comment1.params=
comment1.target=BudgetExceededException()
numComments=2
rescue/exceptions/BudgetExceededException.java
rescue/exceptions/BudgetExceededException.java
package rescue.exceptions;
/**
 * 


 * BudgetExceededException
 * 


 * @version 1.0
 * @since 06-Jun-2020
 */
public class BudgetExceededException extends Exception {
    public BudgetExceededException() {
        super("Do not have sufficient funds.");
    }
}
rescue/exceptions/InvalidOptionException.class
package rescue.exceptions;
public synchronized class InvalidOptionException extends Exception {
public void InvalidOptionException();
}
rescue/exceptions/InvalidOptionException.ctxt
#BlueJ class context
comment0.target=InvalidOptionException
comment0.text=\r\n\

\r\n\ InvalidOptionException\r\n\

\r\n\ @version\ 1.0\r\n\ @since\ 06-Jun-2020\r\n
comment1.params=
comment1.target=InvalidOptionException()
numComments=2
rescue/exceptions/InvalidOptionException.java
rescue/exceptions/InvalidOptionException.java
package rescue.exceptions;
/**
 * 


 * InvalidOptionException
 * 


 * @version 1.0
 * @since 06-Jun-2020
 */
public class InvalidOptionException extends Exception {
    public InvalidOptionException() {
        super("Invalid Option");
    }
}
rescue/exceptions/package.bluej
#BlueJ package file
objectbench.height=92
objectbench.width=761
package.divider.horizontal=0.6
package.divider.vertical=0.8014354066985646
package.editor.height=396
package.editor.width=674
package.editor.x=32
package.editor.y=32
package.frame.height=600
package.frame.width=800
package.numDependencies=0
package.numTargets=2
package.showExtends=true
package.showUses=true
readme.height=58
readme.name=@README
readme.width=47
readme.x=10
readme.y=10
target1.height=50
target1.name=BudgetExceededException
target1.showInterface=false
target1.type=ClassTarget
target1.width=190
target1.x=10
target1.y=90
target2.height=50
target2.name=InvalidOptionException
target2.showInterface=false
target2.type=ClassTarget
target2.width=170
target2.x=10
target2.y=150
rescue/package.bluej
#BlueJ package...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here