In: Computer Science
Write a class encapsulating the concept of a Student, assuming
that the Student has the following attributes:
the name of the student, the average of the student, and the
student’s GPA.
Include a default constructor, an overloaded constructor, the
accessors and mutators, and methods toString()
and equals(). Also include a method returning the letter grade base
on the following range for the average:
Average Range Letter Grade
90-100 A
85-89 B+
80-84 B
75-79 C+
70-74 C
65-69 D+
60-64 D
0-59 F
You do not need to write a client program or write comments.
public class Student {
private String name;
private double average;
private double gpa;
public Student() {
}
public Student(String aName, double aAverage, double aGpa) {
super();
name = aName;
average = aAverage;
gpa = aGpa;
}
public String getName() {
return name;
}
public double getAverage() {
return average;
}
public double getGpa() {
return gpa;
}
public void setName(String aName) {
name = aName;
}
public void setAverage(double aAverage) {
average = aAverage;
}
public void setGpa(double aGpa) {
gpa = aGpa;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(average);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(gpa);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@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 (Double.doubleToLongBits(average) != Double.doubleToLongBits(other.average))
return false;
if (Double.doubleToLongBits(gpa) != Double.doubleToLongBits(other.gpa))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Student [name=" + name + ", average=" + average + ", gpa=" + gpa + "]";
}
public String letterGrade() {
if (average >= 90)
return "A";
if (average >= 85)
return "B+";
if (average > 80)
return "B";
if (average >= 75)
return "C+";
if (average > 70)
return "C";
if (average >= 65)
return "D+";
if (average > 60)
return "D";
return "F";
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME