Question

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 (5 points extra credit)

Create another class called CourseSection (20 points extra credit)

  • 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.

Submit the .java files for each of the 2 classes as well as the file containing the client.

Homework Answers

Answer #1
//TestStudent.java
public class TestStudent {
        public static void main(String[] args) {
                //creating 2 objects
                Student s1 = new Student("Uday", "Hyd", "12323",3.5);
                Student s2 = new Student("Uday", "Hyd", "12323",3.5);
                // printing 2 objects. toString wil be called 
                System.out.println(s1);
                System.out.println(s2);
                //checking equal method
                System.out.println("Equal? "+(s1.equals(s2)));
        }
}
//Student.java
class Student{
        private String name;
        private String address;
        private String phone;
        private double gpa;
        /**
         * Constructor taking parameters
         * @param aName
         * @param aAddress
         * @param aPhone
         * @param aGpa
         */
        public Student(String aName, String aAddress, String aPhone, double aGpa) {
                super();
                name = aName;
                address = aAddress;
                phone = aPhone;
                gpa = aGpa;
        }
        //getters and setters
        public String getName() {
                return name;
        }
        public String getAddress() {
                return address;
        }
        public String getPhone() {
                return phone;
        }
        public double getGpa() {
                return gpa;
        }
        public void setName(String aName) {
                name = aName;
        }
        public void setAddress(String aAddress) {
                address = aAddress;
        }
        public void setPhone(String aPhone) {
                phone = aPhone;
        }
        public void setGpa(double aGpa) {
                gpa = aGpa;
        }
        //tostring
        @Override
        public String toString() {
                return "Student [name=" + name + ", address=" + address + ", phone=" + phone + ", gpa=" + gpa + "]";
        }

        @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 (address == null) {
                        if (other.address != null)
                                return false;
                } else if (!address.equals(other.address))
                        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;
                if (phone == null) {
                        if (other.phone != null)
                                return false;
                } else if (!phone.equals(other.phone))
                        return false;
                return true;
        }
        
        
}


//CourseSection.java
class CourseSection{
        private String courseName;
        private int days;
        private String courseMeets;
        private String description;
        private Student a;
        private Student b;
        private Student c;
        //constructor to initialize the variables
        public CourseSection(String aCourseName, int aDays, String aCourseMeets, String aDescription, Student aA,
                        Student aB, Student aC) {
                super();
                courseName = aCourseName;
                days = aDays;
                courseMeets = aCourseMeets;
                description = aDescription;
                a = aA;
                b = aB;
                c = aC;
        }
        //setters and getters
        public String getCourseName() {
                return courseName;
        }
        public int getDays() {
                return days;
        }
        public String getCourseMeets() {
                return courseMeets;
        }
        public String getDescription() {
                return description;
        }
        public Student getA() {
                return a;
        }
        public Student getB() {
                return b;
        }
        public Student getC() {
                return c;
        }
        public void setCourseName(String aCourseName) {
                courseName = aCourseName;
        }
        public void setDays(int aDays) {
                days = aDays;
        }
        public void setCourseMeets(String aCourseMeets) {
                courseMeets = aCourseMeets;
        }
        public void setDescription(String aDescription) {
                description = aDescription;
        }
        public void setA(Student aA) {
                a = aA;
        }
        public void setB(Student aB) {
                b = aB;
        }
        public void setC(Student aC) {
                c = aC;
        }
        //toString
        @Override
        public String toString() {
                return "CourseSection [courseName=" + courseName + ", days=" + days + ", courseMeets=" + courseMeets
                                + ", description=" + description + ", a=" + a + ", b=" + b + ", c=" + c + "]";
        }
        
        //equls method
        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                CourseSection other = (CourseSection) obj;
                if (a == null) {
                        if (other.a != null)
                                return false;
                } else if (!a.equals(other.a))
                        return false;
                if (b == null) {
                        if (other.b != null)
                                return false;
                } else if (!b.equals(other.b))
                        return false;
                if (c == null) {
                        if (other.c != null)
                                return false;
                } else if (!c.equals(other.c))
                        return false;
                if (courseMeets == null) {
                        if (other.courseMeets != null)
                                return false;
                } else if (!courseMeets.equals(other.courseMeets))
                        return false;
                if (courseName == null) {
                        if (other.courseName != null)
                                return false;
                } else if (!courseName.equals(other.courseName))
                        return false;
                if (days != other.days)
                        return false;
                if (description == null) {
                        if (other.description != null)
                                return false;
                } else if (!description.equals(other.description))
                        return false;
                return true;
        }
        
}
//TestCourseSection.java
public class TestCourseSection {
        public static void main(String[] args) {
                //creating 3 student objects 
                Student a = new Student("Uday", "Hyd", "12323",3.5);
                Student b = new Student("Virat", "BLR", "12312",3.3);
                Student c = new Student("Keerthi", "CSK", "12343",3.9);
                //creaeting 2 CouseSection Objects
                CourseSection cs1 = new CourseSection("Java", 35, "Java programs", "Core Java", a, b, c);
                CourseSection cs2 = new CourseSection("Java", 35, "Java programs", "Core Java", a, b, c);
                //calling toString
                System.out.println(cs1);
                System.out.println(cs2);
                //calling equal
                System.out.println("Equal? "+(cs1.equals(cs2)));
        }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

Please Like and Support me as it helps me a lot

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a class Student with the states (attributes): Name, address, phone number, Student ID. Also define...
Create a class Student with the states (attributes): Name, address, phone number, Student ID. Also define the behavior of student as learn, perform assignment, read, attendance, do presentation (Exemple: My name is {Name}). After that create 3 instances of the class Student and present the instance (My name is .....)  
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String),...
Create a class called Employee that contains three instance variables (First Name (String), Last Name (String), Monthly Salary (double)). Create a constructor that initializes these variables. Define set and get methods for each variable. If the monthly salary is not positive, do not set the salary. Create a separate test class called EmployeeTest that will use the Employee class. By running this class, create two employees (Employee object) and print the annual salary of each employee (object). Then set the...
We encourage you to work in pairs for this challenge to create a Student class with...
We encourage you to work in pairs for this challenge to create a Student class with constructors. First, brainstorm in pairs to do the Object-Oriented Design for a Student class. What data should we store about Students? Come up with at least 4 different instance variables. What are the data types for the instance variables? Write a Student class below that has your 4 instance variables and write at least 3 different constructors: one that has no parameters and initializes...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
Write the program in java Implement a class Product. Create instance variables to store product name...
Write the program in java Implement a class Product. Create instance variables to store product name and price and supply the values through constructor. For example new Product(“Toaster’, 29.95). Create methods, getName, getPrice. Write a method productPrinter that prints the product name and its price after reducing it by $5. Create a main class and necessary constructs in the main class to run the Product class.
Write C++ program to create a student record include a student ID, first name, nickname, course,...
Write C++ program to create a student record include a student ID, first name, nickname, course, subject, and subject marks. Task: Create a function to insert a number of students in the record. Create a function to print all student information by a table. Create a function to print all student information that they're in a specific course chosen by user input. Create a function to search for a student by student ID and print student information. Create a function...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and...
In JAVA write the following program: Objective: Practice object-oriented principles by making two Peanut Butter and Jelly Sandwiches. The program must create two sandwiches based on user input. The sandwich information for both must then print out their details and determine if the two sandwiches are equal. Requirements: Write a class called Bread with the following Instance Variables Name: The name brand of the bread. o   Calories: The number of calories per slice assumed to be between 50 and 250 inclusively....
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two...
****in java Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also define...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT