基于GitHub App业务深度讲解 Kotlin高级特性与框架设计

219 阅读3分钟

download:基于GitHub App业务深度讲解 Kotlin高级特性与框架设计

【Kotlin中文社区负责人亲授】本课程以GitHub APP业务为主线,将Kotlin高级特性与关键技术贯穿始末,带你写出更具Kotlin风格的Android APP;同时结合真实场景,带你设计与实现高质量通用框架,充分提升编程思维。

适合人群
有1年以上 Android 开发经验
想要掌握Kotlin高级特性并提升框架设计能力的开发者

技术储备要求
至少有一个Android项目开发经验
有Kotlin 基础
了解反射、泛型,并发概念
package com.kukudeyu.hotelsystem;
public class Room {
private int id; //房间编号
private String type; //房间类型
private boolean status; //房间状态:true表示闲暇,false表示占用
public Room() {
}
public Room(int id, String type, boolean status) {
this.id = id;
this.type = type;
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
/*

[

package com.kukudeyu.hotelsystem;
public class Hotel {
private Room[][] rooms; //应用二维数组创立酒店房间数组
/

应用结构办法来停止酒店房间布置操作
应用数组遍历,创立酒店房间对象放进酒店房间数组里
其中,
一层为单人世,二层为双人世,三层为总统套房

/
public Hotel() {
rooms = new Room[3][10];
for (int i = 0; i < rooms.length; i++) {
for (int j = 0; j < rooms[i].length; j++) {
if (i == 0) {
rooms[i][j] = new Room((i + 1)

100 + j + 1, "单人世", true);
} else if (i == 1) {
rooms[i][j] = new Room((i + 1)

100 + j + 1, "双人世", true);
} else if (i == 2) {
rooms[i][j] = new Room((i + 1)

100 + j + 1, "总统套房", true);
}
}
}
}
/

print办法提供查看房间列表功用,能够查询一切房间的当前状态
应用循环将一切房间对象均调用Room类的toString办法停止房间状态查询

/
public void print(){
for(int i = 0 ; i< rooms.length ; i++){
for(int j = 0 ; j<rooms[i].length ; j++){
System.out.print(rooms[i][j].toString()); //调用Room类重写的toString办法,查看单个房间的状态
}
System.out.println();
}
}
/

提供booking办法,用于修正房间状态
即订房
调用getStatus办法查询房间状态
假如为true为闲暇,提示订房胜利
假如为false为占用,提示房间占用

/
public void booking(int id){
if(rooms[id / 100 -1][id % 100 -1].getStatus()){
rooms[id / 100 - 1][id % 100 -1].setStatus(false); //调用setStatus办法对房间状态停止修正
System.out.println("订房胜利!");
}else{
System.out.println("房间已占用,请换另外一间房!");
}
}
/

提供cancelBooking办法,用于修正房间状态
即退房
对getStatus办法的返回值运用逻辑非,查询房间状态
假如为false为占用,
*/
public void cancelBooking(int id){
if( rooms[id / 100 -1][id % 100 -1].getStatus() ){
System.out.println("房间闲暇,无需退房!");
}else{
rooms[id / 100 - 1][id % 100 -1].setStatus(true);
System.out.println("退房胜利!");
}
}
}
HotelSystem类(酒店系统类)

](mailto:br/%3E@Override%3Cbr/)