0% found this document useful (0 votes)
10 views4 pages

TUGASPROJECTOPPJAVA 64c695183d244

The document defines Person, Lecturer, and Student classes with attributes like name, ID, age, etc. and get/set methods to access them. The Main class creates objects of each type, sets their attributes, and prints them out to demonstrate polymorphism whereby a Lecturer and Student both extend the Person class but have their own specific attributes as well.

Uploaded by

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

TUGASPROJECTOPPJAVA 64c695183d244

The document defines Person, Lecturer, and Student classes with attributes like name, ID, age, etc. and get/set methods to access them. The Main class creates objects of each type, sets their attributes, and prints them out to demonstrate polymorphism whereby a Lecturer and Student both extend the Person class but have their own specific attributes as well.

Uploaded by

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

public class Person {

protected String Name;


protected String ID;
protected int age;
//
public Person() {
Name = "";
ID = "";
age = 0;
}
public Person(String Name, String ID, int age) {
this.Name = Name;
this.ID = ID;
this.age = age;
}
//
public String getName() {
return Name;
}

public void setName(String name) {


Name = name;
}

public String getID() {


return ID;
}

public void setID(String iD) {


ID = iD;
}
public int getAge() {
return age;
}

public void setAge(int age) {


this.age = age;
}

public class Lecturer extends Person {


private String faculty;
private double salary;

public Lecturer(String Name, String ID, int age, String faculty, double salary) {
this.Name = Name;
this.ID = ID;
this.age = age;
this.faculty = faculty;
this.salary = salary;
}

public String getFaculty() {


return faculty;
}

public void setFaculty(String faculty) {


this.faculty = faculty;
}

public double getSalary() {


return salary;
}

public void setSalary(double salary) {


this.salary = salary;
}
}

public class Student extends Person {


private String major;
private float GPA;
public Student(String Name, String ID, int age,String major, float GPA) {
this.Name = Name;
this.ID = ID;
this.age = age;
this.major = major;
this.GPA = GPA;

}
public String getMajor() {
return major;
}

public void setMajor(String major) {


this.major = major;
}

public float getGPA() {


return GPA;
}

public void setGPA(float gPA) {


GPA = gPA;
}

public class Main {


public static void main(String[] args) {
Person Mohammad = new Person("Mohammad", "0123456789", (int) 35 );
System.out.println("Name: " + Mohammad.getName());
System.out.println("ID: " + Mohammad.getID());
System.out.println("age: " + Mohammad.getAge());
System.out.println("--------------------------------------------------------------
--------------------");
//
//
Lecturer lecturer = new Lecturer("Paijo", "0987654321",(int)
35,"kebangsaan",(double) 8700000);
System.out.println("Name: " + lecturer.getName());
System.out.println("ID: " + lecturer.getID());
System.out.println("age: " + lecturer.getAge());
System.out.println("faculty: " + lecturer.getFaculty());
System.out.println("salary: " + lecturer.getSalary());
System.out.println("--------------------------------------------------------------
----------------------");

//

Student student = new Student("Suep", "789023456", (int) 35, "IT", (float)6);


System.out.println("Name: " + student.getName());
System.out.println("ID: " + student.getID());
System.out.println("age: " + student.getAge());
System.out.println("major: " + student.getMajor());
System.out.println("GPA: " + student.getGPA());
}

You might also like