JAVA:定义一个表示学生信息的类student

(1) 类student的成员变量(根据实际数据的情况,自定类型):sNO表示学号,sName表示姓名,sSex表示性别,sAge表示年龄,sJava语言课程的成绩。
(2) 类student的方法成员:getNO()获得学号,getName()获得姓名,getSex()获得性别,getAge()获得年龄,getJava()获得Java课程成绩。
(3) 按照上题中学生类student的定义,创建两个该类的对象,存储并输出两个学生的信息,计算并输出这两个学生Java语言成绩的平均成绩。

1.Bean
package com.test;

public class Student {
private String sSO;//学号
private String sName;//姓名
private String sSex;//性别
private String sAge;//年龄
private String sJava;//成绩
public String getSSO() {
return sSO;
}
public void setSSO(String sso) {
sSO = sso;
}
public String getSName() {
return sName;
}
public void setSName(String name) {
sName = name;
}
public String getSSex() {
return sSex;
}
public void setSSex(String sex) {
sSex = sex;
}
public String getSAge() {
return sAge;
}
public void setSAge(String age) {
sAge = age;
}
public String getSJava() {
return sJava;
}
public void setSJava(String java) {
sJava = java;
}
}

2.测试类
package com.test;

public class textStudent {

/**
* @param args
*/
public static void main(String[] args) {
Student s1 = new Student();//学生对象一
Student s2 = new Student();//学生对象二
//学生一信息
s1.setSName("Tom");
s1.setSSO("1001002");
s1.setSAge("18");
s1.setSSex("男");
s1.setSJava("89");
//学生二信息
s2.setSName("Lucy");
s2.setSSO("1001001");
s2.setSAge("19");
s2.setSSex("女");
s2.setSJava("90");

System.out.println("两名学生的信息如下:");
System.out.println("学号\t姓名\t年龄\t性别\t成绩");
System.out.println(s1.getSSO()+"\t"+s1.getSName()+"\t"+s1.getSAge()+"\t"+s1.getSSex()+"\t"+s1.getSJava());
System.out.println(s2.getSSO()+"\t"+s2.getSName()+"\t"+s2.getSAge()+"\t"+s2.getSSex()+"\t"+s2.getSJava());
System.out.println();
int sj1 = Integer.parseInt(s1.getSJava());
int sj2 = Integer.parseInt(s2.getSJava());
double sum = (sj1+sj2)/2.0;//保留一位小数
System.out.println("平均成绩为:"+sum);
}

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-12-20
楼主问这种基础东西,是初学者,楼上那样写交给老师的话,老师一看就知道不是自己写的了。
(1)
public class Student {
String sNO;//学号
String sName;//姓名
char sSex;//性别
int sAge;//年龄
int sJava;//成绩
public String getNO() {
return sNO;
}
public String getName() {
return sName;
}
public char getSex() {
return sSex;
}
public int getSAge() {
return sAge;
}
public int getJava() {
return sJava;
}
}
(2,3)
public class Test {
public static void main(String[] args) {
Student s1 = new Student();//学生对象一
Student s2 = new Student();//学生对象二
//学生一信息
s1.sNO="430331";
s1.sName="Lucy";
s1.sSex='女';
s1.sAge=19;
s1.sJava=88;
//学生二信息
s2.sNO="430332";
s2.sName="Lily";
s2.sSex='女';
s2.sAge=19;
s2.sJava=87;

System.out.println("两名学生的信息如下:");
System.out.println("学号\t姓名\t年龄\t性别\t成绩");
System.out.println(s1.sNO+"\t"+s1.sName+"\t"+s1.sAge+"\t"+s1.sSex+"\t"+s1.sJava);
System.out.println(s2.sNO+"\t"+s2.sName+"\t"+s2.sAge+"\t"+s2.sSex+"\t"+s2.sJava);
System.out.println("两学生的平均成绩是"+(s1.sJava+s2.sJava)/2.0);
}

}

用java表示学生信息 问题:用java怎么写学生表示?
getJava():获得Java 课程成绩 (4)根据类Student的定义,创建五个该类的对象,输出每个学生的信息,计算并输出这五个学生Java语言成绩的平均值,以及计算并输出他们Java语言成绩的最大值和最小值。*\/ class student{ String sNO,sName,sSex;int sAge;double sJava;public student(String a,String ...

用JAVA定义一个学生类Student来表示学生信息,学生类中包含成员有学号...
public class Student {private int sNo; \/\/学号private String name; \/\/姓名private String sex; \/\/性别private int yu; \/\/语文private int shu; \/\/数学private int wai; \/\/外语public int getsNo() {return sNo;}public void setsNo(int sNo) {this.sNo = sNo;}public String ge...

JAVA:定义一个表示学生信息的类student
public class textStudent { \/ param args \/ public static void main(String[] args) { Student s1 = new Student();\/\/学生对象一 Student s2 = new Student();\/\/学生对象二 \/\/学生一信息 s1.setSName("Tom");s1.setSSO("1001002");s1.setSAge("18");s1.setSSex("男");s1.setS...

...个student类的对象,定义一个表示学生的类student
public class Student{ private String num; private String sex; private String name; private int age; public Student(String num,String sex,String name){ this.num=num; this.sex=sex; this.name=name; } public String getNum(){ return this.num; }...

用java定义一个Student类,包含的内容如下:
public class Student { private String s_no;\/\/学号 private String s_name;\/\/姓名 private boolean isLeader;\/\/班干部否 private String s_sex;\/\/性别 private double s_shuxue;\/\/数学 private double s_yuwen;\/\/语文 private double s_waiyu;\/\/外语 \/\/学生信息录入 public void addStudent...

如何使用java来创建一个学生类?
首先,你需要创建一个学生类来表示学生的信息,例如:public class Student { private String name;private int age;private String gender;private String grade;public Student(String name, int age, String gender, String grade) { this.name = name;this.age = age;this.gender = gender;this....

用java编程,设计一个学生类,要求包含姓名年龄、性别、java成绩、c++成 ...
public class Student{ private String name; private String sex; private int score_java; private int score_c; private int score_php; void averagescore() { int sum = 0; int average = 0; sum += score_java+score_c+score_php; average = sum\/3; ...

编写一个表示学生的Java类Student。
public static void main(String args[]){ private int stuId;private String name;\/\/其它属性省略,方法同上。public Student(){ \/\/默认构造方法 } public void setStuId(int stuId){ this.stuId=studId;} public void setName(String name){ this.name=name;} public int getStuId(){ return ...

【java】设计一个学生类Student和它的一个子类Undergraduate,要求如...
public String name;public int age;public Student(String name,int age){ this.name=name;this.age=age;} public void show(){ System.out.println("name: "+name+" age: "+age);} } class UnderGraduate extends Student{ public String degree;public UnderGraduate(String name,int age,...

JAVA创建学生类Student,学生姓名变量stuname,学生学号变量stunumber...
public StudentVo(String stuname, String stunumber, String stuclass) { this.stuname = stuname;this.stunumber = stunumber;this.stuclass = stuclass;} Override public String toString() { return "StudentVo{" + "我是'" + stuclass + '\\'' + "班级学生,我叫='" + stuname + '...

相似回答