Lab 4
Lab 4
A) Create a super (parent) class called Course. The Course class represents any
course that does not have a lab (without a lab). The class should include the
followings:
Private attributes:
o courseCode (type string)
o examMark (type double)
o courseWorkMark (type double)
A constructor that initializes the three attributes of the class.
A public and static variable called noOfCourses (stands for number of
courses). The initial value for this variable is 0 and it increases with every
new course object created.
A public method called finalMark () which returns the total sum of course’
marks. The total mark is computed as (examMark + courseWorkMark).
A public and static method called getNoOfCourses(). it returns the total
number of courses created.
An overriden method called toString(), which returns a string that represents
the Course object.
B) Extend the above Course code by creating a sub (child) class called CourseLab.
The CourseLab inherits the super class Course. The class should include the
followings:
An attribute called labMark (type double), which represents the mark of the
lab.
A constructor that initializes the attributes of the class. (Hint: don’t forget to
consider the super class’ constructor using the keyword: super).
An overriden method called finalMark (), which returns the total sum of
course’ marks in this sub class. The total mark in this case is computed as
(examMark + courseWorkMark + labMark).
An overriden method called toString(), which returns a string that represents
the CourseLab object.
C) Write an application with a main Method that creates objects from the classes
Course and CourseLab and displays the objects information. Your application code
should also display the total number of courses that have been created.
Answer:
package main;
class Course{
private String courseCode;
private double examMark;
public double courseWorkMark;