In: Computer Science
Implement a class Student, including the following attributes and methods:
Example:
Student student = new Student("Zack");
student.score = 10;
student.getLevel(); // should be 'D'.
student.score = 60;
student.getLevel(); // should be 'C'.
Java Language
Explanation:
here is the code which has the class Student with the attributes mentioned name and score.
Now, getLevel returns the Level based on the score entered.
Code:
import java.util.*;
class Student
{
public String name;
public int score;
Student(String name)
{
this.name = name;
this.score = score;
}
char getLevel()
{
if(score>=90)
{
return 'A';
}
else if(score>=80)
{
return 'B';
}
else if(score>=60)
{
return 'C';
}
else
{
return 'D';
}
}
}
public class Main {
public static void main(String[] args) throws Exception {
Student student = new Student("Zack");
student.score = 10;
System.out.println(student.getLevel());
student.score = 60;
System.out.println(student.getLevel());
}
}
Output;
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!