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