java设计一个course类并且给出运行结果
时间: 2024-03-23 08:41:26 浏览: 48
好的,下面是一个简单的Java Course类的设计:
```java
public class Course {
private String courseName;
private int courseCode;
private int creditHours;
public Course(String name, int code, int credits) {
courseName = name;
courseCode = code;
creditHours = credits;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String name) {
courseName = name;
}
public int getCourseCode() {
return courseCode;
}
public void setCourseCode(int code) {
courseCode = code;
}
public int getCreditHours() {
return creditHours;
}
public void setCreditHours(int credits) {
creditHours = credits;
}
public void displayCourseInfo() {
System.out.println("Course Name: " + courseName);
System.out.println("Course Code: " + courseCode);
System.out.println("Credit Hours: " + creditHours);
}
}
```
下面是一个简单的测试程序,用于演示Course类的使用:
```java
public class CourseTest {
public static void main(String[] args) {
Course java = new Course("Java Programming", 101, 3);
java.displayCourseInfo();
}
}
```
运行结果为:
```
Course Name: Java Programming
Course Code: 101
Credit Hours: 3
```
阅读全文