解题思路:先把学生的属性,封装在学生类中,然后再在测试类中简单编写题目要求
注意事项:
参考代码: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分
2 人评分
字符串对比 (C语言代码)浏览:1471 |
C语言考试练习题_排列 (C语言代码)浏览:767 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:793 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:660 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:1324 |
模拟计算器 (C++代码)浏览:885 |
1118(求助_已解决)浏览:351 |
C二级辅导-公约公倍 (C语言代码)浏览:537 |
剪刀石头布 (C语言代码)浏览:1519 |