gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
java设计一个学生类Student,并进行测试,要求如下: ①Student类中包含两个私有的成员属性姓名、成绩; ②分别为两个属性定义两个方法、一个方法用于设置值,…
- User
java设计一个学生类Student,并进行测试,要求如下: ①Student类中包含两个私有的成员属性姓名、成绩; ②分别为两个属性定义两个方法、一个方法用于设置值, 一个方法用于获取值; ③Student 类中定义一个无参构造方法和一个接收两个参数的有参构造方法。 实验扩展,将Student类和测试类分别放在不同的包中,测试实验效果。
- Assistant
//Student类代码 package com.example.demo;
public class Student { private String name; private double score;
public Student() {} public Student(String name, double score) { this.name = name; this.score = score; } public void setName(String name) { this.name = name; } public void setScore(double score) { this.score = score; } public String getName() { return name; } public double getScore() { return score; }}
//测试类代码 package com.example.test;
import com.example.demo.Student;
public class Test { public static void main(String[] args) { Student stu1 = new Student(); stu1.setName("Tom"); stu1.setScore(90); System.out.println("姓名:" + stu1.getName() + ",成绩:" + stu1.getScore());
Student stu2 = new Student("Jerry", 80); System.out.println("姓名:" + stu2.getName() + ",成绩:" + stu2.getScore()); }}