mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 20:42:00 -05:00
style:fmt
This commit is contained in:
@@ -1,40 +1,46 @@
|
||||
package com.study.demo2;
|
||||
|
||||
public class Student {
|
||||
private String id;
|
||||
private String name;
|
||||
private int[] score = new int[10];
|
||||
private String id;
|
||||
private String name;
|
||||
private int[] score = new int[10];
|
||||
|
||||
public Student(String id, String name, int[] scores) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
if (scores.length == 10) {
|
||||
this.score = scores;
|
||||
}
|
||||
public Student(String id, String name, int[] scores) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
if (scores.length == 10) {
|
||||
this.score = scores;
|
||||
}
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
int sum = 0;
|
||||
for (int s : score) {
|
||||
sum += s;
|
||||
}
|
||||
return (double) Math.round((sum / 10.0) * 100) / 100;
|
||||
public double getAverage() {
|
||||
int sum = 0;
|
||||
for (int s : score) {
|
||||
sum += s;
|
||||
}
|
||||
return (double) Math.round((sum / 10.0) * 100) / 100;
|
||||
}
|
||||
|
||||
public int getMaxScore() {
|
||||
int max = score[0];
|
||||
for (int s : score) {
|
||||
if (s > max) max = s;
|
||||
}
|
||||
return max;
|
||||
public int getMaxScore() {
|
||||
int max = score[0];
|
||||
for (int s : score) {
|
||||
if (s > max)
|
||||
max = s;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public char getGrade() {
|
||||
double avg = getAverage();
|
||||
if (avg >= 90) return 'A';
|
||||
else if (avg >= 80) return 'B';
|
||||
else if (avg >= 70) return 'C';
|
||||
else if (avg >= 60) return 'D';
|
||||
else return 'E';
|
||||
}
|
||||
}
|
||||
public char getGrade() {
|
||||
double avg = getAverage();
|
||||
if (avg >= 90)
|
||||
return 'A';
|
||||
else if (avg >= 80)
|
||||
return 'B';
|
||||
else if (avg >= 70)
|
||||
return 'C';
|
||||
else if (avg >= 60)
|
||||
return 'D';
|
||||
else
|
||||
return 'E';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user