You are on page 1of 4

import java.util.

ArrayList;
import java.util.Scanner;

public class kiemtra {


public kiemtra() {
System.out.println("Hello World!");
}

class Name {
String firstName;
String middleName;
String lastName;

public Name(String firstName, String middleName, String lastName) {


this.firstName = firstName;
this.middleName = middleName;
this.lastName = lastName;
}

@Override
public String toString() {
return firstName + " " + middleName + " " + lastName;
}
}

class Address {
String homeNo;
String street;
String district;
String city;

Address(String homeNo, String street, String district, String city) {


this.city = city;
this.district = district;
this.homeNo = homeNo;
this.street = street;
}
}

abstract class Person {


String id;
Name name;
String phone;
Address address;
public Person(String id, Name name, String phone, Address address) {
this.id = id;
this.name = name;
this.phone = phone;
this.address = address;
}

public void updatePhone(String phone) {


this.phone = phone;
}

public abstract void addToCourse(Course course);


}

class Student extends Person {


String className;

public Student(String id, Name name, String phone, Address address) {


super(id, name, phone, address);
}

@Override
public void addToCourse(Course course) {
course.students.add(this);
}
}

class Faculty extends Person {


String job;

public Faculty(String id, Name name, String phone, Address address) {


super(id, name, phone, address);
}

@Override
public void addToCourse(Course course) {
course.faculties.add(this);
}
}

class Course {
String id;
String name;
String description;
int credit;
ArrayList<Faculty> faculties;
ArrayList<Student> students;

public Course(String id, String name, String description, int credit) {


this.id = id;
this.name = name;
this.description = description;
this.credit = credit;
this.faculties = new ArrayList<>();
this.students = new ArrayList<>();
}

@Override
public String toString() {
return "Course: " + name + " (ID: " + id + ")";
}
}

public static void main(String[] args) {


kiemtra kiemTra = new kiemtra();
Scanner sc = new Scanner(System.in);
System.out.println("Select an option:");
System.out.println("1: Student");
System.out.println("2: Lecturer");
System.out.println("3: Course");
int option = sc.nextInt();

// Create a sample student


Name studentName = kiemTra.new Name("Alice", "", "Smith");
Address studentAddress = kiemTra.new Address("123", "Main St",
"District1", "City1");
Student student = kiemTra.new Student("S12345", studentName, "555-1234",
studentAddress);
student.className = "E21CQCN03-B";

// Create a sample faculty


Name facultyName = kiemTra.new Name("John", "M", "Doe");
Address facultyAddress = kiemTra.new Address("456", "Elm Rd",
"District2", "City2");
Faculty faculty = kiemTra.new Faculty("F67890", facultyName, "555-5678",
facultyAddress);
faculty.job = "Professor";
// Create a

sample course
Course course = kiemTra.new Course("C101", "Introduction to Programming",
"Basic programming concepts", 3);

// Add the student and faculty to the course

// Display information
switch (option) {
case 1:
student.addToCourse(course);
System.out.println("Student: " + student.name + ", ID: " +
student.id + ", Class: " + student.className+", "+student.phone);
break;
case 2:
faculty.addToCourse(course);
System.out.println("Faculty: " + faculty.name + ", ID: " +
faculty.id + ", Job: " + faculty.job+", "+faculty.phone);
break;
case 3:
System.out.println(course);
break;
default:
System.out.println("Invalid option");
}
}
}

You might also like