0% found this document useful (0 votes)
29 views

ProjectObject 64f30b6304532

The document describes an object-oriented programming project in Java that defines classes for Person, Lecturer, and Student. The Person class establishes common attributes like ID, name, and age that are inherited by the Lecturer and Student classes. Lecturer adds attributes for salary and faculty, while Student adds GPA and major. A Main class demonstrates creating objects from each class and printing their attribute values.

Uploaded by

fAbdul Hanif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

ProjectObject 64f30b6304532

The document describes an object-oriented programming project in Java that defines classes for Person, Lecturer, and Student. The Person class establishes common attributes like ID, name, and age that are inherited by the Lecturer and Student classes. Lecturer adds attributes for salary and faculty, while Student adds GPA and major. A Main class demonstrates creating objects from each class and printing their attribute values.

Uploaded by

fAbdul Hanif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Project Object-Oriented Programming - Java

1. Class Person
class Person {
private int ID;
private String name;
private int age;

public Person(int ID, String name, int age) {


this.ID = ID;
this.name = name;
this.age = age;
}

// Getter methods
public int getID() {
return ID;
}

public String getName() {


return name;
}

public int getAge() {


return age;
}

// Setter methods
public void setID(int ID) {
this.ID = ID;
}

public void setName(String name) {


this.name = name;
}

public void setAge(int age) {


this.age = age;
}
}
2. Class Lecturer
class Lecturer extends Person {
private double salary;
private String faculty;

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

// Getter methods
public double getSalary() {
return salary;
}

public String getFaculty() {


return faculty;
}

// Setter methods
public void setSalary(double salary) {
this.salary = salary;
}

public void setFaculty(String faculty) {


this.faculty = faculty;
}
}
3. Class Student

class Student extends Person {


private double GPA;
private String major;

public Student(int ID, String name, int age, double GPA, String major) {
super(ID, name, age);
this.GPA = GPA;
this.major = major;
}

// Getter methods
public double getGPA() {
return GPA;
}

public String getMajor() {


return major;
}

// Setter methods
public void setGPA(double GPA) {
this.GPA = GPA;
}

public void setMajor(String major) {


this.major = major;
}
}
4. Class Main
public class Main {
public static void main(String[] args) {
// Membuat objek dari class Person
Person person = new Person(1, "John Doe", 30);

// Membuat objek dari class Lecturer


Lecturer lecturer = new Lecturer(2, "Dr. Smith", 45, 50000.0, "Computer
Science");

// Membuat objek dari class Student


Student student = new Student(3, "Alice Johnson", 20, 3.75,
"Mathematics");

// Menampilkan informasi dari objek-objek yang telah dibuat


System.out.println("Person ID: " + person.getID() + ", Name: " +
person.getName() + ", Age: " + person.getAge());
System.out.println("Lecturer ID: " + lecturer.getID() + ", Name: " +
lecturer.getName() + ", Age: " + lecturer.getAge() +
", Salary: " + lecturer.getSalary() + ", Faculty: " +
lecturer.getFaculty());
System.out.println("Student ID: " + student.getID() + ", Name: " +
student.getName() + ", Age: " + student.getAge() +
", GPA: " + student.getGPA() + ", Major: " + student.getMajor());
}
}
OUTPUT

You might also like