Question
Using netbeans Java : Can anyone help me to solve this: Objective/s: At the end of this activity, you should be able to: Utilize the
Using netbeans Java : Can anyone help me to solve this:
Objective/s:
At the end of this activity, you should be able to:
Utilize the knowledge gained in this module to create an application that relies on polymorphism and inheritance
Understand the difference between polymorphism and inheritance
Use an abstract class and an interface
StudentRecord
Class Names: Lab8Main (main class)
StudentRecord:
public class StudentRecord {
//these are the attributes
private String name;
private double mathGrade;
private double englishGrade;
private double scienceGrade;
//these are the mutators and accessors
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMathGrade() {
returnmathGrade;
}
public void setMathGrade(double mathGrade) {
this.mathGrade = mathGrade;
}
public double getEnglishGrade() {
returnenglishGrade;
}
public void setEnglishGrade(double englishGrade) {
this.englishGrade = englishGrade;
}
public double getScienceGrade() {
returnscienceGrade;
}
public void setScienceGrade(double scienceGrade) {
this.scienceGrade = scienceGrade;
}
//custom method
public double computeAverageGrade(){
return (this.mathGrade + this.englishGrade + this.scienceGrade)/3;
}
}
ComputerScienceStudentRecord
The StudentRecord class is given for your reference. The following are your tasks:
Test Stem / Question | Choices |
1: Create a class that will inherit the attributes and methods of the StudentRecord class. What keyword is used in order create a parent-child relationship between two classes? | A: extends |
B: implements | |
C: extension | |
D: overloads | |
2: How will you declare that class. Use the ComputerScienceStudentRecord as the identifier of the class. | A: public class ComputerScienceStudentRecord extends StudentRecord { // body } |
B: public class StudentRecord extends ComputerScienceStudentRecord{ // body } | |
C: public class ComputerScienceStudentRecord implements StudentRecord { // body } | |
D: public class ComputerScienceStudentRecord overloads StudentRecord { // body } | |
3: Overload the StudentRecord constructor with one that accepts 4 parameters namely the name, mathGrade, englishGrade and scienceGrade. | A: public ComputerScienceStudentRecord (final String name, final int mathGrade, final int englishGrade, final int scienceGrade) { // body } |
B: public ComputerScienceStudentRecord (final name, final mathGrade, final englishGrade, final scienceGrade) { // body } | |
C: @overloads public ComputerScienceStudentRecord (final name, final mathGrade, final englishGrade, final scienceGrade) { // body } | |
D: @overloads public ComputerScienceStudentRecord (final String name, final int mathGrade, final int englishGrade, final int scienceGrade) { // body } | |
4: Now set the values of the parameters to the attributes of the class. What keyword will you use? | A: this |
B: super | |
C: just use the setter. This is the suggested way to do that. | |
D: no need for keyword, you can just use the = sign. | |
5: Create an attribute named computerProgrammingGrade with primitive int data type. How will you do that? | A: private int computerProgrammingGrade = 0; |
B: private Integer computerProgrammingGrade = 0; | |
C: private double computerProgrammingGrade = 0; | |
D: private computerProgrammingGrade = 0; | |
6: Now override the computeAverageGrade. How will you do that? | A: @override public double computeAverageGrade() //body } |
B: @overrides public double computeAverageGrade() //body } | |
C: @overrides public double super.computeAverageGrade() //body } | |
D: public double super.computeAverageGrade() //body } | |
7: What pillar of Object Oriented Programming is used when we override a method from the super type? | A: Both Inheritance and Polymorphism |
B: Polymorphism only since we are using the method to morph into another with different implementation | |
C: Inheritance only. | |
D: All of the concept applies. | |
8: Now try to make the computeAverageGrade private. Can you still access it in your subclass? | A: No. Private classes can only be access in the class that it belongs to. |
B: Yes. All are inherited by the subclass. | |
C: It depends on the additional modifier. | |
D: Yes. As long as you use the super keyword. | |
9: Now try to make the computeAverageGrade final. Run and compile. What happens in your subclass? | A: Returns an error because final method cannot be overriden. |
B: Returns an error because it is not possible to declare a method final. It only applies to attributes. | |
C: It is no longer visible in the sub class. | |
D: Nothing. The code run perfectly even if there is an overriden method in the subclass. | |
10: Create a test class with a main method. Create an instance of ComputerScienceStudentRecord. Which of the following is the possible way to do that?
ComputerScienceStudentRecord studentRecord = ComputerScienceStudentRecord(List Marie, 91, 92, 93) B. StudentRecord studentRecord = ComputerScienceStudentRecord(List Marie, 91, 92, 93) | A: A only. |
B: B only. | |
C: Both A & B. | |
D: None of the choices. |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started