Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Java Programming Assignment IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther Java Programming Assignment Introduction to Information Technology/G 4478/8936 Note 1: Only use Java classes that...

1 answer below »
Java Programming Assignment
IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther
Java Programming Assignment
Introduction to Information Technology/G 4478/8936
Note 1: Only use Java classes that are part of the standard Java SE SDK distribution! For
the purpose of this assignment, you are not allowed to use any third party classes except
for UCanAccess
1
if you attempt stage 4.
Note 2: Familiarise yourself with the Java Style Guide at the end of this document.
Note 3: All cases of plagiarism will be pursued! If in doubt, consult the Student
Academic Integrity Policy http:
www.canbe
a.edu.au/cu
ent-students/canbe
a-
students/conduct
The context for this assignment (all parts) is an examination of the growth rates of
species in a given habitat. This assignment will test a student’s knowledge of and skills in
writing application software for a particular task, understanding the business rules of a
particular problem, coding these in a computer program, developing a graphical user
interface, reading data from a text file on disk, and connecting to an SQL database from
within the program. As such, the assignment requires you to integrate and synthesise
what you have learnt so far, in order to design and create a co
ectly working solution.
For this assignment, students will use the Java programming language and development
will be on the Eclipse IDE platform as practised in the computer lab classes. This
assignment consists of four stages, with different requirements for undergraduate students
in 4478 Introduction to IT and for graduate / postgraduate students in 8936 Introduction
to IT G.
 Stage 1: A simple console program (no GUI)
 Stage 2: The same but wrapped in a GUI
 Stage 3: Input comes from a text file – read only once, then information stored in
a suitable data class, a
ay, etc.
 Stage 4: Input comes from an SQL database file.

4478 IIT 8936 IIT G
Part A – Stage 1 (25 marks) Part A – Stages 1 and 2 (27 marks)
Part B – Stage 2 (10 marks) Part B – Stage 3 (13 marks)
Part C – Stage 3 (15 marks) Part C – Stage 4 (10 marks)
Bonus* – Stage 4 (up to 10 marks)
*Stage 4 is a bonus stage for undergraduate students to give you a stretch target. It allows
you to pick up extra marks to make up for marks lost elsewhere in the assignment, but
note that you cannot achieve more than 50/50 marks.

1 http:
ucanaccess.sourceforge.net/site.html
IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther
Population Calculator

Preamble: A client has approached you with a request to write a software application to
calculate the number of specimens in a habitat after a given number of generations, given
a starting population and two different ways for the population to grow.
a) The first scenario is that the number of specimens grows by a given percentage in
each generation (i.e. fixed growth rate, variable number of generations)
) The second way for the population to grow is by a varying rate each generation,
for ten generations. (i.e. variable growth rate, fixed number (10) of generations)
In each scenario, you’re required to calculate the final population after the given number
of generations has elapsed and then calculate the number of specimens that will die due
to overpopulation.

A Worked example: In a hypothetical habitat the growth rate of a particular species per
generation is given as a percentage of its population. For example, if the number of fish
in a pond at the start is four and the growth rate is 50%, after one generation there are six
fish (4*1.5 or 4+4*50/100), after two generations there are nine fish (6 * 1.5) and so on.

At beginning, population of the pond = 4
After generation 1, population of the pond = 4 + (4*50/100) = 6
After generation 2, population of the pond = 6 + (6*50/100) = 9 …
If the number of specimens doubles in every generation, the growth rate is 100%.
Note that the habitat has a limited ca
ying capacity (5000 for part A). Any specimens
spawning over that number will die due to overpopulation. (For simplicity we assume
that they die due to overpopulation only after the prescribed number of generations has
elapsed.)
NOTE: For simplicity we assume the population to be an integer value.
Test Cases

