Question

In: Computer Science

Write a class encapsulating the concept of a Student, assuming that the Student has the following...

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.

Solutions

Expert Solution

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


Related Solutions

Write a class encapsulating the concept of a Student, assuming that a student has the following...
Write a class encapsulating the concept of a Student, assuming that a student has the following attributes: last name, first name, id, array of grades. Include a constructor, the accessors and mutators, and method toString. Also code the following methods: one returning the GPA using the array of grades (assuming each grade represents a course grade and all courses have the same number of credit hours) and a method to add a course grade to the array of grades (this...
Write a class encapsulating the concept of the weather forecast, assuming that it has the following...
Write a class encapsulating the concept of the weather forecast, assuming that it has the following attributes: the temperature and the sky conditions (e.g. sunny, snowy, cloudy, rainy, etc.).  Include a default constructor, an overloaded constructor, accessors and mutators, and the methods, toString() and equals(). Temperature, in Fahrenheit, should be between -50 and +150; the default value is 70, if needed. The default sky condition is sunny. In Addition, include a method that converts Fahrenheit to Celsius. Celsius temperature = (Fahrenheit...
In the programming language java: Write a class encapsulating the concept of a telephone number, assuming...
In the programming language java: Write a class encapsulating the concept of a telephone number, assuming a telephone number has only a single attribute: aString representing the telephone number. Include a constructor, the accessor and mutator, and methods 'toString' and 'equals'. Also include methods returning the AREA CODE (the first three digits/characters of the phone number; if there are fewer than three characters in the phone number of if the first three characters are not digits, then this method should...
Write a class encapsulating the concept of a corporate name (for example, IBM), assuming a corporate...
Write a class encapsulating the concept of a corporate name (for example, IBM), assuming a corporate name has the following attribute: the corporate name. Include a constructor, the accessors and mutators, and methods toString() and equals(). Also include and method that returns a potential domain name by adding a www. at the beginning and .com at the end of the corporate name (for instance, if the corporate name is IBM, that method should return www.ibm.com). Write a client class to...
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
1. Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and...
1. Write a superclass encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length; it has two methods that calculate and return its area and volume. You also need to include a client class (with the main method)...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The...
***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The program should allow creation an array of object instances to assign firstName, lastName and mark from input user and perform and assign grade based on mark’s criteria displayed below. MARKS INTERVAL 95 - 100 90 - <95 85 - <90 80 - <85 75 - <80 70 - <75 65 - <70 60 - <65 0 - <60 LETTER GRADE A+ A B+ B...
In class, we calculated the externality through tax revenues of educating a Binghamton student, assuming some...
In class, we calculated the externality through tax revenues of educating a Binghamton student, assuming some parameter values (e.g. that combined state and local taxes are 12% of earnings). Your guess about those parameter values might be different from what we used in class. What’s your personal guess about the values of those parameters? Take your guess about those parameter values and calculate the size of the externality. Is the state’s subsidy of Binghamton students’ education larger or smaller than...
In class, we calculated the externality through tax revenues of educating a Binghamton student, assuming some...
In class, we calculated the externality through tax revenues of educating a Binghamton student, assuming some parameter values (e.g. that combined state and local taxes are 12% of earnings). Your guess about those parameter values might be different from what we used in class. What’s your personal guess about the values of those parameters? Take your guess about those parameter values and calculate the size of the externality. Is the state’s subsidy of Binghamton students’ education larger or smaller than...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT