The language is Java, no UML diagram is needed just a working program with neces
ID: 3585524 • Letter: T
Question
The language is Java, no UML diagram is needed just a working program with necessary objects
Explanation / Answer
public class Student{
//Declare variables
private String Name;
private double Test1;
private double Test2;
private double Test3;
//default Constructor
public Student(){
this.Name = "No Name";
this.Test1 = 0.0;
this.Test2 = 0.0;
this.Test3 = 0.0;
}
//Constructor with arguments
public Student(String Name,double Test1,double Test2, double Test3){
this.Name = Name;
this.Test1 = Test1;
this.Test2 = Test2;
this.Test3 = Test3;
}
//setter methods
public void setName(String Name){
this.Name = Name;
}
public void setTest1(double Test1){
this.Test1 = Test1;
}
public void setTest2(double Test2){
this.Test2 = Test2;
}
public void setTest3(double Test3){
this.Test3 = Test3;
}
//getter methods
public String getName(){
return this.Name;
}
public double getTest1(){
return this.Test1;
}
public double getTest2(){
return this.Test2;
}
public double getTest3(){
return this.Test3;
}
//average method
public double getAverage(){
return (this.Test1 + this.Test2 + this.Test3)/3.0;
}
//main method
public static void main(String args[]){
Student s = new Student("Student Name",1.0,2.0,3.0);
System.out.println("Average : "+s.getAverage());
}
}
/* sample output
Average : 2.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.