任务3-3 查看手机配置与功能

此博客围绕使用Java编写程序展开。随着科技发展,手机普及且功能强大。案例要求针对两款配置和功能不同的手机,编写程序实现查看其配置(品牌、型号等)及功能(自动拨号等),并将结果打印在控制台,还给出了相关代码及运行结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

题目

代码

1.Phone.java

2.PhoneTest.java

运行结果


题目

随着科技的发展,手机早已普及,手机的功能越来越多且越来越强大,人们在生活中越来越依赖手机。

有两款配置和功能都不同的手机,配置信息包括品牌、型号、操作系统、价格和内存;手机功能包括自动拨号、游戏和播放歌曲。本案例要求使用所学的知识编写一个程序,实现查看手机配置及功能,并将查看结果打印在控制台。

代码

1.Phone.java

package item10.example;

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

	    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("价格: " + price);
	        System.out.println("内存: " + memory + "\n");
	    }

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

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

	    public void downloadMusic(String name) {
	        System.out.println("下载音乐" + name);
	    }

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

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

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

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

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

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

		public String getBrand() {
			return brand;
		}

		public String getType() {
			return type;
		}

		public String getOs() {
			return os;
		}

		public double getPrice() {
			return price;
		}

		public int getMemory() {
			return memory;
		}
}

2.PhoneTest.java

package item10.example;

public class PhoneTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Phone p1=new Phone("苹果","iphoneX","ios",8888,8);
        p1.about();
        p1.call("1");
        p1.playGame();
        p1.downloadMusic("我的中国心");
        p1.playMusic("我的中国心");
        System.out.println("----------------------------------------------");
 
        Phone p2=new Phone("华为","华为荣耀20","Android",6666,16);
        p2.about();
        p2.call("2");
        p2.playGame();
        p2.downloadMusic("北京欢迎你");
        p2.playMusic("北京欢迎你");
	}
}

运行结果

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值