Repository navigation
Expand file tree
/
Copy pathday12.java
More file actions
58 lines (51 loc) · 1.44 KB
/
Copy pathday12.java
File metadata and controls
58 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
class Student
{
protected String firstName;
protected String lastName;
int phone;
Student(String fname, String lname, int p) {
firstName = fname;
lastName = lname;
phone = p;
}
public void display() { // display the details of the student
System.out.println("First Name: " + firstName + "\nLast Name: " + lastName);
System.out.println("Phone: " + phone);
}
}
class Grade extends Student
{
private int score;
// Write your code here
Grade(String fname, String lname, int ph, int sc) {
super(fname, lname, ph);
this.score = sc;
}
public String calculate() {
if (this.score < 40)
return "D";
else if (this.score >= 40 && this.score < 60)
return "B";
else if (this.score >= 60 && this.score < 75)
return "A";
else if (this.score >= 75 && this.score < 90)
return "E";
else
return "O";
}
}
public class day12
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String firstName = sc.nextLine();
String lastName = sc.nextLine();
int phone = sc.nextInt();
int score = sc.nextInt();
Student stu = new Grade(firstName, lastName, phone, score);
stu.display();
Grade g = (Grade)stu;
System.out.println("Grade: " + g.calculate());
}
}