I am using Java netbeans to program this file. Please write code in java, thanks
ID: 3883404 • Letter: I
Question
I am using Java netbeans to program this file. Please write code in java, thanks
Define a class Student which extends Person defined in class. It adds the attributes
Int Test1, test2, test3
Double average
String grade
Define a constructor which takes all the attributes of person and uses a default value of 0 for the test scores, “unknown” for grade and 0 for aversge. It has methods computeaverage() and calculategrade(). The grades are based on the average, with above 92 an A, 85 to 92 a B, 70 to 85 a C, 60 to 70 a D etc. Grades only has a getter. All other attributes have a setter and a getter.
Explanation / Answer
Note:- While writing the below code I assumed that Person class has only attribute 'name'. Please modify the constructor according to your Person class.
public class Student extends Person{
private int Test1, test2, test3;
private double average;
private String grade;
public Student(String name) {
super(name);
Test1=0;
test2=0;
test3=0;
average=0;
grade="unknown";
}
public double computeaverage(){
double ave=(Test1+test2+test3)/(double)3;
average=ave;
return ave;
}
public String calculategrade(){
if(computeaverage()>92){
return "A";
}else if(computeaverage() >85 && computeaverage() <= 92){
return "B";
}else if(computeaverage() >70 && computeaverage() <= 85){
return "C";
}else if(computeaverage() >=60 && computeaverage() <= 70){
return "D";
}else{
return "F";
}
}
public int getTest1() {
return Test1;
}
public void setTest1(int Test1) {
this.Test1 = Test1;
}
public int getTest2() {
return test2;
}
public void setTest2(int test2) {
this.test2 = test2;
}
public int getTest3() {
return test3;
}
public void setTest3(int test3) {
this.test3 = test3;
}
public double getAverage() {
return average;
}
public void setAverage(double average) {
this.average = average;
}
public String getGrade() {
return grade;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.