Em mới bắt đầu học Java ạ bài tập của em thì như hình bên dưới ạ
còn đây là phần code ạ
đây là class Gradelitem
public class Gradelitem {
private String title;
private float rate;
private float mart;
public Gradelitem() {
}
public Gradelitem(String title, float rate, float mart) {
this.title = title;
this.rate = rate;
this.mart = mart;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public float getRate() {
return rate;
}
public void setRate(float rate) {
this.rate = rate;
}
public float getMart() {
return mart;
}
public void setMart(float mart) {
this.mart = mart;
}
@Override
public String toString() {
return "title=" + title + ", rate=" + rate + ", mart=" + mart + '}';
}
}
đây là class Student
public class Student {
private int code;
private String name;
ArrayList<Gradelitem> gradelitems;
public Student() {
}
public Student(int code, String name, ArrayList<Gradelitem> gradelitems) {
this.code = code;
this.name = name;
this.gradelitems = gradelitems;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList<Gradelitem> getGradelitems() {
return gradelitems;
}
public void setGradelitems(ArrayList<Gradelitem> gradelitems) {
this.gradelitems = gradelitems;
}
public void addGradelitem(Gradelitem gra){
this.gradelitems.add(gra);
}
public float getGPA(){
float tmp = 0;
for (Gradelitem gradelitem : gradelitems) {
tmp = (gradelitem.getRate() * gradelitem.getMart());
}
return tmp/100.0f;
}
public boolean isPass(){
return (getGPA() > 5);
}
@Override
public String toString() {
return "Student{" + "code=" + code + ", name=" + name + "Gradelitems=" + gradelitems.toString() + '}';
}
}
đây là class course
public class Course {
private int code;
private String title;
private LocalDate startDate, endDate;
ArrayList<Student> students;
public Course() {
students = new ArrayList<Student>();
}
public Course(int code, String title, LocalDate startDate, LocalDate endDate, ArrayList<Student> students) {
this.code = code;
this.title = title;
this.startDate = startDate;
this.endDate = endDate;
this.students = students;
}
public Course(int code, String title, ArrayList<Student> students) {
this.code = code;
this.title = title;
this.students = students;
}
public Course(int code, ArrayList<Student> students) {
this.code = code;
this.students = students;
}
public int getCode() {
return code;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}
public ArrayList<Student> getStudents() {
return students;
}
public void setStudents(ArrayList<Student> students) {
this.students = students;
}
public void addStudent(Student st){
this.students.add(st);
}
public int getNumberOfPassStudent(){
int count = 0;
for (Student student : students) {
if(student.isPass() == true){
count ++;
}
}
return count;
}
public int getNumberOfBisStudent(){
return students.size() - getNumberOfPassStudent();
}
public void displayPassStudent(){
for (Student student : students) {
if(student.isPass() == true){
System.out.println(student);
}
}
}
public void displayBisStudent(){
for (Student student : students) {
if(student.isPass() == false){
System.out.println(student);
}
}
}
@Override
public String toString() {
return "Course{" + "code=" + code + ", title=" + title + ", startDate=" + startDate + ", endDate=" + endDate + '}'
+ "\nNumber of pass Student:" + getNumberOfPassStudent() + "\nNumber of bis Student: " + getNumberOfBisStudent();
}
}
Vì mới học nên em chưa biết gọi tới Arraylist để sử dụng trong hàm main nên ai có thể giúp em phần main đc ko ạ