03-Nhóm 7 - Kiemtra - Trương Anh Đ T
03-Nhóm 7 - Kiemtra - Trương Anh Đ T
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;
}
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 {
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);
}
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);
}
}