Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Creating and Using Classes, Object-Oriented Thinking 1. Java classes can represe

ID: 3871739 • Letter: C

Question

Creating and Using Classes, Object-Oriented Thinking 1. Java classes can represent real-world 2. The in a class, along with their values, model the state of an object. 3. The in a class define the behavior of an object. Create a class named Student with the following data members and visibilities: -name: String -major: String -age: double gpa: double Create constructors for your Student class. Create a no-arg default constructor and at least one convenience constructor. 4. 5. 6. Create accessor (get) and mutator (set) methods for each data member. 7. Write a test script named StudentTest.java that creates an instance of Student and gives each data member values using mutator methods. Create a class named Course with the following data members and visibilities: -name: String -subject: String -number: int -credits: int 8. I/ex: Calculus I I/ ex: MATH Ilex: 1161 // ex: 4 . Create constructors for your Course class. Create a no-arg default constructor and at one convenience constructor. Create accessor (get) and mutator (set) methods for each data member. . Modify StudentTest.java so that it creates an instance of Course and fills in data mem values for each of that course using mutator methods. Think about the relationships that exist in the real world for these two types of obje What are some ways they can be related? Think of at least two natural relationshi involving a Student and a Course What are some ways we could implement these relationships in code using what w about classes and objects?

Explanation / Answer

ANSWER:

1) Yes. Using object oriented programming

4) Student class with data members and visibilities

public class Student {

private String name;

private String major;

private double age;

private double gpa;

}

5) Default constructor and parameterized constructor

public Student() {

super();

}

public Student(String name, String major, double age, double gpa) {

super();

this.name = name;

this.major = major;

this.age = age;

this.gpa = gpa;

}

6) getters and setters for above student class

public class Student {

private String name;

private String major;

private double age;

private double gpa;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getMajor() {

return major;

}

public void setMajor(String major) {

this.major = major;

}

public double getAge() {

return age;

}

public void setAge(double age) {

this.age = age;

}

public double getGpa() {

return gpa;

}

public void setGpa(double gpa) {

this.gpa = gpa;

}

}

7) Using mutator methods

public class StudentTest {

public static void main(String[] args) {

// creating instance for Student class

Student student = new Student();

student.setName("Pathan");

student.setMajor("YES");

student.setAge(24.3);

student.setGpa(1500.23);

}

}

Let me know any concerns. Thank you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote