java写一个类,包括信息为手机的型号,价格和颜色。功能为打电话给某人和发信息给某人

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("-----------");


	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值