Just wanted to know if i coded the method on calculating the GPA and staus of th
ID: 3545804 • Letter: J
Question
Just wanted to know if i coded the method on calculating the GPA and staus of the candidates properly
Appreciate it!
I'm asked to:
Create a Candidate class. It will contain instance variables for the candidate name, the grades and the average. You will need a method to calculate the GPA, and determine the status of the candidates.
calculate the GPA (grade point average) based on the following:
A = 4.0, B = 3.0, C = 2.0, D = 1.0, E = 0.0, F = 0.0.
The application will then determine the status of each candidate based on the following:
Explanation / Answer
public class Candidate {
//Instance variables for the candidate name, the grades, and the average
private String firstName;
private String lastName;
private String letterGrade;
private double total = 0.0;
private int count = 0;
private double GPA;
private int check = 0;
public Candidate(){
firstName = "";
lastName = "";
GPA = 0;
}
public Candidate(String fName, String lName, double average){
fName = firstName;
lName = lastName;
GPA = average;
for( count = 0 ; count < 6 ; count++)
{
if(letterGrade == "A" || letterGrade == "a"){
total += 4.0;
count++;
}
else if(letterGrade == "B" || letterGrade == "b"){
total += 3.0;
count++;
}
else if(letterGrade == "C" || letterGrade == "c"){
total += 2.0;
count++;
}
else if(letterGrade == "D" || letterGrade == "d"){
total += 1.0;
count++;
}
else if(letterGrade == "E" || letterGrade == "e" &&
(letterGrade == "F" || letterGrade == "f")){
total += 0.0;
count++;
}
if (letterGrade == "D" || letterGrade == "F" || letterGrade == "d" || letterGrade == "f")
check = 1;
}
GPA = total / 6;
if(check == 1)
System.out.println("Ineligible");
else
{
if(GPA >= 3.5){
System.out.println("Scholarship");
}
else if((GPA >= 3.0 && GPA < 3.5)){
System.out.println("Honor");
}
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLetterGrade() {
return letterGrade;
}
public void setLetterGrade(String letterGrade) {
this.letterGrade = letterGrade;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
this.total = total;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public double getGPA() {
return GPA;
}
public void setGPA(double gPA) {
GPA = gPA;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.