Question

In: Computer Science

Create a class called Student. Include the following instance variables: name, address, phone, gpa Create all...

Create a class called Student.

  • Include the following instance variables: name, address, phone, gpa
  • Create all of the methods required for a standard user defined class: constructors, accessors, mutators, toString, equals
  • Create the client for testing the Student class

Create another class called CourseSection

  • Include instance variables for: course name, days and times course meets (String), description of course, student a, student b, student c (all of type Student)
  • Create all of the methods required for a standard user defined class as before with Student

Create a client that tests the CourseSection class. Test the accessors, mutators, equals, to toString method. Ultimately, this will also be testing the Student class because instances of Student are in the Course Section class.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.



This is a very big question.
I have solved all of them. 
Please give me an upvote dear, Much Appreciated.!!

======
Stduent.java
======
package demo;

import java.util.Objects;

public class Student
{
    private String name;
    private String address;
    private String Phone;
    private double GPA;

    // Constructor

    public Student() {
    }

    public Student(String name, String address, String phone, double GPA) {
        this.name = name;
        this.address = address;
        Phone = phone;
        this.GPA = GPA;
    }
    // accessor and mutator

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return Phone;
    }

    public void setPhone(String phone) {
        Phone = phone;
    }

    public double getGPA() {
        return GPA;
    }

    public void setGPA(double GPA) {
        this.GPA = GPA;
    }

    // toString

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", Phone='" + Phone + '\'' +
                ", GPA=" + GPA +
                '}';
    }

    // equals()

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return Double.compare(student.getGPA(), getGPA()) == 0 &&
                Objects.equals(getName(), student.getName()) &&
                Objects.equals(getAddress(), student.getAddress()) &&
                Objects.equals(getPhone(), student.getPhone());
    }
    
}

=======

CourseSection.java

=======

package demo;

import java.util.Objects;

public class CourseSection
{
    private String courseName;
    private int days;
    private String timesCourseMeets;
    private String description;
    private Student a;
    private Student b;
    private Student c;

    // Constructor
    public  CourseSection()
    {

    }
    public CourseSection(String courseName, int days, String timesCourseMeets, String description, Student a, Student b, Student c) {
        this.courseName = courseName;
        this.days = days;
        this.timesCourseMeets = timesCourseMeets;
        this.description = description;
        this.a = a;
        this.b = b;
        this.c = c;
    }

    // Accessor and mutator

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public int getDays() {
        return days;
    }

    public void setDays(int days) {
        this.days = days;
    }

    public String getTimesCourseMeets() {
        return timesCourseMeets;
    }

    public void setTimesCourseMeets(String timesCourseMeets) {
        this.timesCourseMeets = timesCourseMeets;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Student getA() {
        return a;
    }

    public void setA(Student a) {
        this.a = a;
    }

    public Student getB() {
        return b;
    }

    public void setB(Student b) {
        this.b = b;
    }

    public Student getC() {
        return c;
    }

    public void setC(Student c) {
        this.c = c;
    }

    // toString()

    @Override
    public String toString() {
        return "CourseSection{" +
                "courseName='" + courseName + '\'' +
                ", days=" + days +
                ", timesCourseMeets='" + timesCourseMeets + '\'' +
                ", description='" + description + '\'' +
                ", a=" + a +
                ", b=" + b +
                ", c=" + c +
                '}';
    }


    // equals()

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CourseSection)) return false;
        CourseSection that = (CourseSection) o;
        return getDays() == that.getDays() &&
                Objects.equals(getCourseName(), that.getCourseName()) &&
                Objects.equals(getTimesCourseMeets(), that.getTimesCourseMeets()) &&
                Objects.equals(getDescription(), that.getDescription()) &&
                Objects.equals(getA(), that.getA()) &&
                Objects.equals(getB(), that.getB()) &&
                Objects.equals(getC(), that.getC());
    }

}

=======


Related Solutions

in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and...
Create a class called Vehicle that includes four instance variables:      name, type,     tank size and average petrol consumption. Provide 2 constructors, the first takes name and type as parameter, the second takes four parameters for the four instance variables. (2 pt) Provide also a method called distancePerTank that calculate the average distance that a vehicle can travel if the tank is full (multiplies the tank size by the average petrol consumption), then returns the value. (2 pt) Provide a...
with PHP Create a class called Employee that includes three instance variables—a first name (type String),...
with PHP Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary int). Provide a constructor that initializes the three instance data member. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its 0. Write a test app named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary....
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 PLEASE Create a class called Child with an instance data values: name and age....
IN JAVA PLEASE Create a class called Child with an instance data values: name and age. a. Define a constructor to accept and initialize instance data b. include setter and getter methods for instance data c. include a toString method that returns a one line description of the child
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
Create a class called Sphere. The class will contain the following    Instance data double radius...
Create a class called Sphere. The class will contain the following    Instance data double radius Methods Constructor with one parameter which will be used to set the radius instance data Getter and Setter for radius             Area - calculate the area of the sphere (4 * PI * radius * radius)             Volume - calculate and return the volume of the sphere (4/3 * PIE * radius * radius * radius) toString - returns a string with the...
I need to add variables such as name, address and phone into a Jpanel in the...
I need to add variables such as name, address and phone into a Jpanel in the constructor called AddressBook. I then need to add that panel into a Jframe and call it in the main method how would i do that in java.
Create a class that holds data about a job applicant. Include a name, a phone number,...
Create a class that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics: Include a constructor that accepts values for each of the fields. Also include a get method for each field. Create an application that instantiates several job applicant objects and pass each in turn to a Boolean method that determines whether each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT