java基础编程练习之谁拿了最多奖学金
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
System.out.println("请输入学生人数");
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
Student[] students = new Student[num];
Scanner scanner1 = new Scanner(System.in);
int max = 0;
int index = 0;
int sum = 0;
for (int i = 0; i < students.length; i++)
{
String info = scanner1.nextLine();//YaoLin 87 82 Y N 0
String[] arrs = info.split(" ");
students[i] = new Student();
students[i].setName(arrs[0]);
students[i].setAvgScore(Integer.parseInt(arrs[1]));
students[i].setClassScore(Integer.parseInt(arrs[2]));
students[i].setLeader(arrs[3].equals("Y"));
students[i].setWest(arrs[4].equals("Y"));
students[i].setPapernum(Integer.parseInt(arrs[5]));
students[i].calculateMoney();
sum += students[i].getValue();
if(max < students[i].getValue())
{
max = students[i].getValue();
index = i;
}
}
System.out.println(students[index].getName());
System.out.println(students[index].getValue());
System.out.println(sum);
}
}
public class Student {
private String name;
private int avgScore;
private int classScore;
private boolean isLeader;
private boolean isWest;
private int papernum;
private int value;
public void calculateMoney()
{
if(avgScore > 80 && papernum >= 1)
{
value += 8000;
}
if(avgScore > 85 && classScore > 80)
{
value += 4000;
}
if(avgScore > 90)
{
value += 2000;
}
if(avgScore > 85 && isWest)
{
value += 1000;
}
if(isLeader && classScore > 80)
{
value += 850;
}
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAvgScore() {
return avgScore;
}
public void setAvgScore(int avgScore) {
this.avgScore = avgScore;
}
public int getClassScore() {
return classScore;
}
public void setClassScore(int classScore) {
this.classScore = classScore;
}
public boolean isLeader() {
return isLeader;
}
public void setLeader(boolean leader) {
isLeader = leader;
}
public boolean isWest() {
return isWest;
}
public void setWest(boolean west) {
isWest = west;
}
public int getPapernum() {
return papernum;
}
public void setPapernum(int papernum) {
this.papernum = papernum;
}
}