发布网友 发布时间:2022-05-03 09:03
共3个回答
热心网友 时间:2023-10-18 01:27
package test;
public class test{
public static void main(String[] args) {
Mysdent mysdent1 = new Mysdent();
mysdent1.setName("张三");
mysdent1.setCollege("信息学院");
mysdent1.setMajor("计算机专业");
mysdent1.setClassSchool("三班");
mysdent1.setTotalScore(578);
mysdent1.get();
Mysdent mysdent2 = new Mysdent(
"李四", "建设学院", "土木工程专业", "5班", 627);
mysdent2.get();
}
}
class Mysdent {
private String name;//姓名
private String college;//学院
private String major;//专业
private String classSchool;//班级
private double totalScore;//总成绩
public void get() {
System.out.println("======================");
System.out.println("姓名:"+name);
System.out.println("学院:"+college);
System.out.println("专业:"+major);
System.out.println("班级:"+classSchool);
System.out.println("总成绩:"+totalScore);
}
public Mysdent() {
super();
// TODO 自动生成的构造函数存根
}
public Mysdent(String name, String college, String major, String classSchool, double totalScore) {
super();
this.name = name;
this.college = college;
this.major = major;
this.classSchool = classSchool;
this.totalScore = totalScore;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getClassSchool() {
return classSchool;
}
public void setClassSchool(String classSchool) {
this.classSchool = classSchool;
}
public double getTotalScore() {
return totalScore;
}
public void setTotalScore(double totalScore) {
this.totalScore = totalScore;
}
}
热心网友 时间:2023-10-18 01:27
class Mystudent{热心网友 时间:2023-10-18 01:28
Eclipse等编辑器都支持自动生成get和set,写完属性值,直接生成就OK了。
对象的两种赋值方式,就写两个构造方法,一个有参,一个无参,也都可以一键生成,敲那几个属性花2分钟,生成其他代码10秒就完成了。
热心网友 时间:2023-10-18 01:27
package test;
public class test{
public static void main(String[] args) {
Mysdent mysdent1 = new Mysdent();
mysdent1.setName("张三");
mysdent1.setCollege("信息学院");
mysdent1.setMajor("计算机专业");
mysdent1.setClassSchool("三班");
mysdent1.setTotalScore(578);
mysdent1.get();
Mysdent mysdent2 = new Mysdent(
"李四", "建设学院", "土木工程专业", "5班", 627);
mysdent2.get();
}
}
class Mysdent {
private String name;//姓名
private String college;//学院
private String major;//专业
private String classSchool;//班级
private double totalScore;//总成绩
public void get() {
System.out.println("======================");
System.out.println("姓名:"+name);
System.out.println("学院:"+college);
System.out.println("专业:"+major);
System.out.println("班级:"+classSchool);
System.out.println("总成绩:"+totalScore);
}
public Mysdent() {
super();
// TODO 自动生成的构造函数存根
}
public Mysdent(String name, String college, String major, String classSchool, double totalScore) {
super();
this.name = name;
this.college = college;
this.major = major;
this.classSchool = classSchool;
this.totalScore = totalScore;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getClassSchool() {
return classSchool;
}
public void setClassSchool(String classSchool) {
this.classSchool = classSchool;
}
public double getTotalScore() {
return totalScore;
}
public void setTotalScore(double totalScore) {
this.totalScore = totalScore;
}
}
热心网友 时间:2023-10-18 01:27
class Mystudent{热心网友 时间:2023-10-18 01:28
Eclipse等编辑器都支持自动生成get和set,写完属性值,直接生成就OK了。
对象的两种赋值方式,就写两个构造方法,一个有参,一个无参,也都可以一键生成,敲那几个属性花2分钟,生成其他代码10秒就完成了。