//根据消息内容进行处理,并回复客户端
if (line.toUpperCase().startsWith("VIP")) { //如果读到的
内容以 "VIP" 开头(不区分大小写)
out.println("Vip2022:" + line); //加上前缀 "Vip2022:",
回复客户端
} else { //否则
out.println("2022:" + line); //加上前缀 "2022:",回复
客户端
}
}
//关闭 I/O 流和客户端 Socket
in.close();
out.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
1.1.4
设计一个个人数据类 Pclass,包含两个私有的宇符串类型的属性: 姓名 (name)
和血型(blood),方法 showName(显示姓名,方法 showBlood () 显示血型,并要
为私有的属性编写相应的 get 和 set 方法。包含两个构造器,一个构造器只能
初始化姓名,另一个构造器可以用来初始化姓名和血型,并能能够记录创建个人
对象的总个数,编写一个公有类 Test 用来测试 Pclass 类,分别使用 Pclass 的
两个构造器来定义对象,并调用其方法。
1)Pclass.java
public class PClass {
private String name;
private String blood;
private static int count = 0;
public PClass(String name) {
this.name = name;
count ++;
}
public PClass(String name, String blood) {
this.name = name;
this.blood = blood;