0% found this document useful (0 votes)
18 views7 pages

03-Nhóm 7 - Kiemtra - Trương Anh Đ T

The document defines classes for a student management system including classes for Name, Address, Person, Student, Faculty and Course. It includes methods to input, add and display student and faculty data.

Uploaded by

manhung19112003
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)
18 views7 pages

03-Nhóm 7 - Kiemtra - Trương Anh Đ T

The document defines classes for a student management system including classes for Name, Address, Person, Student, Faculty and Course. It includes methods to input, add and display student and faculty data.

Uploaded by

manhung19112003
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/ 7

Trương Anh Đạt - B21DCDT063 - Nhóm 7

Exam 1
package exam1;
import java.util.*;
class Name{
String firstName;
String midName;
String lastName;
public String getFirstName() {
return firstName;
}
public String getMidName() {
return midName;
}
public String getLastName() {
return lastName;
}
public Name(String firstName, String midName, String
lastName) {
this.firstName = firstName;
this.midName = midName;
this.lastName = lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setMidName(String midName) {
this.midName = midName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Name inputName() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first name: ");
String firstName = sc.nextLine();
System.out.print("Enter mid name: ");
String midName = sc.nextLine();
System.out.print("Enter last name: ");
String lastName = sc.nextLine();
Name name = new Name(firstName, midName, lastName);
return name;
}
}
class Address{
String homeNumber;
String street;
String district;
String city;

public Address(String homeNumber, String street, String


district, String city) {
this.homeNumber = homeNumber;
this.street = street;
this.district = district;
this.city = city;
}
public String getHomeNumber() {
return homeNumber;
}
public String getStreet() {
return street;
}
public String getDistrict() {
return district;
}
public String getCity() {
return city;
}
public void setHomeNumber(String homeNumber) {
this.homeNumber = homeNumber;
}
public void setStreet(String street) {
this.street = street;
}
public void setDistrict(String district) {
this.district = district;
}
public void setCity(String city) {
this.city = city;
}
public Address inputAddress() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter home number: ");
String homeNum = sc.nextLine();
System.out.print("Enter street: ");
String street = sc.nextLine();
System.out.print("Enter district: ");
String district = sc.nextLine();
System.out.print("Enter city: ");
String city = sc.nextLine();
Address address = new Address(homeNum, street,
district, city);
return address;
}
}
class Course{
String courseId;
String courseName;
int credit;
public String getCourseId() {
return courseId;
}
public String getCourseName() {
return courseName;
}
public int getCredit() {
return credit;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public void setCredit(int credit) {
this.credit = credit;
}
}
class Person{
String id;
String phone;
Name name;
Address address;

public Person(String id, String phone, Name name, Address


address) {
this.id = id;
this.phone = phone;
this.name = name;
this.address = address;
}
public String getId() {
return id;
}
public String getPhone() {
return phone;
}

public Name getName() {


return name;
}

public Address getAddress() {


return address;
}
}
class Student extends Person{
List<Course> enrollCourse;
public Student(String id, String phone, Name name,
Address address, String classroom) {
super(id, phone, name, address);
this.Classroom = classroom;
this.enrollCourse = new ArrayList<Course>();

}
String Classroom;
public String getClassroom() {
return Classroom;
}
public void setClassroom(String class1) {
Classroom = class1;
}
public static Student inputStudent() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter ID: ");
String id = sc.nextLine();
System.out.print("Enter phone number: ");
String phone = sc.nextLine();
String fn = "", mn = "", ln = "";
Name name = new Name(fn, mn, ln);
name.inputName();
String hn = "", str = "", dis = "", ct = "";
Address address = new Address(hn, str, dis, ct);
address.inputAddress();
System.out.print("Enter classroom: ");
String classroom = sc.nextLine();
Student stu = new Student(id, phone, name, address,
classroom);
return stu;
}
}
class Faculty extends Person{
public Faculty(String id, String phone, Name name,
Address address, String job) {
super(id, phone, name, address);
this.job = job;
// TODO Auto-generated constructor stub
}
String job;
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public static Faculty inputFaculty() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter ID: ");
String id = sc.nextLine();
System.out.print("Enter phone number: ");
String phone = sc.nextLine();
String fn = "", mn = "", ln = "";
Name name = new Name(fn, mn, ln);
name.inputName();
String hn = "", str = "", dis = "", ct = "";
Address address = new Address(hn, str, dis, ct);
address.inputAddress();
System.out.print("Enter job: ");
String job = sc.nextLine();
Faculty giangVien = new Faculty(id, phone, name,
address, job);
return giangVien;
}
public class ex1 {

static List<Student> students;


static List<Faculty> faculties;
static List<Course> courses;
public static int chonMot() {
int chon = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Select: ");
chon = sc.nextInt();
return chon;
}
public static void showMenu() {

System.out.println("+-------------------------------------+");
System.out.println("1. Add a course to student:");
System.out.println("2. Add a course to leturer:");
System.out.println("3. Add new course");
System.out.println("10. Exit");

System.out.println("+-------------------------------------+");
}
public static void addStudent() {
Student sinhVien = Student.inputStudent();
students.add(sinhVien);

System.out.println("+-------------------------------------+");
System.out.println("Output");
System.out.println("Student ID: " + sinhVien.id);
System.out.println("Student phone number: " +
sinhVien.phone);
System.out.println("Student name: " +
sinhVien.name.lastName + " "
+ sinhVien.name.midName + " " +
sinhVien.name.firstName);
System.out.println("Student address: " +
sinhVien.address.homeNumber + ", "
+ sinhVien.address.street + ", " +
sinhVien.address.district + ", "
+ sinhVien.address.city);
}

public static void addFaculty() {


Faculty giangVien = Faculty.inputFaculty();
faculties.add(giangVien);

System.out.println("+-------------------------------------+");
System.out.println("Output");
System.out.println("Student ID: " + giangVien.id);
System.out.println("Student phone number: " +
giangVien.phone);
System.out.println("Student name: " +
giangVien.name.lastName + " "
+ giangVien.name.midName + " " +
giangVien.name.firstName);
System.out.println("Student address: " +
giangVien.address.homeNumber + ", "
+ giangVien.address.street + ", " +
giangVien.address.district + ", "
+ giangVien.address.city);
}
public static void main(String[] args) {
int chon = 0;
do {
showMenu();
chon = chonMot();
switch(chon) {
case 1:
addStudent();
break;
case 2:
addFaculty();
break;
case 3:
//addCourse();
default:
System.out.println("Bạn đã nhập sai");
break;
}
}
while (chon != 0);
}
}

You might also like