Question

In: Computer Science

Write a class encapsulating the concept of a student, assuming a student has the following attributes:...

Write a class encapsulating the concept of a student, assuming a student has the following attributes: a name, a Social Security number, and a GPA (for instance, 3.5). Include a constructor, the accessors and mutators, and methods toString and equals. Write a client class (test driver with main method) to test all the methods in your class (create 2 student objects, print the name, social security number and GPA of the 2 students, check if the two student’s GPA is the same or equal, change the name of the first student).

Solutions

Expert Solution

class Student
{
   private String name;
   private String SSN;
   private double GPA;
  
   //constructors
   public Student(String name,String SSN,double GPA)
   {
       this.name = name;
       this.SSN = SSN;
       this.GPA = GPA;
   }
   public Student()
   {
       name = " ";
       GPA = 0.0;
       SSN = " ";
   }
  
  
   //accessors and mutators
   public void setName(String name)
   {
       this.name = name;
   }
   public String getName()
   {
       return name;
   }
   public void setSSN(String SSN)
   {
       this.SSN = SSN;
   }
   public String getSSN()
   {
       return SSN;
   }
   public void setGPA(double GPA)
   {
       this.GPA = GPA;
   }
   public double getGPA()
   {
       return GPA;
   }
  
   public boolean equals(Student s)
   {
       if(this.name == s.name && this.SSN == s.SSN && this.GPA == s.GPA)
       return true;
       else
       return false;
   }
   public String toString()
   {
       return "Student Name : "+name+" SSN : "+SSN +" GPA : "+GPA;
   }
}


class TestStudent
{
   public static void main (String[] args)
   {
       Student s1 = new Student("James Hawkings","668798809",3.77);
      
       System.out.println(s1);
      
       Student s2 = new Student();
       s2.setName("Camy Lara");
       s2.setSSN("768708099");
       s2.setGPA(4.5);
       System.out.println(s2);
      
       System.out.println(s1.equals(s2));
   }
}

Output:

Student Name : James Hawkings  SSN : 668798809  GPA : 3.77
Student Name : Camy Lara  SSN : 768708099  GPA : 4.5
false

Do ask if any doubt. Please upvote.


Related Solutions

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...
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 a Student Employee, assuming that a student has the...
Write a class encapsulating the concept of a Student Employee, assuming that a student has the following attributes: last name, first name, id, array of hours worked weekly. Include a constructor, the accessors and mutators, and method toString. Also code the following methods: one returning the average weekly hours and a method to add the hours to the array of hoursWorked (this means creating a large array). Let this array store the weekly hours (not daily hours) worked for each...
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)...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score...
Implement a class Student, including the following attributes and methods: Two public attributes name(String) and score (int). A constructor expects a name as a parameter. A method getLevel to get the level(char) of the student. score level table: A: score >= 90 B: score >= 80 and < 90 C: score >= 60 and < 80 D: score < 60 Example:          Student student = new Student("Zack"); student.score = 10; student.getLevel(); // should be 'D'. student.score = 60; student.getLevel(); //...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name...
Using Python Define a Student class. A Student class needs to have two attributes, the student_name and strudent_grade . It also has three methods as follows: set_grade(grade) that sets the grade of the student. get_grade returns the grade of the student. print_student_info that print the name and grade of student in a formatted string. In the math_utils.py file define a function called average_grade(roster) . This method accepts as input a list of Student Objects and returns the average of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT