You are on page 1of 12

Để giải quyết được bài toán này, chúng ta sẽ thiết kế các lớp Profiles.java, Running.

java,
ComputerScience.java, InformationTechnology.java, InformationSecurity.java và
SoftwareEngineering.java.

Bước 1: Thiết kế lớp Profiles.java

Trong đó có các thuộc tính studentID, firstname, lastname, address, phone và email, và các phương thức
set, get và inputInfo.

public class Profiles {

private String studentID;

private String firstname;

private String lastname;

private String address;

private String phone;

private String email;

public void setInfo(String studentID, String firstname, String lastname, String address, String phone,
String email){

this.studentID = studentID;

this.firstname = firstname;

this.lastname = lastname;

this.address = address;

this.phone = phone;

this.email = email;

public void setStudentID(String studentID){

this.studentID = studentID;

}
public String getStudentID(){

return studentID;

public void setFirstName(String firstname){

this.firstname = firstname;

public String getFirstName(){

return firstname;

public void setLastName(String lastname){

this.lastname = lastname;

public String getLastName(){

return lastname;

public void setAddress(String address){

this.address = address;

public String getAddress(){

return address;

}
public void setPhone(String phone){

this.phone = phone;

public String getPhone(){

return phone;

public void setEmail(String email){

this.email = email;

public String getEmail(){

return email;

public void inputInfo(){

Scanner scanner = new Scanner(System.in);

System.out.print("Nhap student ID: ");

studentID = scanner.nextLine();

System.out.print("Nhap first name: ");

firstname = scanner.nextLine();

System.out.print("Nhap last name: ");

lastname = scanner.nextLine();

System.out.print("Nhap address: ");

address = scanner.nextLine();

System.out.print("Nhap phone: ");

phone = scanner.nextLine();

System.out.print("Nhap email: ");


email = scanner.nextLine();

public String getInfo(){

return "Student ID: " + studentID + "\n"

+ "Full name: " + firstname + " " + lastname + "\n"

+ "Address: " + address + "\n"

+ "Phone: " + phone + "\n"

+ "Email: " + email + "\n";

Bước 2: Thiết kế lớp Running.java

Ở lớp này, chúng ta sẽ tạo đối tượng std01, cập nhập thông tin cho đối tượng bằng cách gán giá trị qua
các phương thức set, sau đó in thông tin của std01 ra màn hình. Tiếp đó, tạo đối tượng std02, cập nhập
thông tin cho đối tượng bằng cách gán giá trị trực tiếp qua Constructor, sau đó in thông tin của std02 ra
màn hình.

import java.util.*;

public class Running {

public static void main(String[] args) {

Profiles std01 = new Profiles();

std01.setStudentID("001");

std01.setFirstName("Mai");

std01.setLastName("Thanh");

std01.setAddress("Hanoi");

std01.setPhone("1234567890");

std01.setEmail("maithanh@gmail.com");
System.out.println("Student 01 info: \n" + std01.getInfo());

Profiles std02 = new Profiles();

std02.setInfo("002", "Trung", "Pham", "HCM City", "0987654321", "trungpham@gmail.com");

System.out.println("Student 02 info: \n" + std02.getInfo());

Bước 3: Thiết kế lớp ComputerScience.java

Ở lớp này, chúng ta sử dụng lớp Profiles như là một lớp abstract và tạo đối tượng sc01 (bao gồm thông
tin sinh viên), in ra màn hình danh sách sinh viên cùng điểm tích lũy.

import java.util.*;

public class ComputerScience {

public static void main(String[] args) {

List<Profiles> lstProfile = new ArrayList<>();

Profiles sc01 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (8.5 + 9.0 + 7.5) / 3;

};

sc01.setInfo("001", "Mai", "Thanh", "Hanoi", "1234567890", "maithanh@gmail.com");

lstProfile.add(sc01);
Profiles sc02 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (7.5 + 6.0 + 9.0) / 3;

};

sc02.setInfo("002", "Trung", "Pham", "HCM City", "0987654321", "trungpham@gmail.com");

lstProfile.add(sc02);

Profiles sc03 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (9.0 + 8.0 + 8.5) / 3;

};

sc03.setInfo("003", "Tuan", "Le", "Da Nang", "0988777888", "tuanle@gmail.com");

lstProfile.add(sc03);

System.out.println("List of students in Computer Science:");

for(Profiles student : lstProfile) {

System.out.println(student.getInfo() + "Average grade: " + student.getAverageGrade() + "\n");

Bước 4: Thiết kế lớp InformationTechnology.java


Ở lớp này, chúng ta sử dụng lớp Profiles như là một lớp abstract và tạo đối tượng sc02 (bao gồm thông
tin sinh viên), in ra màn hình danh sách sinh viên cùng điểm tích lũy.

import java.util.*;

public class InformationTechnology {

public static void main(String[] args) {

List<Profiles> lstProfile = new ArrayList<>();

Profiles sc01 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (8.5 + 9.0 + 7.5) / 3;

};

sc01.setInfo("001", "Mai", "Thanh", "Hanoi", "1234567890", "maithanh@gmail.com");

lstProfile.add(sc01);

Profiles sc02 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (7.5 + 6.0 + 9.0) / 3;

};

sc02.setInfo("002", "Trung", "Pham", "HCM City", "0987654321", "trungpham@gmail.com");

lstProfile.add(sc02);
Profiles sc03 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (9.0 + 8.0 + 8.5) / 3;

};

sc03.setInfo("003", "Tuan", "Le", "Da Nang", "0988777888", "tuanle@gmail.com");

lstProfile.add(sc03);

System.out.println("List of students in Information Technology:");

for(Profiles student : lstProfile) {

System.out.println(student.getInfo() + "Average grade: " + student.getAverageGrade() + "\n");

Bước 5: Thiết kế lớp InformationSecurity.java

Ở lớp này, chúng ta sử dụng lớp Profiles như là một lớp abstract và tạo đối tượng sc03 (bao gồm thông
tin sinh viên), in ra màn hình danh sách sinh viên cùng điểm tích lũy.

import java.util.*;

public class InformationSecurity {

public static void main(String[] args) {

List<Profiles> lstProfile = new ArrayList<>();

Profiles sc01 = new Profiles() {


@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (8.5 + 9.0 + 7.5) / 3;

};

sc01.setInfo("001", "Mai", "Thanh", "Hanoi", "1234567890", "maithanh@gmail.com");

lstProfile.add(sc01);

Profiles sc02 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (7.5 + 6.0 + 9.0) / 3;

};

sc02.setInfo("002", "Trung", "Pham", "HCM City", "0987654321", "trungpham@gmail.com");

lstProfile.add(sc02);

Profiles sc03 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (9.0 + 8.0 + 8.5) / 3;

};

sc03.setInfo("003", "Tuan", "Le", "Da Nang", "0988777888", "tuanle@gmail.com");

lstProfile.add(sc03);
System.out.println("List of students in Information Security:");

for(Profiles student : lstProfile) {

System.out.println(student.getInfo() + "Average grade: " + student.getAverageGrade() + "\n");

Bước 6: Thiết kế lớp SoftwareEngineering.java

Ở lớp này, chúng ta sử dụng lớp Profiles như là một lớp abstract và tạo đối tượng sc04 (bao gồm thông
tin sinh viên), in ra màn hình danh sách sinh viên cùng điểm tích lũy.

import java.util.*;

public class SoftwareEngineering {

public static void main(String[] args) {

List<Profiles> lstProfile = new ArrayList<>();

Profiles sc01 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (8.5 + 9.0 + 7.5) / 3;

};

sc01.setInfo("001", "Mai", "Thanh", "Hanoi", "1234567890", "maithanh@gmail.com");

lstProfile.add(sc01);

Profiles sc02 = new Profiles() {


@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (7.5 + 6.0 + 9.0) / 3;

};

sc02.setInfo("002", "Trung", "Pham", "HCM City", "0987654321", "trungpham@gmail.com");

lstProfile.add(sc02);

Profiles sc03 = new Profiles() {

@Override

public double getAverageGrade() {

// Tính điểm trung bình 3 học phần

return (9.0 + 8.0 + 8.5) / 3;

};

sc03.setInfo("003", "Tuan", "Le", "Da Nang", "0988777888", "tuanle@gmail.com");

lstProfile.add(sc03);

System.out.println("List of students in Software Engineering:");

for(Profiles student : lstProfile) {

System.out.println(student.getInfo() + "Average grade: " + student.getAverageGrade() + "\n");

Chúng ta hoàn tất các lớp và có thể chạy bằng cách gọi đại diện cho các lớp:

public class Main {


public static void main(String[] args) {

Running mainRunning = new Running();

ComputerScience mainComputerscience = new ComputerScience();

InformationTechnology mainInformationtechnology = new InformationTechnology();

InformationSecurity mainInformationsecurity = new InformationSecurity();

SoftwareEngineering mainSoftwareengineering = new SoftwareEngineering();

Kết quả sẽ giống như các đoạn code chúng ta đã viết trên.

You might also like