Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need a UML diagram for this application and comment lines written into the code that explain what is happening at each line. Course Registration

I need a UML diagram for this application and comment lines written into the code that explain what is happening at each line.
Course Registration System
Client.java
import javax.swing.JOptionPane;
import java.util.ArrayList;
public class Client {
public static void main(String[] args){
ArrayList students = new ArrayList<>();
ArrayList courses = new ArrayList<>();
ArrayList teachers = new ArrayList<>();
teachers.add(new Teacher("John Doe"));
teachers.add(new Teacher("Jane Smith"));
courses.add(new Course("Math", teachers.get(0)));
courses.add(new Course("Science", teachers.get(1)));
while (true){
String name = JOptionPane.showInputDialog("Enter student name:");
if (name == null || name.isEmpty()) break;
Student student = new Student(name);
students.add(student);
String[] courseOptions = new String[courses.size()];
for (int i =0; i < courses.size(); i++){
courseOptions[i]= courses.get(i).getCourseName();
}
String courseName =(String) JOptionPane.showInputDialog(null, "Select course:",
"Course Selection", JOptionPane.QUESTION_MESSAGE, null, courseOptions, courseOptions[0]);
for (Course course : courses){
if (course.getCourseName().equals(courseName)){
student.enrollCourse(course);
break;
}
}
JOptionPane.showMessageDialog(null, student.toString());
int continueOption = JOptionPane.showConfirmDialog(null,"Do you want to continue?");
if (continueOption != JOptionPane.YES_OPTION) break;
}
}
}
Student.java:
import java.util.ArrayList;
public class Student {
private String name;
private int studentID;
private ArrayList enrolledCourses;
public static int studentCount =0;
public Student(String name){
this.name = name;
this.studentID =++studentCount;
this.enrolledCourses = new ArrayList<>();
}
public void enrollCourse(Course course){
enrolledCourses.add(course);
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
@Override
public String toString(){
return "Student ID: "+ studentID +"
Name: "+ name +"
Enrolled Courses: "+ enrolledCourses;
}
}
Course.java:
public class Course {
private String courseName;
private int courseID;
private Teacher teacher;
private static int courseCount =0;
public Course(String courseName, Teacher teacher){
this.courseName = courseName;
this.teacher = teacher;
this.courseID =++courseCount;
}
public String getCourseName(){
return courseName;
}
public void setCourseName(String courseName){
this.courseName = courseName;
}
@Override
public String toString(){
return "Course ID: "+ courseID +"
Course Name: "+ courseName +"
Teacher: "+ teacher;
}
}
Teacher.java:
public class Teacher {
private String name;
private int teacherID;
private static int teacherCount =0;
public Teacher(String name){
this.name = name;
this.teacherID =++teacherCount;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
@Override
public String toString(){
return "Teacher ID: "+ teacherID +"
Name: "+ name;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

c. What steps can you take to help eliminate the stress?

Answered: 1 week ago