This repository has been archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay 12: Inheritance.java
73 lines (65 loc) · 1.56 KB
/
Day 12: Inheritance.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.util.*;
class Person {
protected String firstName;
protected String lastName;
protected int idNumber;
// Constructor
Person(String firstName, String lastName, int identification){
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = identification;
}
// Print person data
public void printPerson(){
System.out.println(
"Name: " + lastName + ", " + firstName
+ "\nID: " + idNumber);
}
}
class Student extends Person
{
int[] testScores;
Student(String fn,String ln,int i,int n[])
{
super(fn,ln,i);
this.testScores=n;
}
public String calculate()
{
int s=0;
for(int i=0;i<testScores.length;i++)
{
s=s+testScores[i];
}
double a=(double)s/testScores.length;
if(a<=100&&a>=90)
return "O";
else if(a<90&&a>=80)
return "E";
else if(a<80&&a>=70)
return "A";
else if(a<70&&a>=55)
return "P";
else if(a<55&&a>=40)
return "D";
else
return "T";
}
}
class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String firstName = scan.next();
String lastName = scan.next();
int id = scan.nextInt();
int numScores = scan.nextInt();
int[] testScores = new int[numScores];
for(int i = 0; i < numScores; i++){
testScores[i] = scan.nextInt();
}
scan.close();
Student s = new Student(firstName, lastName, id, testScores);
s.printPerson();
System.out.println("Grade: " + s.calculate());
}
}