Что не так с этим java-кодом? Подсказка : что-то связанное с наследованием
Whats wrong with this java code? HINT: related to inheritanc
Что я уже пробовал:
<pre>import java.util.*; import java.lang.String; 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; /* * 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[] testScores) { this.firstName = firstName; this.lastName = lastName; this.idNumber = id; this.testScores = testScores; } /* * Method Name: calculate * @return A character denoting the grade. */ // Write your method here public char calculate() { int totalMarks = 0; char grade; for(int i = 0; i<testScores.length;i++) { totalMarks = totalMarks + testScores[i]; } if(totalMarks >=90 ){ grade = 'O'; }else if(totalMarks >=80 && totalMarks < 90) { grade = 'E'; }else if(totalMarks >=70 && totalMarks < 80) { grade = 'A'; }else if(totalMarks >=55 && totalMarks < 70) { grade = 'p'; }else if(totalMarks >=40 && totalMarks < 55) { grade = 'D'; }else { grade = 'T'; } return grade; } } 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()); } }
phil.o
Мы не делаем вашу домашнюю работу.