package henu.rjxy.demo01;
public class Demo01Phone {
private String brand;
private String price;
private String color;
private boolean online;
public void Phone(String brand, String price, String color,boolean online) {
// super();
this.brand = brand;
this.price = price;
this.color = color;
this.online = online;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isOnline() {
return online;
}
public void setOnline(boolean online) {
this.online = online;
}
//1.打电话方法
public void phoneCall(String phoneName,boolean flag){
if(flag){
System.out.println("正在使用"+this.getBrand()+"品牌手机给"+phoneName+"打电话。");
}else{
System.out.println("正在接"+phoneName+"的电话。");
}
}
//2.发信息方法
public void sendMsg(String pnum,boolean flag){
if(flag){
System.out.println("给"+pnum+"手机号码发的信息。");
}else{
System.out.println("收到来自"+pnum+"的短信息。");
}
}
public void show(){
System.out.println(this.brand);
System.out.println(this.price);
System.out.println(this.color);
}
//定义一个测试类,实例化手机类,分别调用以上四个方法。
public static void main(String[] args) {
Demo01Phone phone1 = new Demo01Phone();
phone1.setBrand("苹果");
phone1.setPrice("8000.0");
phone1.setColor("黑");
phone1.phoneCall("张三", true);
phone1.phoneCall("张三", false);
phone1.sendMsg("张三", true);
phone1.sendMsg("张三", false);
phone1.show();
System.out.println("-----------");
Demo01Phone phone2 = new Demo01Phone();
phone2.setBrand("华为");
phone2.setPrice("6000.0");
phone2.setColor("白");
phone2.phoneCall("李四", true);
phone2.phoneCall("李四", false);
phone2.sendMsg("李四", true);
phone2.sendMsg("李四", false);
phone2.show();
System.out.println("-----------");
Demo01Phone phone3 = new Demo01Phone();
phone3.setBrand("三星");
phone3.setPrice("4000.0");
phone3.setColor("红");
phone3.phoneCall("王五", true);
phone3.phoneCall("王五", false);
phone3.sendMsg("王五", true);
phone3.sendMsg("王五", false);
phone3.show();
System.out.println("-----------");
}
}
java写一个类,包括信息为手机的型号,价格和颜色。功能为打电话给某人和发信息给某人
最新推荐文章于 2024-08-20 04:46:10 发布