Creating and Using Classes, Inheritance and Polymorphism Exam 1 Preparation Crea
ID: 3871117 • Letter: C
Question
Creating and Using Classes, Inheritance and Polymorphism Exam 1 Preparation Creating and Using Classes, Object-Oriented Thinking L. Java classes can represent real-world 2. The in a class, along with their values, model the state off an object -macass define the behavior of an object. 4. Create a class named Student with the following data members and visibilities name: String major: String age: double tpa: double 5. Create constructors for your Student class Create a no-ang default constructor and at least one convenience 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 8. Create a class named Course with the following data members and visibilities name: String ex: Calculus subject: String ex: MATH -number: int Wex: 116 credits: int llex:4 9. Create constructors for your Course dass. Create a arg default constructor at least one convenience 10. Create accessor lget) and mutator (set) methods for each data member 11. Modify StudentTest java so that it creates an instance of Course and a menber values for each of that course using mutator methods 12. Think about the relationships that exist in the real world for these two types of objects What are some ways they can be related? Think of at least two natural relationships involving a Student and a Course. 13. What are some ways we could implement these relationships in code using what we know about classes and objects? 1. What type of relationship do Vehicle and Engine have? 2. In that relationship, Vehicle is the class and Engine is the class a" Engine 3 We could describe that relationship as:Vehicle 4. How is this relationship implemented in Java? . How is this relationship represented in UML? Shapes 1 of the Java class relationships we have studied, what type of relationship do Shape and Circle have 2. Iin that relationship, Shape is the 3. We could describe that relationship as: Circle and Circle is the a Shape What Java keyword represents this relationship? S. How is this relationship represented in UML? 6. In the Rectangle class, are width and length instance or static members? 7. in the Shape class, is numShapes an instance or static member? How would you access t? 8. The data members in all of the shape-based classes are declared private. What action can be done to each class to allow access to those members without changing their visibility? Examine and execute the TestShapes java file myCircle, myCircleZ, myRectangle, and myRectangle are 2. How many constructors are called when creating a Shape? . How many constructors are called when creating a Circle a. What is the process called that accounts for this behavior? When weiting the Triangle class, the author forgot the toString) methoc What is the technical term for how this Which toString) gets invoked? Why? happens? a. 5. The getArea) method in Triangle invokes a super command with a method name. a What does the super command do? b. Which getArea) gets invoked? WhyExplanation / Answer
1. Java classes can represent real-world __entities/objects__.
2. The __attributes__ in a class, along with their values, model the state of an object.
3. The __methods__ in a class define the behaviour of an object.
4. Create a class named Student with the following data members and visibilities:
-name: String
-major: String
-age: double
-gpa: double
class Student
{
private String name;
private String major;
private double age;
private double gpa;
}
5. Create constructors for your Student class. Create a no-arg default constructor and
atleast one convenience constructor.
class Student
{
private String name;
private String major;
private double age;
private double gpa;
public Student()
{
name = "";
major = "";
age = 0.0;
gpa = 0.0;
}
public Student(String name, String major, double age, double gpa)
{
this.name = name;
this.major = major;
this.age = age;
this.gpa = gpa;
}
}
6. Create accessor (get) and mutator (set) methods for each data members.
class Student
{
private String name;
private String major;
private double age;
private double gpa;
public Student()
{
name = "";
major = "";
age = 0.0;
gpa = 0.0;
}
public Student(String name, String major, double age, double gpa)
{
this.name = name;
this.major = major;
this.age = age;
this.gpa = gpa;
}
public String getName() { return name; }
public String getMajor() { return major; }
public double getAge() { return age; }
public double getGPA() { return gpa; }
public void setName(String name) { this.name = name; }
public void setMajor(String major) { this.major = major; }
public void setAge(double age) { this.age = age; }
public void setGPA(double gpa) { this.gpa = gpa; }
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.