When designing and implementing software applications, it is always important to first
work out how to test the program(s) and what data to use, then to code. The following
test cases have been designed to systematically test different conditions in the above
ules. Use these to test your program, but make sure that your program can also handle
other data, including negative growth in one or more generations.
IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther
Test Description Option Starting
Population
Number
of
Generati
ons
Growth Rate Final
Population
(integer)
Died
(inte
ger)
Fixed rate (doubling);
under habitat capacity
F XXXXXXXXXX
Fixed Growth (80% each
generation); over habitat
capacity
F XXXXXXXXXX
Variable Growth; no
growth; under habitat
capacity
V XXXXXXXXXX,0,0,0,0,0,0,0,
0,0
10 0
Variable Growth, under
habitat capacity
V XXXXXXXXXX,20,25,30,50
,70,60,80,50,2
3746
0
Variable Growth; over
habitat capacity
V XXXXXXXXXX,100,80,70,
60,100,10,20,5
,85
XXXXXXXXXX
Submission Instruction

Add all Java files (ending in .java) to a ZIP file. You do not need to zip the entire project
folder, just the Java source file(s) (the ‘src’ folder). Submit the ZIP file via Canvas (max.
size 10MB). Click the submit button to upload the zipped file and submit assignment.
Stage 1:
Write a simple Java program to calculate the number of fish in a pond after a number of
generations. The pond has a capacity of 5000 fish. ). In Stage 1, you will be developing a
Java program without a GUI. Input and output are via the console.
When the program is executed, the user will first input whether the calculation is of fixed
ate of growth (F) or variable rate of growth (V). Then, depending on the user input, the
program will
anch out to execute either Section 1 or Section 2 as follows;
Section 1 (Fixed rate of growth)
The program must then request the user to input the starting population, number of
generations and the rate of growth. At a minimum, when your program is run, the
terminal window must display (with words that explain each number) the values of the
starting population, the rate of growth (as a percentage) the CAPACITY of the pool, the
IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther
number of generations the program was run for, and whether or not there is still room in
the pond. If the pond becomes full, also state how many fish died from over-population.
Section 2 (Variable growth rates)
The program must then request the user to input the starting population and the 10 rates
of growth for the consequent generations. E.g.
XXXXXXXXXX XXXXXXXXXX
Step-by-Step Guide for Stage 1

1. Think about your strategy for how you will calculate the population after each
generation. Is the growth rate fixed or variable? For a fixed growth rate (section
1), how many generations will the program run for? What is the final population?
How many fish died? Hint: those over the capacity of the pond. For section 2, you
need different rates for each generation. Different strategies are possible. Here is
one:
a. Use an integer a
ay of 10 elements to store the different growth rates.
. Once the values for the growth rates have been entered by the user via the
console and stored in the a
ay, multiply the cu
ent population by the
growth rate and add the resulting number to the ‘cu
ent’ population,
creating the new value for the population. Note that you can’t have part of
a fish!
2. Create a new Java project.
3. Add a simple Java class named Stage1. Do not add a GUI.
4. In the Stage1 class (file Stage1.java), you may put all code for the user
interaction and the calculation into the main method. (You might still need to
define global variables and constants outside the main method at the start of the
class.) Declare and instantiate the variables that you will need for section 1
IIT/IIT G Java 2018 S1 r1 - Adapted from Trish Crowther
(starting population, number of generations). For section 2 you will also need an
integer a
ay that will hold the growth rates, at the start of the main method, for
example:

int[] iaGrowthRate = new int[10];
Add code to read in the starting population, then the ten values for each
generation’s growth rate from the console. In Java, there are different ways to do
this. A recommended way is to use the Scanner class:

Scanner inConsole = new Scanner(System.in);
Read the starting population
System.out.println(“Enter the starting population of
fish”);
iStart = inConsole.nextInt();
Ask whether the growth rate is fixed or variable
System.out.println(“Enter F for fixed growth, V for
variable”)
cOption = inConsole.next().charAt(0);
Read the fixed growth rate
iRate = inConsole.nextInt();
Variable Growth
First growth rate for generation 1
System.out.print(“Enter the growth rate for generation
one: ”);
iaGrowthRate[0] = inConsole.nextInt();
Repeat (and adapt) the last two lines for the other growth rates for the next nine
generations.
5. Now add the code that implements your strategy of calculating the final
population of fish.
6. Finally, add two System.out.println() statements that state the final
Answered Same Day Apr 13, 2020

