用java定义一个学生类,要处理的信息有学号、姓名、年龄、专业。
class Student{private int STU_NUM;private String STU_NAME;private int STU_AGE;public Student(int NUM,String NAME){this.STU_NAME=NAME;this.STU_NUM=NUM;}public Student(int NUM,String NAME,int AGE){this.STU_NAME=NAME;this.STU_NUM=NUM;this.STU_AGE=AGE;}}
完整代码如下,复制到eclipse中运行:
public class StuExam {private String snum;// 学号private String cnum;// 班号private String name;// 姓名private char sex;// 性别private int age;// 年龄// get/set方法用来获取/设置学生实例对象的信息public String getSnum() {return snum;}public void setSnum(String snum) {this.snum = snum;}public String getCnum() {return cnum;}public void setCnum(String cnum) {this.cnum = cnum;}public String getName() {return name;}public void setName(String name) {this.name = name;}public char getSex() {return sex;}public void setSex(char sex) {this.sex = sex;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public static void main(String[] args) {StuExam stu = new StuExam();// 对学生类实例化// 对学生信息赋值stu.setSnum("0504112");stu.setCnum("02");stu.setSex('女');stu.setName("杨子");stu.setAge(20);// 输出学生信息System.out.println("学号:" + stu.getSnum() + "
班号:" + stu.getCnum()+ "
性别:" + stu.getSex() + "
姓名:" + stu.getName() + "
年龄:"+ stu.getAge());}}
public class Student {
private int sno; // 学号
private String sname; // 姓名
private int sage; // 年龄
private String profession; // 专业
public Student() {
}
public Student(int sno, String sname, int sage, String profession) {
super();
this.sno = sno;
this.sname = sname;
this.sage = sage;
this.profession = profession;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public String getProfession() {
return profession;
}
public void setProfession(String profession) {
this.profession = profession;
}
@Override
public String toString() {
return "Student [sno=" + sno + ", sname=" + sname + ", sage=" + sage
+ ", profession=" + profession + "]";
}
}
public class Student{
private int stu_no;
private String name;
private int age;
private String profession;
设置下get/set方法
话说你连定义个类都不会 要来有啥用呢
}
JAVA编写一个学生类的程序
在编程中,构建一个学生类是常见的实践任务。首先,定义一个名为Student的实体类,其包含三个属性:学生的名字(name)、年龄(age)和分数(score)。以下是具体实现方式:class Student { public String name;public int age;public double score;public Student(String name, int age, double score) { t...
用Java编写一段测试程序,生成student类的两个对象,并输出每个对象基本信 ...
在Java编程中,创建一个名为Student的类是基础练习之一。该类包含学生的基本信息,如学号、姓名、性别和年龄。下面展示了一个简单的Student类的定义及其使用示例。首先定义Student类:public class Student { private String sNo;private String sName;private String sSex;private int sAge;public Student(...
编写一个java程序,封装一个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 定义学生类,并在main方法中创建学生类对象,并调用学生类定义的方...
public class Student { private String id; private String name; private String profession; private String major; public Student(){ } public Student(String id,String name,String major){ this.id = id; this.name = name; this.major = major; } pu...
java语言编写, 定义一个“学生”类,然后创建10个学生对象,计算他们的平 ...
\/\/ 假设10个学生的成绩为如下所示 List<Student> list = Arrays.asList(new Student(56), new Student(66),new Student(76), new Student(86), new Student(96), new Student(44), new Student(77), new Student(77), new Student(87),new Student(88));Integer[] grades = new ...
编写一个表示学生的Java类Student。
package a;public class 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;} ...
用JAVA编写一个学生类Student的程序
package langs;public class Student { private String sno; private String name; private char sex; private int age; public Student() { \/\/ TODO Auto-generated constructor stub } public Student(String sno, String name, char sex, int age) { super(); this.sno = sno; this....
java编程定义一个学生类Student,成员变量有学号,姓名,性别,身高,体重...
{vs.add(new Student(i,"张三"+i,"男",+1.72,65.03));}java.util.Iterator<Student> it = vs.iterator();while(it.hasNext()){System.out.println("---");Student st = it.next();System.out.println("序号:" + st.num);System....
用java创建一个学生类,包括学号,姓名,成绩,然后构造方法,初始化,输出...
public class Student {private String name;private String number;private int score;public Student() {}public Student(String name, String number, int score) {super();this.name = name;this.number = number;this.score = score;}public String getName() {return name;}public void set...
java定义一个学生类,属性:姓名,性别,年龄体重,银行账户余额,给每个属 ...
public class Student { private String name; private String Gender; private int age; private double weight; private double balance; public Student() { } public Student(String name, String gender, int age, double weight, double balance) { this.name = name...