java 基础编程题 在线等 急!!!
发布网友
发布时间:2022-04-30 21:21
我来回答
共5个回答
热心网友
时间:2023-10-13 21:51
public class Student {
// 学号(ID) 姓名(name) 性别(sex) 年龄(age)
private int id = 0;
private String name = null;
private String sex = null;
private int age = 0;
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Student() {
}
public Student(int id, String name, String sex, int age) {
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
}
public void display() {
System.out.print("id = [" + id + "],");
System.out.print("name = [" + name + "],");
System.out.print("sex = [" + sex + "],");
System.out.print("age = [" + age + "]");
System.out.println();
}
}
public class TestStudent {
public static void main(String[] args) {
Student stu1 = new Student();
stu1.setId(1);
stu1.setName("name1");
stu1.setSex("m");
stu1.setAge(20);
Student stu2 = new Student(2, "name2", "g", 18);
stu1.display();
stu2.display();
}
}
热心网友
时间:2023-10-13 21:51
public class Student{
public Student(){//无参构造函数
}
public Student(int age,String name,String sex,String ID){//有参构造函数
this,ID=ID;
this.name=name;
this.age=age;
this.sex=sex;
}
private String ID;
private String name;
private String sex;
private int age;
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
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 getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void display(){
System.out.println("age==="+age+"sex===="+sex+"name===="+name+"ID===="+ID);
}
}
热心网友
时间:2023-10-13 21:52
private String name ;
private String age;
private String sex;
private int id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
热心网友
时间:2023-10-13 21:53
哥们,太简单了。这用工具2分钟就好了
热心网友
时间:2023-10-13 21:53
这个很简单的阿。
你写多少了?贴出来看看