I need help to do the program of the next homework. A teacher has 14 students in
ID: 2246845 • Letter: I
Question
I need help to do the program of the next homework. A teacher has 14 students in a course and he wants save information of them and about the course. From the students, he wants save the students: names, position in a classroom, studied carrier, what programs they know, the test grades, the projects grades, the participation in class grades. And also each student will belong to a one group (there are three different groups A,B,C). The course has 5 blocks: Java SE, Java EE, Web, BBDD, Projects and he would like to save information of the subjects studied in each block. Part I: UML · Make the UML diagram that includes the main elements
Explanation / Answer
Hi ..
import school.*;
import school.courses.*;
public class Main {
public static void main(String[] args) {
Teacher sriram = new Teacher("sriram");
Teacher bharat = new Teacher("bharat");
Teacher lil = new Teacher("Lil");
Teacher jana = new Teacher("jana");
Course[] courses = {
new NetworkCourse(15, sriram),
new SwingCourse(30, bharat),
new APIDesignCourse(50, lil),
new PerformanceCourse(5, jana)
};
School school = new School(courses);
Student ludwig = new Student("Ludwig");
Student cam = new Student("Cam");
Student daniel = new Student("Daniel");
ludwig.setPreferredCourses(NetworkCourse.class, SwingCourse.class); //give students preferred classes if they have them
cam.setPreferredCourses(APIDesignCourse.class, PerformanceCourse.class, NetworkCourse.class);
school.register(ludwig, cam, daniel);
/*
* Below is where we test by printing things out
*/
test(school);
}
static void test(School school) {
/*
* Prints all the students in the school, all the courses in the school, and which course each student has
*/
System.out.println("Students and their courses:");
for(Student student : school.getStudents()) {
if(student != null) {
String message = student.getName() + " is taking"; //message will reset for each new student, since we do = and not += here
for(Course course : student.getCourses())
message += " - " + course.getName();
System.out.println(message);
}
}
System.out.println(" Courses and their students:");
for(Course course : school.getCourses()) {
String message = course.getName() + " is taken by";
for(Student student : course.getStudents()) {
if(student != null)
message += " - " + student.getName();
}
System.out.println(message);
}
}
}------------------------------
package school;
import java.util.*;
public abstract class Course {
private Teacher teacher;
private Student[] students;
private UUID id;
protected Course(int maxStudents, Teacher teacher) { //might allow multiple teachers later
students = new Student[maxStudents];
this.teacher = teacher;
id = UUID.randomUUID();
}
void addStudent(Student student) {
for(int i = 0; i < students.length; i++) {
if(student == students[i])
continue;
if(students[i] == null) {
students[i] = student;
return;
}
}
}
public Teacher getTeacher() {
return teacher;
}
public Student[] getStudents() {
return Arrays.copyOf(students, students.length);
}
public boolean isFull() {
boolean full = true;
for(Student student : students)
full = student != null;
return full;
}
public abstract String getName();
}
thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.