解题思路:先把学生的属性,封装在学生类中,然后再在测试类中简单编写题目要求
注意事项:
参考代码:import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
Student[] s = new Student[n];
//录入信息:
for (int i = 0; i < s.length; i++) {
String name1 = in.next();
int qimo1 = in.nextInt();
int banji1 = in.nextInt();
char is_banganbu1 = in.next().charAt(0);
char is_xibu1 = in.next().charAt(0);
int num_state1 = in.nextInt();
s[i] = new Student(name1, qimo1, banji1, is_banganbu1, is_xibu1, num_state1);
}
int max = 0;
for (int i = 0; i < s.length; i++) {
max = Math.max(max, s[i].getScholar());
}
for (int i = 0; i < s.length; i++) {
if (s[i].getScholar() == max) {
System.out.println(s[i].getName());
break;
}
}
System.out.println(max);
int sumScho = 0;
for (int i = 0; i < s.length; i++) {
sumScho+=s[i].getScholar();
}
System.out.println(sumScho);
}
}
class Student{
private String name;
private int qimo;
private int banji;
private char is_banganbu;
private char is_xibu;
private int num_state;
Student(){
}
Student(String name, int qimo, int banji, char is_banganbu, char is_xibu, int num_state){
this.name = name;
this.qimo = qimo;
this.banji = banji;
this.is_banganbu = is_banganbu;
this.is_xibu = is_xibu;
this.num_state = num_state;
}
//name:
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
//banji
public int getBanji() {
return banji;
}
public void setBanji(int banji) {
this.banji = banji;
}
//num_state
public int getNum_state() {
return num_state;
}
public void setNum_state(int num_state) {
this.num_state = num_state;
}
public int getQimo() {
return qimo;
}
public void setQimo(int qimo) {
this.qimo = qimo;
}
public char getIs_banganbu() {
return is_banganbu;
}
public void setIs_banganbu(char is_banganbu) {
this.is_banganbu = is_banganbu;
}
// 西部学生
public char getIs_xibu() {
return is_xibu;
}
public void setIs_xibu(char is_xibu) {
this.is_xibu = is_xibu;
}
public boolean is_Xibu(char s){
if(s=='Y'){
return true;
}
return false;
}
public boolean is_Banganbu(char s){
if(s=='Y'){
return true;
}
return false;
}
//重载
@Override
public String toString(){
return this.name + "\n" + this.getScholar() + "\n" + this.getScholar();
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
public int getScholar(){
String name = this.name;
int qimo = this.qimo;
int banji = this.banji;
char is_banganbu = this.is_banganbu;
char is_xibu = this.is_xibu;
int num_state = this.num_state;
//奖学金
int sYuanshi = 0;
int sWusi = 0;
int sChengji = 0;
int sXibu = 0;
int sBanji = 0;
if(qimo>80 & num_state>=1){
sYuanshi = 8000;
}
if(qimo>85 & banji > 80){
sWusi = 4000;
}
if(qimo>90){
sChengji = 2000;
}
if(qimo > 85 & is_xibu=='Y'){
sXibu = 1000;
}
if(banji > 80 & is_banganbu=='Y'){
sBanji = 850;
}
int sum = sYuanshi + sXibu + sWusi + sChengji + sBanji;
return sum;
}
}
0.0分
1 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复