1 개요[ | ]
- Day 12: Inheritance
2 Java[ | ]
HR30 Day 12: Inheritance/Java 문서를 참고하십시오.
Java
Copy
class Student extends Person {
private int[] testScores;
Student(String firstName, String lastName, int id, int[] scores) {
super(firstName, lastName, id);
this.testScores = scores;
}
char calculate() {
double avg = Arrays.stream(this.testScores).average().getAsDouble();
if( avg >= 90 ) return 'O';
if( avg >= 80 ) return 'E';
if( avg >= 70 ) return 'A';
if( avg >= 55 ) return 'P';
if( avg >= 40 ) return 'D';
return 'T';
}
}
3 PHP[ | ]
HR30 Day 12: Inheritance/PHP 문서를 참고하십시오.
PHP
Copy
class Student extends person {
private $testScores;
public function __construct($first_name, $last_name, $identification, $scores) {
parent::__construct($first_name, $last_name, $identification);
$this->testScores = $scores;
}
function calculate() {
$average = array_sum($this->testScores) / count($this->testScores);
if( $average >= 90 ) return 'O';
if( $average >= 80 ) return 'E';
if( $average >= 70 ) return 'A';
if( $average >= 55 ) return 'P';
if( $average >= 40 ) return 'D';
return 'T';
}
}
4 Python[ | ]
HR30 Day 12: Inheritance/Python 문서를 참고하십시오.
Python
Copy
import builtins
def print(*args,**kwargs):
if "sep" not in kwargs and args[0] =="Grade: ":
builtins.print(*args,**kwargs,sep="")
else:
builtins.print(*args,**kwargs)
class Student(Person):
# Class Constructor
#
# Parameters:
# firstName - A string denoting the Person's first name.
# lastName - A string denoting the Person's last name.
# id - An integer denoting the Person's ID number.
# scores - An array of integers denoting the Person's test scores.
#
# Write your constructor here
def __init__(self, firstName, lastName, idNum, scores):
super().__init__(firstName, lastName, idNum)
self.scores = scores
# Function Name: calculate
# Return: A character denoting the grade.
#
# Write your function here
def calculate(self):
avg = sum(self.scores) / len(self.scores)
if avg >= 90: return "O"
if avg >= 80: return 'E'
if avg >= 70: return 'A'
if avg >= 55: return 'P'
if avg >= 40: return 'D'
return 'T'
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.