public class Student {
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "StudentInfo \n[No=" + sNo + ", Name=" + sName + ", Sex=" + sSex
+ ", Age=" + sAge + ", Java=" + sJava + "]";
}
/**
* @param sJava
* the sJava to set
*/
public void setsJava(int sJava) {
this.sJava = sJava;
}
/**
* @param sNo
* @param sName
* @param sSex
* @param sAge
* @param sJava
*/
public Student(String sNo, String sName, String sSex, int sAge, int sJava) {
super();
this.sNo = sNo;
this.sName = sName;
this.sSex = sSex;
this.sAge = sAge;
this.sJava = sJava;
}
/**
* @return the sNo
*/
public String getsNo() {
return sNo;
}
/**
* @return the sName
*/
public String getsName() {
return sName;
}
/**
* @return the sSex
*/
public String getsSex() {
return sSex;
}
/**
* @return the sAge
*/
public int getsAge() {
return sAge;
}
/**
* @return the sJava
*/
public int getsJava() {
return sJava;
}
private String sNo;
private String sName;
private String sSex;
private int sAge;
private int sJava;
}
public class TestStudent {
public static void getAverage(float java[]) {
int n = 0;
float sum = 0;
while (n < java.length) {
sum += java[n];
n++;
}
System.out.println("Average = " + sum / java.length);
}
public static void getMaxMin(float java[]) {
float max = java[0], min = java[0];
for (int n = 0; n < java.length; n++) {
if (java[n] > max) {
max = java[n];
}
if (java[n] < min) {
min = java[n];
}
}
System.out.println("Max = " + max + ";Min = " + min);
}
public static void printInfo(String s[]) {
for (String a : s) {
System.out.println(a);
}
};
public static void main(String[] args) {
Student s1 = new Student("s1", "Zhao", "male", 16, 11);
Student s2 = new Student("s2", "Qian", "female", 16, 10);
Student s3 = new Student("s3", "Sun", "male", 16, 30);
Student s4 = new Student("s4", "Li", "female", 16, 40);
Student s5 = new Student("s5", "Zhou", "male", 16, 50);
String[] sInfo = { s1.toString(), s2.toString(), s3.toString(),
s4.toString(), s5.toString() };
float[] iJava = { s1.getsJava(), s2.getsJava(), s3.getsJava(),
s4.getsJava(), s5.getsJava() };
printInfo(sInfo);
getAverage(iJava);
getMaxMin(iJava);
}
}
提供代码供参考:
class student{
String sNO,sName,sSex;
int sAge;
double sJava;
public student(String a,String b,String c,int d ,double e){
sNO=a;
sName=b;
sSex=c;
sAge=d;
sJava=e;}
String getNo(){
return sNO;}
String getName(){
return sName;}
String getSex(){
return sSex;}
int getAge(){
return sAge;}
double getJava(){
return sJava;}
void show(){
System.out.println("姓名:"+getName());
System.out.println("学号:"+getNo());
System.out.println("性别:"+getSex());
System.out.println("年龄:"+getAge());
System.out.println("Java成绩:"+getJava());}
}
public class TestStudent{
public static void main(String[] args){
double avrage,K1,K2,K3,K4,K5;
student A1=new student("13190310","张一","男",18,80);
student A2=new student("13190311","王二","女",19,83);
student A3=new student("13190312","李三","男",19,82);
student A4=new student("13190313","赵四","女",20,88);
student A5=new student("13190314","蒋五","女",20,90);
A1.show();
System.out.println();
A2.show();
System.out.println();
A3.show();
System.out.println();
A4.show();
System.out.println();
A5.show();
System.out.println();
K1=A1.getJava();
K2=A2.getJava();
K3=A3.getJava();
K4=A4.getJava();
K5=A5.getJava();
avrage=(K1+K2+K4+K3+K5)/5;
System.out.println("Java平均成绩:"+avrage);
double a[]={K1,K2,K3,K4,K5};
double max=0,min=0,ck;
for(int i=0;i<4;i++){
max=K1;
if(max ck=max;
max=a[i+1];
a[i+1]=ck;} }
System.out.println("Java的最高分为:"+max);
for(int i=0;i<4;i++){
max=K1;
if(min>a[i+1]){
ck=min;
min=a[i+1];
a[i+1]=ck;}
}
System.out.println("Java的最低分为:"+max);
}
}
public class student
{
private string name;
private string sex;
private string old;
private string grade;
private string class
}
按照这个句式分别为学生(student)这个类加入姓名(name)性别(sex)年龄(old)年级(grade)班级(class)五个基本属性
这就是一个基本的java类
public class Student {
private String studentNumber;
private String name;
private String sex;
private int age;
// getters and setters
...
}
不要光看外表