用JAVA定义一个学生类Student来表示学生信息,学生类中包含成员有学号(id)、姓名(name)、年龄和成绩
//测试类!public class StudentTest {public static void main(String[] args) {//测试1:Studen s=new Studen();//创建对象!System.out.println(s);//测试打印对象属性!System.out.println("
----------------分割线------------------
");//测试2:Studen s1=new Studen("张三","2017-12-07","1900/10/10","机电",100);s1.study();System.out.println(s1);}}//学生类!class Studen{private String name;//姓:private String number;//号:private String day;//生;private String spe;//专!private int age;//年龄!Studen(){//空参构造!this("无名氏","2017-12-13","1999/10/27","本课",18);}//形参构造!public Studen(String name, String number, String day, String spe, int age) {super();this.name = name;this.number = number;this.day = day;this.spe = spe;this.age = age;}//修改年龄!public void setAge(int age) {this.age = age;}//修改出生!public void setDay(String day) {this.day = day;}//修改专业!public void setSpe(String spe) {this.spe = spe;}//修改姓名!public void setName(String name) {this.name = name;}//修改学号!public void setNumber(String number) {this.number = number;}//获取学号!public String getNumber() {return number;}//获取出生!public String getDay() {return day;}//获取专业!public String getSpe() {return spe;}//获取年龄!public int getAge() {return age;}//获取姓名!public String getName() {return name;}//学习方法!public void study() {System.out.println(name+",在学习:"+spe);}public String toString() {return "姓名:"+name+";年龄:"+age+";专业:"+spe+";学号:"+number;}}
import java.util.LinkedList;
import java.util.List;
public class Student {
private int id; // 学号
private String name; // 姓名
private int age; // 年龄
private int sex; // 性别 0,女;1,男
List students = new LinkedList();
/**
* 构造方法
*
* @param id
* @param name
* @param age
* @param sex
*/
public Student(int id, String name, int age, int sex) {
this.id = id;
this.name = name;
this.age = age;
this.sex = sex;
}
/**
* 增加学生
*
* @param s
*/
public void add(Student s) {
if (students != null)
students.add(s);
}
/**
* 根据学号删除学生
*
* @param id
*/
public void deleteById(int id) {
if (students != null) {
for (int i = 0; i < students.size(); i++) {
Student s = students.get(i);
if (s.getId() == id)
students.remove(s);
}
}
}
/**
* 所有学生年龄增加一岁
*/
public void addAgeAll() {
if (students != null) {
for (int i = 0; i < students.size(); i++) {
students.get(i).setAge(students.get(i).getAge() + 1);
}
}
}
/**
* 按顺序显示所有学生信息
*/
public void printAllStudent() {
if (students != null) {
for (int i = 0; i < students.size(); i++) {
Student s = students.get(i);
System.out.println(s.getId() + "" + s.getName() + ""
+ s.getSex() + "" + s.getAge());
}
}
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
}
如下所示:
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 getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getYu() {
return yu;
}
public void setYu(int yu) {
this.yu = yu;
}
public int getShu() {
return shu;
}
public void setShu(int shu) {
this.shu = shu;
}
public int getWai() {
return wai;
}
public void setWai(int wai) {
this.wai = wai;
}
public class $ {
public static void main(String[] args) {
Student s0 = new Student();
System.out.println(s0);
Studentmen s1 = new Studentmen();
System.out.println(s1);
}
}
class Student {
private long id;
private String name;
private int age;
private double grade;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
public String toString() {
return "我是学生";
}
}
class Studentmen extends Student {
private String duty;
public String getDuty() {
return duty;
}
public void setDuty(String duty) {
this.duty = duty;
}
public String toString() {
return "我是班干部";
}
}
java基础知识
3、已知一个int数组, 编程从数组中获取最大数。4、编写程序获取已知文件的扩展名. 注意: abc.txt的扩展名是txt, abc.java.txt的扩展名也是txt5、定义一个学生类, 需要有姓名, 年龄, 考试成绩三个成员属性. 属性(成员变量)需要私有并提供get, set方法, 可以通过构造函数进行初始化。6、使用第5题定义的学生...
...语句与 FOREIGN KEY 约束"FK__Tb_Studen__Stude__1920BF5C"冲_百度...
StudentNo int references Tb_Student(StudentNo),的意思是Tb_Student_Course表StudentNo的值必须是Tb_Student表StudentNo字段已有的值、但是你Tb_Student表的主键StudentNo的值是自增的、所以按你的插入语句Tb_Student_Course表StudentNo的值只能取1,2,3,4 不要把具有实际意义的字段设置为自增主键、因...