Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.
Week 1
Class diagrams show the classes of the system, their relationships, and the attributes and operations (methods).
Classes form the main building blocks of an object-oriented application.
User |
---|
- userId : int - firstName : String - lastName : String |
+ getUserId() : int + setUserId(int) : void + getFirstName() : String + setFirstName(String) : void + getLastName() : String + setLastName(String) : void + toString() : String |
Name |
---|
- attributes |
+ methods |
User |
---|
- userId : int - firstName : String - lastName : String |
+ getUserId() : int + setUserId(int) : void + getFirstName() : String + setFirstName(String) : void + getLastName() : String + setLastName(String) : void + toString() : String |
User |
---|
- userId : int - firstName : String - lastName : String |
+ getUserId() : int + setUserId(int) : void + getFirstName() : String + setFirstName(String) : void + getLastName() : String + setLastName(String) : void + toString() : String |
Professor |
---|
- salary : double |
+ getSalary(): double + setSalary(double): void + toString(): String |
Student |
---|
- gradeLevel : int - gpa : double |
+ getGradeLevel(): int + setGradeLevel(int): void + getGpa(): int + setGpa(int): void + toString(): String |
User |
---|
- userId : int - firstName : String - lastName : String |
+ getUserId : int + setUserId : void + getFirstName : String + setFirstName : void + getLastName : String + setLastName : void + toString : String |
is a
is a
Objects are often associated with other objects.
For example:
A professor instructs a course
A student enrolls in a course
A course has enrollments
Associations are modeled as lines connecting the two classes.
Associations can be clarified by depicting labels and directionality.
Enrollment |
---|
- student : Student - course : Course - finalGrade : char |
+ getStudent(): Student + setStudent(Student): void + getSection(): Section + setSection(Section): void + getFinalGrade(): char + setFinalGrade(char): void + toString() |
Course |
---|
- courseId : int - title: String - featured: boolean |
+ getCourseId(): int + setCourseId(int): void + getTitle(): String + setTitle(String): void + isFeatured(): boolean + setFeatured(boolean): void + toString(): String |
instructs
has
has
Professor |
---|
Student |
---|
User |
---|
Enrollment |
---|
Student |
---|
GradeReport |
---|
- student : Student - enrollments : List<Enrollment> - dateCreated : LocalDate |
// methods omitted |
receives
composed of
has
The multiplicity of the association is labeled on either end of the line, one multiplicity indicator for each direction
Each student has 0 or more enrollments.
Each enrollment has 1 student.
Each professor instructs 0 to 5 courses.
Each course has 1 to 3 professors.
Indicator | Meaning |
---|---|
0..1 | Zero or one |
0..* | Zero or more |
0..n (such as 0..10) | Zero to n (such as zero to ten) |
n (such as 1) | Exactly n (Only one) |
1..* | One or more |
1..n (such as 1..10) | One to n (such as one to ten) |
Enrollment |
---|
Course |
---|
Professor |
---|
Student |
---|
User |
---|
1
0..*
0..6
1..3
1
0..*
Each course has 0 or more enrollments.
Each enrollment has 1 course.
Your Task:
With the direction of the teacher, create a complete class diagram using one of the tools above.
Your Task:
Identify six nouns from the problem domain above that can be used as classes.
Use a diagramming tool to create a class diagram with access modifiers, data types, parameters, return types, inheritance, associations, composition, multiplicity, and annotations.
*.class
package edu.kirkwood.learnx.model;
public class LearnxUser {
private int userId;
private String firstName;
private String lastName;
public LearnxUser() {}
public LearnxUser(int userId, String firstName, String lastName) {
this.userId = userId;
this.firstName = firstName;
this.lastName = lastName;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "LearnxUser [userId=" + userId + ", firstName=" + firstName + ", lastName="
+ lastName + "]";
}
}
package edu.kirkwood.learnx.model;
public class Student extends LearnxUser {
private int gradeLevel;
private double gpa;
public Student() {
super();
}
public Student(int userId, String firstName, String lastName, int gradeLevel, double gpa) {
super(userId, firstName, lastName);
this.gradeLevel = gradeLevel;
this.gpa = gpa;
}
public int getGradeLevel() {
return gradeLevel;
}
public void setGradeLevel(int gradeLevel) {
this.gradeLevel = gradeLevel;
}
public double getGpa() {
return gpa;
}
public void setGpa(double gpa) {
this.gpa = gpa;
}
@Override
public String toString() {
return "Student [userId=" + getUserId() + ", firstName=" + getFirstName() + ", lastName="
+ getLastName() + ", gradeLevel=" + gradeLevel + ", gpa=" + gpa + "]";
}
}
package edu.kirkwood.learnx.data;
import java.util.ArrayList;
import java.util.List;
import edu.kirkwood.learnx.model.Student;
public class StudentDAO {
public static List<Student> getSampleStudents() {
List<Student> students = new ArrayList<>();
students.add(new Student());
students.add(new Student(1, "Marc", "Hauschildt", 12, 3.65));
return students;
}
}
package edu.kirkwood.learnx;
import java.util.List;
import edu.kirkwood.learnx.data.StudentDAO;
import edu.kirkwood.learnx.model.Student;
public class SeatingChartBuilder {
public static void main(String[] args) {
List<Student> students = StudentDAO.getSampleStudents();
for(Student student: students) {
System.out.println(student);
}
}
}
git init -b main
git checkout -b main
git add .
git config --global user.name "YOUR FULL NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
git commit -m "initial commit"
git remote add origin https://github.com/YOUR-USERNAME/java2-demos.git
git push origin main
git config --global credential.helper cache
git init -b main
git checkout -b main
.env
# Key=Value
Initial commit
git remote add origin https://github.com/YOUR-USERNAME/java-demos.git
git config --global credential.helper cache
By Marc Hauschildt
Web Technologies and Computer Software Development Instructor at Kirkwood Community College in Cedar Rapids, IA.