5/27/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39107 1/2
Java Programs
When a program requires user input, you must be sure to incorporate user information in your program;
that is, if a program requires an argument, then omitting the argument should generate a message that
informs the user as to the type of input required. All programs must have appropriate output information
displays and user prompts as necessary.
Complete, working, and tested programs are required to solve the following exercises. See Documentation
and Test Plans for required documentation.
In the programs for this assignment, 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). If a program specifies
multiple classes, then each class should be in its own separate source file.
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 class called Animal with overload sound() methods. These methods should be overloaded based on various
primitive data types and print different types of animal sounds (“oink,” “honk,” etc.) depending on which overload
version is called. You may use the program you wrote for Assignment 1, question 4 as a starting point. Create
child classes for Pig, Sheep, Duck, and Cow. Every child class has its ove
ide sound() method, and the ove
ide
method will call the appropriate overload sound() method according to what animal it represents. Write
a main() that creates instances of different animals, and calls these animal instances sound() method, so different
animals will print different sounds accordingly. Note: The sound() method does not generate the sound; it only
prints the sound word to output.
2. Define a class called Book. This class should store attributes such as the title, ISBN number, author, edition,
publisher, and year of publication. Provide get/set methods in this class to access these attributes. Define a class
called Bookshelf, which contains the main method. This class should create a few book objects with distinct names
and store them in an A
ayList. This class should then list the names of all books in the A
ayList. Enhance the
program by providing a sort function, which will sort the books in ascending order of their year of publication.
Create a few more Book objects with the same names but with different edition numbers, ISBNs, and years of
publication. Add these new Book objects to the A
ayList, and display the book list sorted by book name; fo
duplicate books of the same name, sort the list by year of publication. (Hint: You will need to define a comparato
class that takes two Book objects as parameters of the compareTo method. This method should do a two-step
comparison and return a Boolean value. The first comparison should compare the name of the book. If the name is
the same, the second comparison should compare the year of publication.)
Documentation and Test Plans
5/27/2021 Assignment
https:
scis.lms.athabascau.ca/mod/assign/view.php?id=39107 2/2
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