java编程 有没有人会这道题的 帮帮忙谢谢了
private String name;
private int score;
//无参构造方法
public Student() {
}
//有参构造方法
public Student(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", score=" + score +
'}';
}
}
//测试类
public class StudentTest {
public static void main(String[] args) {
//使用无参构造方法
Student stu1 = new Student();
stu1.setName("student1");
stu1.setScore(100);
//使用有参构造方法
Student stu2 = new Student("student2", 99);
System.out.println("[输出学生1]" + stu1);
System.out.println("[输出学生2]" + stu2);
}
}
2020-04-17
public static void main(String[] args) {
Student student1 = new Student();
student1.setName("李四");
student1.setScore(70);
Student student2 = new Student("张三", 80);
System.out.println(student1);
System.out.println(student2);
}
private String name;
private double score;
public Student(String name, double score) {
this.name = name;
this.score = score;
}
public Student() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public String toString() {
return "姓名: " + this.name + ", 成绩: " + this.score;
}
}
class Student{
private String name;
private double score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public Student() {}
public Student(String name, double score) {
super();
this.name = name;
this.score = score;
}
}
public class TestDemo {
public static void main(String[] args) {
Student stu1 = new Student();
stu1.setName("张三");
stu1.setScore(85);
System.out.println("姓名:"+stu1.getName()+",成绩:"+stu1.getScore());
Student stu2 = new Student("李四",90);
System.out.println("姓名:"+stu2.getName()+",成绩:"+stu2.getScore());
}
}