用JAVA语言定义一个类,输出学生班级,姓名信息

如题所述

import java.util.ArrayList;
import java.util.List;

public class Student {

public static void main(String[] args) {
List<Students> studentCount = new ArrayList<Students>();//定义一个对象数组存放所有学生的信息
Students firstStudent = new Students();
firstStudent.setGrand("一班");//因为对象里的成员变量是私有的,只能通过SET方法来复制
firstStudent.setName("张三");
studentCount.add(firstStudent);
Students secondStudent = new Students();
secondStudent.setGrand("三班");
secondStudent.setName("王五");
studentCount.add(secondStudent);
for (int index = 0; index < studentCount.size(); index++) {//遍历并通过GET方法取值并输出
System.out.println(studentCount.get(index).getGrand() + " "
+ studentCount.get(index).getName());
}

}

}
/**
* 定义这样的一个Students类存放学生的相关信息
* @author Administrator
*
*/
class Students {
private String name;
private String grand;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getGrand() {
return grand;
}

public void setGrand(String grand) {
this.grand = grand;
}

}
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-19
public class ClassInfo{ private String grade="3年2班"; private String name="java爱好者"; public ClassInfo() { System.out.print(this.grade+"\n"); System.out.print(this.name); }}
第2个回答  2013-08-19
public class ClassInfo(){ public static void main(String [] args){ int classroom=3; String name="张三"; System.out.println(name+"是"+classroom+“班的”); }}

用java定义学生类(学号、姓名、成绩)。用列表list存放班级学生信息...
public String toString() { return "学号:" + no + ",姓名:" + name + ",成绩:" + chengji;} } 结果 排序前 学号:000,姓名:a,成绩:100.0 学号:001,姓名:b,成绩:99.0 学号:002,姓名:c,成绩:98.0 排序后 学号:002,姓名:c,成绩:98.0 学号:001,姓名:b,成绩:99.0 学号:000,...

Java定义一个Student类,包括学号、姓名、性别、班级、出生日期
public class Student { private String sno; \/\/学号 private String name; \/\/姓名 private String sex; \/\/性别 private String calss; \/\/班级 private String major; \/\/专业 public String getSno() { return sno;} public void setSno(String sno) { this.sno = sno;} public String getNam...

怎样用JAVA设计学生类Student,包含“学号、班级、姓名、年龄、成员...
\\r\\npublic class Students {\\r\\n\\tprivate String ID; \/\/学号\\r\\n private String classId; \/\/班级\\r\\n private String name; \/\/姓名\\r\\n\\tprivate int age; \/\/年龄\\r\\n public Students(String ID,String classId,String name,int age){\/\/构造函数\\r\\n th...

Java程序设计,定义一个表示学生的类Student
public class Student { \/\/定义一个学生类 private int StuNum; \/\/学号 private int Class; \/\/班级 private char Gender; \/\/性别 private int Age; \/\/年龄 public Student(int StuNum, int Class, char Gender, int Age){\/\/构造函数 this.stuNum = StuNum;this.class = Cla...

用JAVA写个学生类
System.out.println("显示学生信息:");System.out.println("姓名:"+this.getName());System.out.println("学校:"+this.getSchool());System.out.println("专业:"+this.zhuanye);} public String getXibu() { return xibu;} public void setXibu(String xibu) { this.xibu = xibu;} public...

JAVA定义Student类:代表学生。其中有成员变量:姓名、年龄, 班级, 语文...
import java.math.BigDecimal;public class Student { private String name;private Integer age;private String clazz;private double chineseScore;private double mathScore;private double totalScore;public Student() { super();} public Student(String name, Integer age, String clazz, double chinese...

java语言建立一个班级学生姓名的字符串数组并进行排序
import java.text.Collator;import java.util.Arrays;import java.util.Comparator;public class NameSortDemo {public static void main(String[] args) {String[] names = { "孙小美", "阿土伯", "小明", "钱夫人", "小红", "小菜" };System.out.println("排序前:");for (String name :...

如何用java编辑Student类用于存储单个学生的学号和姓名?
{ public static void main(String[] args){ Student s_me = new Student(); \/\/用Student的Student()方法初始化一个Student对象 Student s_other = new Student(66,"李四"); \/\/用Student的Student(int id,String name)方法初始化一个Student对象 System.out.println("---");System.out.printl...

JAVA创建学生类Student,学生姓名变量stuname,学生学号变量stunumber...
"班级学生,我叫='" + stuname + '\\'' + ", 学号为:'" + stunumber + '\\'' + '}';} public String getStuname() { return stuname;} public void setStuname(String stuname) { this.stuname = stuname;} public String getStunumber() { return stunumber;} public void set...

用java编写一个简单例子,题目如下
private String name;private String id;private String clazz;private int age;private String address;\/ sayHello方法 \/ public void sayHello() { System.out.println("学号为" + this.id + "的同学的具体信息如下:");System.out.println("姓名:" + this.name);System.out.println("班级:" ...

相似回答