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 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...
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 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....
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file....
Create a client for your BankAccount classcalled BankAccountClient.java.    This a separate file from the BankAccount file. Both files must be in the same directory to compile. Display all dollar amounts using the DecimalFormat class. Create an account Ask the user for the type of account, the bank account number, the amount that they will deposit to start the account. Set interest earned to 0. Print the account information using an implicit or explicit call to toString Update an account Use...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character)...
6) Consider the following class descriptions for objects in a video game: An NPC (non-player character) in a video game has some basic data that belongs to all entities in a game. All NPCs have a name, which is a String, health, which is an integer, and a description, which is a String. NPCs have accessor methods for each of their instance variables. NPCs also have an act() method, which is void; however, since there are no true NPCs in...
1. In C++, programmers can use a class to create a large number of instance variables...
1. In C++, programmers can use a class to create a large number of instance variables of the class's type. Group of answer choices True False 2. When a C++ programmer declares a function, they are required to state all of the following except Group of answer choices {} The type of data, if any, returned by the function The function name The type of data, if any, sent to the function 3. When a C++ programmer calls a function,...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to...
In java //Create a New Project called LastNameTicTacToe.// //Write a class (and a client class to test it) that encapsulates a tic-tac-toe board. // A tic-tac-toe board looks like a table of three rows and three columns partially or completely filled with the characters X and O. // At any point, a cell of that table could be empty or could contain an X or an O. You should have one instance variable, a two-dimensional array of values representing the...