0% found this document useful (0 votes)
34 views2 pages

Sample Task Guideline and Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Sample Task Guideline and Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sample task guideline

1. Class Structure:
 Define a superclass named Course that contains the following attributes and
methods:
 Attributes: courseCode (String), courseTitle (String), and courseInstructor
(String).
 Methods:
 Course(String courseCode, String courseTitle, String
courseInstructor): Constructor to initialize the attributes.
 void displayCourseInfo(): Method to display the course information
(course code, course title, and course instructor).
 Define a subclass named OnlineCourse that extends the Course class. This subclass
should include the following:
 Additional attribute: platform (String) representing the online platform used
for the course.
 Implement the constructor to initialize all attributes (courseCode,
courseTitle, courseInstructor, and platform).
 Override the displayCourseInfo() method to also display the online platform
of the course.
2. Object Creation:
 Create an object of the OnlineCourse class and initialize it with appropriate values
for all attributes.
 Display the information of the online course using the displayCourseInfo() method.

TIPS:
 Read and analyze the problem and conceptualize the possible output.
 If having hard time to understand problem try using diagram as your
lead.
 Practice coding using your own problem or inputs.
 Don’t memorize the whole codes instead familiarize the order of
algorithm, keywords and syntax.
VERY, VERY, VERY Basic -------> Sample Code

class Course{ //Class (Parent class)


String courseCode; //Attribute 1
String courseTitle; //Attribute 2
String courseInstructor; //Attribute 3

public Course(String courseCode, String courseTitle, //Constructor


method for parent class
String courseInstructor){
this.courseCode=courseCode;
this.courseTitle=courseTitle;
this.courseInstructor=courseInstructor;
}

public void displayCourseInfo(){ //function method to display course


information
System.out.println("COURSE INFORMATION");
System.out.println("Course Code: "+courseCode+ "\nCourse Title: "
+ courseTitle +"\nCourse Instructor: "+courseInstructor);
}
}

class OnlineClass extends Course{ //Child class (single Inheritance)


String platform; // new attribute for the child class
public OnlineClass(String courseCode, String courseTitle,
//Constructor method for child class
// ** just copy the parameter from the
// parent class then add the new attribute
String courseInstructor, String platform){
super(courseCode, courseTitle, courseInstructor); //Super to copy
th
// constructor from the parent class
this.platform=platform; // Initialize also the new attribute for
child class
}
@Override // method overriding in runtime Polymorphism
public void displayCourseInfo(){
super.displayCourseInfo();
System.out.println("Platform"+platform+"\n");
}
}
public class Main { //Main class
public static void main(String[]args){ //main method
OnlineClass onlineClass1 = new OnlineClass("123ab",
"Programming 2","Moses B. Gawang", "Google Class Room"); //
Object 1
OnlineClass onlineClass2 = new OnlineClass("123ac", "OS",
"Moses Gawang","Zoom"); // object 2
onlineClass1.displayCourseInfo(); // display the object 1 infos by
calling the method above
onlineClass2.displayCourseInfo();// display the object 2 infos by
calling the method above
}
}
// Fix the output display for readbility..

//Thank you!!!!
//Good luck

You might also like