-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
107 lines (94 loc) · 2.58 KB
/
Inheritance.java
File metadata and controls
107 lines (94 loc) · 2.58 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package hackerrank;
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{
private int[] testScores; int a ;
/*
* Class Constructor
*
* @param firstName - A string denoting the Person's first name.
* @param lastName - A string denoting the Person's last name.
* @param id - An integer denoting the Person's ID number.
* @param scores - An array of integers denoting the Person's test scores.
*/
// Write your constructor here
/* Student(String firstName,String lastName,int ID,int[] scores);
{
super(Person);
this.id = ID;
this.scores = scores;
} */
public Student(String firstName, String lastName, int id, int[] testScores){
super(firstName,lastName,id);
this.testScores=testScores;
this.firstName=firstName;
this.lastName=lastName;
this.idNumber=id;
}
/*
* Method Name: calculate
* @return A character denoting the grade.
*/
// Write your method here
public char calculate(){
for(int i=0;i<testScores.length;i++){
a=a+testScores[i+3];
}
a=a/testScores.length;
if(90<=a&&a<=100){
return 'O';
}else if(80<=a&&a<90){
return 'E';
}else if(70<=a&&a<80){
return 'A';
}else if(55<=a&&a<70){
return 'P';
}else if(40<=a&&a<55){
return 'D';
}else if(0<=a&&a<40){
return 'T';
}
else
return Character.MIN_VALUE;
}
}
/* int avg=0;
for(int i=0;i<testScores.length;i++)
avg+=testScores[i];
avg=avg/testScores.length;
return(avg> 89 ?'O': avg>79 ? 'E' : avg > 69 ? 'A' : avg > 54 ? 'P' :avg > 39 ? 'D' : 'T' );
}
}*/
public class Inheritance {
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() );
}
}