Solution

Snehil answered on Apr 16 2020
135 Votes
Population Calculato
.classpath

    
    
    
Population Calculato
.project

     Population Calculato
    
    
    
    
        
             org.eclipse.jdt.core.javabuilde
            
            
        
    
    
         org.eclipse.jdt.core.javanature
    
Population Calculato
.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=e
o
org.eclipse.jdt.core.compiler.problem.enumIdentifier=e
o
org.eclipse.jdt.core.compiler.source=1.8
Population Calculato
in/com/pop/calc/PopData.class
package com.pop.calc;
public synchronized class PopData {
private String sSpeciesName;
private String sHabitat;
private int iStartingPopulation;
private int[] iaGrowthRates;
public void PopData(String, String, int, int[]);
public String getSpeciesName();
public void setSpeciesName(String);
public String getHabitat();
public void setHabitat(String);
public int getStartingPopulation();
public void setStartingPopulation(int);
public int[] getGrowthRates();
public void setGrowthRates(int[]);
}
Population Calculato
in/com/pop/calc/Stage1.class
package com.pop.calc;
public synchronized class Stage1 {
static final int MAX_CAPACITY = 5000;
static final int NUM_GEN = 10;
public void Stage1();
public static void main(String[]);
static void calculateFixedRateGrowth(int, int, int);
static void calculateVariableRateGrowth(int, int[]);
}
Population Calculato
in/com/pop/calc/Stage2GUI$1.class
package com.pop.calc;
synchronized class Stage2GUI$1 implements Runnable {
void Stage2GUI$1();
public void run();
}
Population Calculato
in/com/pop/calc/Stage2GUI$2.class
package com.pop.calc;
synchronized class Stage2GUI$2 implements java.awt.event.ActionListener {
void Stage2GUI$2(Stage2GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage2GUI$3.class
package com.pop.calc;
synchronized class Stage2GUI$3 implements java.awt.event.ActionListener {
void Stage2GUI$3(Stage2GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage2GUI$4.class
package com.pop.calc;
synchronized class Stage2GUI$4 implements java.awt.event.ActionListener {
void Stage2GUI$4(Stage2GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage2GUI$5.class
package com.pop.calc;
synchronized class Stage2GUI$5 implements java.awt.event.ActionListener {
void Stage2GUI$5(Stage2GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage2GUI$6.class
package com.pop.calc;
synchronized class Stage2GUI$6 implements java.awt.event.ActionListener {
void Stage2GUI$6(Stage2GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage2GUI.class
package com.pop.calc;
public synchronized class Stage2GUI {
private final int MAX_POP;
private final int NUM_GEN;
private javax.swing.JFrame jFrame_MainFrame;
private javax.swing.JTextField jTextField_StartingPopulation;
private javax.swing.JTextField jTextField_NumGenerations;
private javax.swing.JTextField jTextField_FixedRate;
private javax.swing.JTextField[] jTextFieldA
ay_VariableGrowthRates;
private final javax.swing.ButtonGroup buttonGroup_RateChoice;
private javax.swing.JRadioButton jRadioButton_FixedGrowth;
private javax.swing.JLabel jLabel_FinalPopulationResult;
private javax.swing.JLabel jLabel_NumFishDied;
public static void main(String[]);
public void Stage2GUI();
private void initialize();
private void SelectFixedToggle(boolean);
}
Population Calculato
in/com/pop/calc/Stage3GUI$1.class
package com.pop.calc;
synchronized class Stage3GUI$1 implements Runnable {
void Stage3GUI$1();
public void run();
}
Population Calculato
in/com/pop/calc/Stage3GUI$2.class
package com.pop.calc;
synchronized class Stage3GUI$2 implements java.awt.event.ActionListener {
void Stage3GUI$2(Stage3GUI);
public void actionPerformed(java.awt.event.ActionEvent);
}
Population Calculato
in/com/pop/calc/Stage3GUI$3.class
package com.pop.calc;
synchronized class Stage3GUI$3 implements javax.swing.event.ListSelectionListener {
void Stage3GUI$3(Stage3GUI, javax.swing.JList, javax.swing.JLabel, javax.swing.JLabel, Stage3GUI$DrawingPanel);
public void valueChanged(javax.swing.event.ListSelectionEvent);
}
Population Calculato
in/com/pop/calc/Stage3GUI$DrawingPanel.class
package com.pop.calc;
synchronized class Stage3GUI$DrawingPanel extends javax.swing.JPanel {
private final int BAR_WIDTH;
private final int BAR_WIDTH_MARGIN;
private int[] iaGrowthRateHeights;
private int[] iaBarPostions;
private int iOldMin;
private int iOldMax;
private int iNewMin;
private int iNewMax;
private int iAvg;
public void Stage3GUI$DrawingPanel(Stage3GUI, int);
public void setBarGraphData(int[]);
public void paintComponent(java.awt.Graphics);
private int getValueInRange(int);
}
Population Calculato
in/com/pop/calc/Stage3GUI.class
package com.pop.calc;
public synchronized class Stage3GUI {
private final int MAX_POP;
private final int NUM_GEN;
private javax.swing.JFrame jFrame_MainFrame;
private javax.swing.JTextField[] jTextFieldA
ay_VariableGrowthRates;
private javax.swing.JLabel jLabel_FinalPopulationValue;
private javax.swing.JLabel jLabel_NumFishDied;
private java.util.Vector vPopData;
public static void main(String[]);
public void Stage3GUI();
private void readFile(String);
private void initialize();
}
Population Calculato
growth.txt
Fish;Pond;10;100,100,80,70,160,75,80,100,50,67
Rats;Shed;6;115,120,125,80,50,70,110,80,50,2
Mice;Barn;8;80,80,50,30,20,10,-5,20,40,10
Bacteria;Petri Dish;300;200,150,100,30,5,50,4,70,50,10
Snakes;Island;12;20,21,22,17,50,60,70,80,20,40
Ra
its;Farm;24;166,150,150,130,140,120,130,150,160,160
Stoats;Forest;10;90,80,90,75,60,15,18,18,17,15
Bats;Belfry;20;50,18,17,20,25,30,15,-10,10,8
Cats;Abandoned House;6;200,150,100,100,80,70,60,10,5,5
Money;Account;1000;2,3,3,2,3,3,5,10,6,5
Population Calculato
src/com/pop/calc/PopData.java
Population Calculato
src/com/pop/calc/PopData.java
package com.pop.calc;
public class PopData 
{
    private String sSpeciesName;
    private String sHabitat;
    private int iStartingPopulation;
    private int[] iaGrowthRates;
        
    
    public PopData(String sSpeciesName, String sHabitat,int iStartingPopulation, int[] iaGrowthRates) 
    {
        this.sSpeciesName = sSpeciesName;
        this.sHabitat = sHabitat;
        this.iStartingPopulation = iStartingPopulation;
        this.iaGrowthRates = iaGrowthRates;
    }
    
    public String getSpeciesName() {
        return sSpeciesName;
    }
    
    public void setSpeciesName(String sSpeciesName) {
        this.sSpeciesName = sSpeciesName;
    }
    
    public String getHabitat() {
        return sHabitat;
    }
    
    public void setHabitat(String sHabitat) {
        this.sHabitat = sHabitat;
    }
    
    public int getStartingPopulation() {
        return iStartingPopulation;
    }
    
    public void setStartingPopulation(int iStartingPopulation) {
        this.iStartingPopulation = iStartingPopulation;
    }
    
    public int[] getGrowthRates() {
        return iaGrowthRates;
    }
    
    public void setGrowthRates(int[] iaGrowthRates) {
        this.iaGrowthRates = iaGrowthRates;
    }
}
Population Calculato
src/com/pop/calc/Stage1.java
Population...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here