5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 1/3
Java Programs
The following exercises do not require any input from the user but will produce output. Everything
equired to execute the program should be provided in the main() method.
Complete, working, and tested programs are required to solve the following exercises. See Documentation
and Test Plans for required documentation.
In programs 1 to 3, classes have not been specified. You must use Assignment1QuestionN as the class
name and Assignment1QuestionN.java as the file name (where N is 1, 2, or 3).
In programs 4 and 5, class names have been specified. You must use the supplied class name for both class
and source file name (i.e., Animal will be in a file Animal.java).
DO NOT use packages in your programs. All programs for this assignment should reside, compile, and
execute from a single working directory.
1. Write a program that generates 60 pairs of random integers (int) with values between 1 and XXXXXXXXXXFor each
generated pair, use an if-else statement to classify the first value as greater than, less than, or equal to the second
value. For output, display BOTH generated values, as well as the classification, in the format “Number 1
classification > Number 2”, one number pair per output line, where < classification > is one of the phrases “less
than,” “equals,” or “greater than.”
2. Write a program that uses two nested for loops and the modulus operator (%) to detect and print prime numbers.
Prime numbers are integral numbers that are evenly divisible only by themselves and 1. Use your program to print
all the prime numbers from 0 to XXXXXXXXXXPrint 10 numbers per output line, with two spaces after each number.
3. Write a program that creates and initializes a two-dimensional a
ay of primitive type double. The size of the a
ay
is determined by the arguments of the method, and the initialization values are a range determined by the beginning
and ending values that are also arguments of the method (so four arguments total). Create a second method that will
print the a
ay generated by the first method. In main(), test the methods by creating and printing several different
sizes of a
ays.
4. Write a class called Animal with an overloaded sound() method. This method should be overloaded based on
various primitive data types and print different types of animal sounds (“oink,” “honk,” etc.) depending on which
overloaded version is called. Write a main() that calls all the different versions. Note: The sound() method does not
generate the sound; it only prints the sound word as output. In main(), test the methods by calling all the overloaded
methods to print animal sounds.
5. Create a class called Elevator that can be moved between floors in an N-storey building. Elevatoruses a constructo
to initialize the number of floors in the building when the object is instantiated. Elevator also has a default
constructor that creates a two-storey (2) building. Elevator has a termination condition that requires the elevator to
e moved to the main (i.e., first) floor when the object is cleaned up. Write a finalize() method that satisfies this
termination condition and verifies the condition by printing a message to the output. In main(), test the possible
scenarios (i.e., create, move from one floor to another, etc.) that can occur when your Elevator is used in a building
5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 2/3
with many floors. (Hint: Termination occurs when the instance is set to null. You may wish to investigate “ga
age
collection” for this exercise.)
Documentation and Test Plans
You may have encountered documentation and test plans in other courses or at your workplace. For this
course, the following are mandatory and should be followed. If the standards for this course differ from
others in your past experience, then, for these assignments, the standards of this course supercede all othe
standards.
At the top of every source file, you must place three comment blocks.
The first comment block contains your name, student ID, date, assignment number, program name, and a
ief program description.
The second comment block is the primary documentation for your program. Explain the program purpose,
code behaviours, and any particulars of the program. Also include detailed instructions for compiling and
executing the program, including example input data if required. Also list separately all classes and
instance variables used in the program, with descriptions.
The third comment block is the test plan. At its core, a test plan simply tells another person how the
program actually worked during testing. In cases where there is no input, there is still often output, so you
can still show exactly how the program should function. In programs with input, you can also describe
various test cases, including those where inco
ect data (or no data) is entered and what output should be
expected. Finally, the test plan is a place to discuss limitations of your program and things that could be
done to improve it.
If you write a program with multiple classes, the first two comment blocks must appear in every source
(class) file. The test plan comment block should only appear in the source file that contains
the main()method used for testing.
Failure to provide all three comment blocks will result in loss of marks, as noted below in Marking
Scheme.
The program “GoodDocs.java” is provided as a complete working example of a program documented to
the standards of this course. (See Resources & Tools in the right-hand column of the course home page.)
Deliverables
Be sure your working directory contains only source code files and any necessary input files as required by
the assignment. Zip this directory into a single zip file and then upload it using the assignment drop box.
https:
comp501r6.athabascau.ca
esources/GoodDocs.java
5/21/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39106 3/3
If you experience difficulty uploading the file, contact your tutor before the due date. Once the due
date has passed, late penalties are in effect whether you have had difficulties or not.
Note: Your tutor will not accept assignments by email.
Marking Scheme
Your assignment is evaluated using the following marking scheme:
Program compiles without e
ors or warnings 20%
Program executes co
ectly 20%
Source code meets the exercise requirements without e
ors 20%
Documentation is provided as required 20%
Test plan is complete 20%
Cautions
If your program does not compile, you will lose both compile marks and execution marks, and most likely,
also some code marks.
If you use components, code fragments, methods, or other work that you did not write yourself, you must
clearly show the authorship of that code, including the author’s name and where the code was obtained.
This should be done in the documentation comment block. No more than 20% of your program can be the
work of others.
If you use the work of others without proper attribution, this is plagiarism and will be penalized with a
mark of 0 on the assignment and possible failure of the course.