南通渡课 IT 教育 111 班同学在 3 教室上崔老师的 Java 课」这个场景进行业务类的抽象,类中包含属性和方法。"/>
将「南通渡课 IT 教育 111 班同学在 3 教室上崔老师的 Java 课」这个场景进行业务类的抽象,类中包含属性和方法。
从中抽象出来的类
1.学校
2.同学
3.教室
4.老师
5.课程
1.学校类
public class School {
// 成员变量
String name;
int tel;
String address;
// 构造器
School(String name, int tel, String address) {
this.name = name;
this.tel = tel;
this.address = address;
}
// 方法
String intro() {
return “这个学校名称是”+this.name+",联系电话是"+this.tel+",地址为"+this.address;
}
}
2.同学类
public class Classmate{
//成员变量
String name;
String code;
int age;
//构造器
Classmate(String name, String code, int age){
this.name=name;
this.code=code;
this.age=age;
//方法
String intro() {
return “我叫”+this.name+",我的学号是"+this.code+",我今年"+this.age+“岁了。”;
}
}
3.教室类
public class Classroom {
// 成员变量
String name;
double size;
String color;
//构造器
Classroom(String name, double size, String color) {
this.name = name;
this.size = size;
this.color=color;
}
// 方法
String intro() {
return “教室名”+this.name+",教室座位数"+this.number;
}
}
4.老师类
public class Teacher {
// 成员变量
String name;
int age;
String code;
//构造器
Teacher(String name, int age, String code) {
this.name = name;
this.age = age;
this.code = code;
}
// 方法
String intro() {
return “老师叫”+this.name+",老师的编号是"+this.code+",老师今年"+this.age+“岁了。”;
}
}
5.课程类
public class Course {
// 成员变量
String name;
int code;
//构造器
Course(String name, int code) {
this.name = name;
}
// 方法
String intro() {
return “课程名”+this.name;
}
}
更多推荐
将「南通渡课 IT 教育 111 班同学在 3 教室上崔老师的 Java 课」这个场景进行业务类的抽象,类中包含属性和方法。
发布评论