将「南通渡课 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;
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值