随着科技的发展,手机的使用已经普及到每个家庭甚至个人,手机的属性越来越强大,功能也越来越多,因此人们在生活中越来越依赖于手机。

任务要求,使用所学知识编写一个手机属性及功能分析程序设计,测试各个手机的属性及功能。使用手机时,输出当前手机的各个属性参数以及正在使用的功能。

创建手机类

package 实验四;


public class phone {
    private String brand;
    private String type;
    private String os;
    private double price;
    private int memory;

    public phone() {}

    public phone(String brand, String type, String os, double price, int memory) {
        this.brand = brand;
        this.type = type;
        this.os = os;
        this.price = price;
        this.memory = memory;
    }

    public void about() {
        /* 查看手机信息 */
        System.out.println("品牌: " + brand);
        System.out.println("型号: " + type);
        System.out.println("操作系统: " + os);
        System.out.println("价格(RMB): " + price);
        System.out.println("内存(G): " + memory);
    }

    public void call(String number) {
        System.out.println("使用自动拨号功能");
        String phoneNumber = null;
        switch (number) {
            case "1":
                phoneNumber = "爷爷的号";
                break;
            case "2":
                phoneNumber = "奶奶的号";
                break;
        }
        System.out.println(phoneNumber);
    }

    public void playGame() {
        System.out.println("玩扫雷游戏");
    }

    public void downloadMusic() {
        System.out.println("开始下载");
        System.out.println("下载完成");
    }

    public void playMusic(String song) {
        System.out.println("播放歌曲:" + song);
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getOs() {
        return os;
    }

    public void setOs(String os) {
        this.os = os;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getMemory() {
        return memory;
    }

    public void setMemory(int memory) {
        this.memory = memory;
    }
}

创建测试类

package 实验四;


public class phonetest {
    public static void main(String[] args) {
        phone p1 = new phone();
        p1.setBrand("苹果");
        p1.setType("iPhone Xs");
        p1.setOs("ios");
        p1.setPrice(8888);
        p1.setMemory(16);

        p1.about();
        p1.call("1");
        p1.playMusic("我的中国心");
        p1.playGame();
        System.out.println("*********************");

        phone p2 = new phone("华为", "华为荣耀20", "Android", 6666, 16);
        p2.about();
        p2.call("3");
        p2.playGame();
        p2.playMusic("北京欢迎你");
    }
}

  • 2
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
好的,我可以帮你编写这个程序。首先,我们需要定义一个手机类,包含各个属性功能的参数。代码如下: ```python class Phone: def __init__(self, brand, model, color, screen_size, battery_capacity, camera_resolution, price): self.brand = brand self.model = model self.color = color self.screen_size = screen_size self.battery_capacity = battery_capacity self.camera_resolution = camera_resolution self.price = price self.current_app = None def make_call(self, number): print("Dialing", number) def send_message(self, message): print("Sending message:", message) def open_app(self, app_name): self.current_app = app_name print("Opening", app_name) def close_app(self): self.current_app = None print("Closing app") def check_battery(self): print("Battery remaining:", self.battery_capacity, "mAh") def take_photo(self): print("Taking photo with", self.camera_resolution, "megapixel camera") def record_video(self): print("Recording video with", self.camera_resolution, "megapixel camera") ``` 在这个类,我们定义了手机的各项属性,如品牌、型号、颜色、屏幕大小、电池容量、相机分辨率和价格,以及一些手机功能,如打电话、发短信、打开应用、关闭应用、查看电池剩余容量、拍照和录像。 接下来,我们需要创建一个手机对象,并测试其属性功能。代码如下: ```python my_phone = Phone("Apple", "iPhone 12 Pro", "Silver", "6.1 inches", 2815, 12, 999) print("Brand:", my_phone.brand) print("Model:", my_phone.model) print("Color:", my_phone.color) print("Screen size:", my_phone.screen_size) print("Battery capacity:", my_phone.battery_capacity, "mAh") print("Camera resolution:", my_phone.camera_resolution, "megapixels") print("Price:", my_phone.price) my_phone.make_call("1234567890") my_phone.send_message("Hello, world!") my_phone.open_app("Messages") my_phone.take_photo() my_phone.check_battery() my_phone.close_app() ``` 在这个例子,我们创建了一个苹果 iPhone 12 Pro 手机对象,并测试了其属性功能,如拨打电话、发送短信、打开应用、拍照、查看电池剩余容量和关闭应用。 程序的输出结果如下: ``` Brand: Apple Model: iPhone 12 Pro Color: Silver Screen size: 6.1 inches Battery capacity: 2815 mAh Camera resolution: 12 megapixels Price: 999 Dialing 1234567890 Sending message: Hello, world! Opening Messages Taking photo with 12 megapixel camera Battery remaining: 2815 mAh Closing app ``` 这里展示了当前手机的各个属性参数以及正在使用功能,包括拨打电话、发送短信、打开应用、拍照、查看电池剩余容量和关闭应用。 希望这个程序能够帮助你分析和测试各种手机属性功能,更好地使用手机

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值