(in java programming language) help me in this GUI question AND BELOW THIS IS PA
ID: 3720443 • Letter: #
Question
(in java programming language)
help me in this GUI question
AND BELOW THIS IS PART #5 -b
__________
( WrongQuizGradeException.java)
public class WrongQuizGradeException extends Exception {
WrongQuizGradeException(){
System.err.println("Quizz Grade Must Be Between 0 and 10!!!!"); } }
___________
(Student.java)
import java.util.ArrayList;
import java.util.Iterator;
public class Student {
private String name;
private Integer ID;
private Double GPA;
private ArrayList<Double> GradesList=new ArrayList<Double>();
Student (String name, Integer ID, Double GPA){ this.name=name;
this.ID=ID;
this.GPA=GPA;
}
public void SetName(String n) {name=n;}
public void SetID(Integer id) {ID=id;}
public void SetGPA(Double GPA) {this.GPA=GPA;}
public String getName() {return name;}
public Integer getID() {return ID;}
public Double getGPA() {return GPA;}
public void addQuiz (double grade) throws WrongQuizGradeException {
if (grade<0 || grade >10) {
throw new WrongQuizGradeException();
}
GradesList.add(grade);
}
public double quizzesAvg() {
Iterator<Double> I=GradesList.iterator();
double sum=0.0;
while (I.hasNext()) {
sum+=I.next();
}
return sum/GradesList.size();
}
public void Print() {
System.out.println("Name: "+name+" ID: "+ID+" GPA: "+GPA);
System.out.println("The Quizes Grades:"); Iterator<Double> I=GradesList.iterator();
while (I.hasNext()) {
System.out.print(I.next()+" ");
}
System.out.println(" The Avg: "+quizzesAvg());
}
}
_____________
(Test.java)
public class Test {
public static void main(String[] args) {
Student S=new Student ("Ali",67,3.0);
try {
S.addQuiz(9);
} catch (WrongQuizGradeException e) {
e.getMessage();
}
try {
S.addQuiz(11);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(7);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(-1);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(5);
} catch (WrongQuizGradeException e) { e.getMessage();
}
//System.out.println(S.quizzesAvg());
S.Print(); } }
Explanation / Answer
public class WrongQuizGradeException extends Exception {
WrongQuizGradeException(){
System.err.println("Quizz Grade Must Be Between 0 and 10!!!!"); } }
___________
(Student.java)
import java.util.ArrayList;
import java.util.Iterator;
public class Student {
private String name;
private Integer ID;
private Double GPA;
private ArrayList<Double> GradesList=new ArrayList<Double>();
Student (String name, Integer ID, Double GPA){ this.name=name;
this.ID=ID;
this.GPA=GPA;
}
public void SetName(String n) {name=n;}
public void SetID(Integer id) {ID=id;}
public void SetGPA(Double GPA) {this.GPA=GPA;}
public String getName() {return name;}
public Integer getID() {return ID;}
public Double getGPA() {return GPA;}
public void addQuiz (double grade) throws WrongQuizGradeException {
if (grade<0 || grade >10) {
throw new WrongQuizGradeException();
}
GradesList.add(grade);
}
public double quizzesAvg() {
Iterator<Double> I=GradesList.iterator();
double sum=0.0;
while (I.hasNext()) {
sum+=I.next();
}
return sum/GradesList.size();
}
public void Print() {
System.out.println("Name: "+name+" ID: "+ID+" GPA: "+GPA);
System.out.println("The Quizes Grades:"); Iterator<Double> I=GradesList.iterator();
while (I.hasNext()) {
System.out.print(I.next()+" ");
}
System.out.println(" The Avg: "+quizzesAvg());
}
}
_____________
(Test.java)
public class Test {
public static void main(String[] args) {
Student S=new Student ("Ali",67,3.0);
try {
S.addQuiz(9);
} catch (WrongQuizGradeException e) {
e.getMessage();
}
try {
S.addQuiz(11);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(7);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(-1);
} catch (WrongQuizGradeException e) { e.getMessage();
}
try {
S.addQuiz(5);
} catch (WrongQuizGradeException e) { e.getMessage();
}
//System.out.println(S.quizzesAvg());
S.Print();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.