package com.itheima;
public class Phone {
private String brand;
private int type;
private int price;
private String os;
private String memory;
public String getBrand(){
return brand;
}
public void setBrand(String brand)
{
this.brand = brand;
}
public String getType(){
return brand;
}
public void setType(int type){
this.type = type;
}
public int getPrice(){
return price;
}
public void setPrice(int price){
this.price = price;
}
public String getOs(){
return os;
}
public void setOs(String os){
this.os = os;
}
public String getMemory(){
return memory;
}
public void setMemory(String memory)
{
this.memory = memory;
}
public Phone(){
}
public Phone(String brand, int type, int price, String os, String memory){
this.brand = brand;
this.type = type;
this.price = price;
this.os = os;
this.memory = memory;
}
public String about(){
return "手机品牌" + this.brand + ",手机型号为"+ this.type;
}
public String call(String no){
return "使用" + this.brand + "手机打电话给" + no;
}
public String playGame(){
return this.brand + "手机游戏";
}
public String downloadMusic(){
return this.brand + "手机下载音乐";
}
public String playMusic(){
return this.brand + "手机播放音乐";
}
}
package com.itheima;
public class Main {
public static void main(String[] args){
Phone phone1 = new Phone("vivo", 1, 2000, "windows", "128G");
System.out.println(phone1.about());
System.out.println(phone1.call("123456"));
System.out.println(phone1.playGame());
System.out.println(phone1.downloadMusic());
System.out.println(phone1.playMusic());
System.out.println("------------------------------------------------");
Phone phone2 = new Phone();
phone2.setBrand("oppo");
phone2.setType(2);
phone2.setPrice(2300);
phone2.setOs("linux");
phone2.setMemory("248G");
System.out.println(phone2.about());
System.out.println(phone2.call("24689"));
System.out.println(phone2.playGame());
System.out.println(phone2.downloadMusic());
System.out.println(phone2.playMusic());
}
}
java基础案例3-3查看手机配置和功能
于 2022-02-07 01:18:41 首次发布