I'm newbie in Java. So question might sound simple, but I'm stuck and can not figure out why this grade always return to '-'?
file:Student.java
{
private String studID;
private double score;
public String getStudID()
{
return studID;
}
public void setStudID(String newID)
{
studID = newID;
}
public double getScore()
{
return score;
}
public void setScore(double newScore)
{
score = newScore;
}
public char determineGrade()
{
if(score>= 100 && score <=80)
{
return 'A';
}
else if( score >=79 && score <= 70)
{
return 'B';
}
else if(score>=69 && score<= 60)
{
return 'C';
}
else if(score>=59 &&score<= 50)
{
return 'D';
}
else if(score>=49 && score<=0)
{
return 'E';
}
else
{
return '-';
}
}
public String toString()
{
return "\nStudent ID :" + studID + "\nScore : " + score + "\nYour Grade is " + determineGrade(score);
}
}```
file : Client.java
import java.util.Scanner;
public class Client {
public static void main(String[] args)
{
Scanner myObj = new Scanner(System.in);
Student ob1 = new Student();
System.out.print("Enter Your Student ID : ");
ob1.setStudID(myObj.next());
System.out.print("Enter Your Score : ");
ob1.setScore(myObj.nextDouble());
System.out.println(ob1.toString());
}
}```
output
Student ID : AD11111
Score : 90
Your Grade is -
Why am I getting Output '-' for grade even though i set the mark between 0-100.How should i use mutator when i use if.....else but when i use accessors method it working well
Aucun commentaire:
Enregistrer un commentaire