import java.util.Scanner;
class DataInput {
String name[];
int korean[], math[], english[];
int sum[];
double average[];
static int rank[];
int students;
public void save() {
Scanner sc = new Scanner(System.in);
System.out.println("Please input number of students");
students = sc.nextInt();
name = new String[students];
korean = new int[students];
math = new int[students];
english = new int[students];
sum = new int[students];
average = new double[students];
rank = new int[students];
for (int i = 0; i < students; i++) {
System.out.println("Name?");
name[i] = sc.next();
System.out.println("Korean Score :");
korean[i] = sc.nextInt();
System.out.println("Math Score :");
math[i] = sc.nextInt();
System.out.println("English Score :");
english[i] = sc.nextInt();
sum[i] = korean[i] + math[i] + english[i];
average[i] = sum[i] / 3;
}
}
}
class DataOutput extends DataInput {
public void ranker() {
for (int i = 0; i < students; i++){
rank[i] = 1;
}
for (int i = 0; i < students; i++) {
for (int j = i + 1; j < students; j++) {
if (sum[i] < sum[j]) {
rank[i] += 1;
} else if(sum[i]>sum[j]){
rank[j] += 1;
}
}
}
}
}
public class Score {
public static void main(String[] args) {
DataInput data = new DataInput();
DataOutput out = new DataOutput();
data.save();
out.ranker();
System.out.println();
System.out.println("Name\t\tKorean Math English\tSum Average Rank");
System.out
.println("-------------------------------------------------------");
for (int i = 0; i < data.students; i++) {
System.out
.println(data.name[i] + "\t\t" + data.korean[i] + " "
+ data.math[i] + " " + data.english[i] + "\t"
+ data.sum[i] + " " + data.average[i] + " "
+ out.rank[i]);
}
}
}
So, this is a little program I built. I think the logic is quite right, but when I run the program and type in all the variables, the ranks of students are all 0.
I can't figure out what's the problem. It would be really thankful if someone helps me.