Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Java to create two classes for tracking students. One class is the Student c

ID: 3745131 • Letter: U

Question

Use Java to create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses.

Problem Scenario

CU Boulder needs a Java programmer to assist them with creating a grade book application. You have graciously volunteered to help. The university wants to track their students and their grades in various courses. For each student, the university wants to track this information:

1. Student id (String – a unique value for each student)

2. Student first name (String)

3. Student last name (String)

4. Student email address (String – a unique value for each student)

The university wants to make sure that they have a correct email address for each student. They want you to verify there is an “@” in the email address.

For each grade item, the university wants to track this information:

1.Grade Item id (Integer – a unique value for each grade item)

2.Student id (String – should match a student in the student list)

3.Course id (String)

4.Item type (String – must be one of the following: HW, Quiz, Class Work, Test, Final)

5.Date (String – format yyyymmdd)

6.Maximum score (Integer – must be greater than 0)

7.Actual score (Integer – must be in the range of 0 to maximum score)

Program Requirements

You have to create two classes for the problem scenario given above. The classes are:

A Student class

A Grade Item class

These two classes will be used in subsequent projects to instantiate the Student and Grade Item objects, and will not contain a main method or any I/O code. Your Student and Grade Item classes should each contain these methods:

Constructor

Get methods for each private variable

A toString method to display an instance of an object

An equals method to determine whether two instances of an object contain exactly the same data

Note: We will assume that our objects are immutable (unchanged once an object is instantiated) so we don’t need any set methods.

Constructors in each class should validate the data as follows:

In the Student class

Ensure all values for String fields are not blank. These are the student id, first name, last name and email address.

Ensure the student email address contains the “@” character. Hint: Use the contains method in the String class.

In the Grade Item class

Ensure all values for String fields are not blank. These are the student id, course id, item type and date.

All Grade item types must be one of the following: HW, Quiz, Class Work, Test, or Final. Use an array to store the types and search that array for a valid type. The entries are casesensitive (“HW” does not equal “Hw”).

Grade Item class: Maximum score must be greater than 0.

Grade Item class: Actual score must be in the range of 0 to maximum score.

If any of the data in either class is invalid, the constructor in which the error was detected must throw the IllegalArgumentException exception.

Note: Data required to initialize the fields will be passed by a method (defined in a subsequent project) to the constructor using arguments. Do not display any error messages or use the Scanner class to ask user for input.

Explanation / Answer

Here is your programs:

package srv.java;

import java.util.regex.Pattern;

public class Student {

private String studentId;

private String firstName;

private String lastName;

private String email;

// getters

public String getStudentId() {

return studentId;

}

public String getFirstName() {

return firstName;

}

public String getLastName() {

return lastName;

}

public String getEmail() {

return email;

}

// constructor

public Student(String studentId, String firstName, String lastName, String email) throws IllegalArgumentException {

if (studentId != null) {

this.studentId = studentId;

}

if (firstName != null) {

this.firstName = firstName;

}

if (lastName != null) {

this.lastName = lastName;

}

String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\." + "[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\.)+[a-z"

+ "A-Z]{2,7}$";

Pattern pat = Pattern.compile(emailRegex);

if (email != null) {

if (pat.matcher(email).matches()) {

this.email = email;

}

}

}

// toString method

@Override

public String toString() {

return "Student [studentId=" + studentId + ", firstName=" + firstName + ", lastName=" + lastName + ", email="

+ email + "]";

}

// equals method

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Student other = (Student) obj;

if (email == null) {

if (other.email != null)

return false;

} else if (!email.equals(other.email))

return false;

if (firstName == null) {

if (other.firstName != null)

return false;

} else if (!firstName.equals(other.firstName))

return false;

if (studentId == null) {

if (other.studentId != null)

return false;

} else if (!studentId.equals(other.studentId))

return false;

if (lastName == null) {

if (other.lastName != null)

return false;

} else if (!lastName.equals(other.lastName))

return false;

return true;

}

}

package srv.java;

import java.text.SimpleDateFormat;

import java.util.Arrays;

public class GradeItem {

private String itemId;

private String studentId;

private String courseid;

private String itemtype[];

private String date;

private int maximumScore;

private int actualScore;

// getters

public String getItemId() {

return itemId;

}

public String getStudentId() {

return studentId;

}

public String getCourseid() {

return courseid;

}

public String[] getItemtype() {

return itemtype;

}

public String getDate() {

return date;

}

public int getMaximumScore() {

return maximumScore;

}

public int getActualScore() {

return actualScore;

}

// constructor

public GradeItem(String itemId, String studentId, String courseid, String[] itemtype, String date, int maximumScore,

int actualScore) throws IllegalArgumentException {

if (itemId != null) {

this.itemId = itemId;

}

if (studentId != null) {

this.studentId = studentId;

}

if (courseid != null) {

this.courseid = courseid;

}

if (itemtype != null) {

this.itemtype = itemtype;

}

if (date != null) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");

this.date = sdf.format(date);

}

if (maximumScore > 0) {

this.maximumScore = maximumScore;

}

if (actualScore >= 0 && actualScore <= maximumScore) {

this.actualScore = actualScore;

}

}

// toString method

@Override

public String toString() {

return "GradeItem [itemId=" + itemId + ", studentId=" + studentId + ", courseid=" + courseid + ", itemtype="

+ Arrays.toString(itemtype) + ", date=" + date + ", maximumScore=" + maximumScore + ", actualScore="

+ actualScore + "]";

}

// equals method

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

GradeItem other = (GradeItem) obj;

if (actualScore != other.actualScore)

return false;

if (courseid == null) {

if (other.courseid != null)

return false;

} else if (!courseid.equals(other.courseid))

return false;

if (date == null) {

if (other.date != null)

return false;

} else if (!date.equals(other.date))

return false;

if (itemId == null) {

if (other.itemId != null)

return false;

} else if (!itemId.equals(other.itemId))

return false;

if (!Arrays.equals(itemtype, other.itemtype))

return false;

if (maximumScore != other.maximumScore)

return false;

if (studentId == null) {

if (other.studentId != null)

return false;

} else if (!studentId.equals(other.studentId))

return false;

return true;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote