Codingassignmenthelper | Home Codingassignmenthelper | Samples

CSC72002 S3

CSC72002

CSC72002 S3

		CSC72002 Assignment 1
Weight: 20% of your final mark
Due:

8 Jan 2021 11 pm

Specifications
Your task is to complete various exercises in NetBeans, using the Java language, and to submit
these via the MySCU link created for this purpose.
Marking criteria includes:
•
•
•
•

Use of correct coding style, including the use of comments;
Accuracy of coding;
Use of suitable coding structures;
Correct submission and naming conventions of assessment items as required.

Getting Help
This assignment is to be completed individually. It is the opportunity to gain an understanding of
the concepts of object oriented programming and coding syntax. It is important that you master
these concepts yourself. You are permitted to work from the examples in the study guide or
textbook but you must acknowledge assistance from other textbooks or classmates. In particular,
you must not use online material or help from others, as this would prevent you from mastering
these concepts.
Who can you get help from? Use this diagram to determine from whom you may seek help
with your program.

Lecturer

Tutors

Online
Forums

Relatives

Flowers
outside unit

Hired coders

Private
Tutors

Other

Classmates

Encouraged
Attribution Required
Ask tutor
Not acceptable

1

Part 1 – Classes and objects
Create a new Java project called usernamePart1 in NetBeans. In my case the project would be
called rghanbarPart1. Select the option to create a main method.
Create a new class called Plant. In the Plant class write the code for:
•
•

2 instance variables that are appropriate for a Plant
A default constructor and a second constructor that initialises all the instance variables

•
•

Accessor (getters) and mutator methods (setters) for all instance variables
A method called printDetails that prints the plants details e.g. “The plants details are: “
followed by all instance variables. The output must be formatted for readability.

In the main method write the code to:
•

Create 2 plants, one using the default constructor, the other using the constructor that
initialises all the instance variables

•

Demonstrate the use of one accessor method and one mutator method for one of the
plants you created

•

Print the plants details using the printDetails method for one of the plants you created

Part 2 – Inheritance, collections and polymorphism
Create a new Java project called usernamePart2 in NetBeans. Select the option to create a main
method.
Create a new class called Flower. Create a second class called Plant. Copy the code from the
Plant class you created in Part 1 into the new Plant class.
Modify the new Flower class so that it extends Plant (Plant is the superclass, Flower is the
subclass).
In the Flower class write the code for:
•
•
•

2 instance variables that are appropriate for a Flower
Accessor and mutator methods for the 2 instance variables
A default constructor and a second constructor that initialises all the instance variables in
the Flower and the Plant classes using the super keyword

The Flower class must also demonstrate the use of:
•
•

Overloaded methods
Overriding a method and the super keyword in a method

2

Polymorphism
In the class that contains the main method, create a second method that takes a Plant as a
parameter and uses one of the plants accessor methods. Then create an object of type Flower
and an object of type Plant in the main method and use the method you have just created to
demonstrate polymorphism.

Part 3 – Abstract classes
Create a new Java project called usernamePart3 in Netbeans. Select the option to create a main
method.
Create a new class called Flower. Create a second new class called Plant. Rewrite your code from
Part2 so that:
•
•
•

The Plant class is abstract
Flower extends Plant
The Plant class contains at least 2 abstract methods

All methods, constructors and instance variables that were in the Flower and Plant classes in part
2 must be included in part 3. You need to rewrite the Flower and Plant classes from part 2 so
that Plant is abstract and there are multiple ways to create a Flower.
In the main method of your project write the code to:
•
•
•

Declare an HashSet with a type parameter of Flower
Add at least 3 Flowers to the HashSet
Use an Iterator (java.util.Iterator) to loop through the Flowers in the HashSet (must use
the hasNext() and next() methods)

•
•
•
•

Check if the HashSet contains a particular Flower
Remove a Flower from the HashSet
Print the size of the HashSet
Clear the HashSet

Please note that collections are covered in Topic 3 and 4. You may need to wait until we have
covered these topics to implement your HashSet.

Part 4 – Interfaces
Create a new Java project called usernamePart4 in NetBeans. Select the option to create a main
method.
Create a new class called Flower. Create a new interface called Plant. Rewrite your code from
Part 2 so that:
•

Plant is an interface

•

Flower implements Plant
3

•

The Plant interface contains at least 2 abstract methods

All methods, constructors and instance variables that were in the Flower and Plant classes in part
2 must be included in part 4. You need to rewrite the Flower and Plant classes from part 2 so
that Plant is an interface and there are multiple ways to create a Flower.
In the main method of your project write the code to:
•
•

Declare a Stack with a type parameter of Flower • Add at least 3 Flowers to the Stack
Demonstrate the use of:
o peek() o
pop() o
empty()

Please note that collections are covered in Topic 3 and 4. You may need to wait until we have
covered these topics to implement your Stack.

Submission
You should now have 4 NetBeans projects. You must zip the projects and the word document in
into one zip file called username_A1.zip For example, mine would be rghanbar_A1.zip.
Submit this file via the Assignment 1 link on MySCU by the due date. Please leave enough time
for it to upload, so do not submit at the last minute!

4


		
To Download Click Here > CSC72002 S3 2020 Assignment 1.pdf
Codingassignmenthelper | Home Codingassignmenthelper | Home