随着科技的发展,手机的使用已经普及到每个家庭甚至个人,手机的属性越来越强大,功能也越来越多,因此人们在生活中越来越依赖于手机。
任务要求,使用所学知识编写一个手机属性及功能分析程序设计,测试各个手机的属性及功能。使用手机时,输出当前手机的各个属性参数以及正在使用的功能
项目效果
My_Phone类
public class My_Phone {
private String brand;
private String type;
private int price;
private String os;
private String memory;
private String call_name;
private String music_name;
public My_Phone(String brand, String type, int price, String os, String memory) {
this.brand = brand;
this.type = type;
this.price = price;
this.os = os;
this.memory = memory;
}
public void about(){
System.out.println("品牌:"+brand+"\n"+"型号:"+brand+"\n"+"操作系统:"+type+"\n"+"价格:"+price+"\n"+"内存:"+memory+"\n");
}
public void call(String call_name){
System.out.println("使用自动拨号功能");
System.out.println("给"+call_name+"打电话");
}
public void playGame(){
System.out.println("上号吗,来一把");
}
public void downloadMUsic(String music_name){
System.out.println("下载歌曲"+music_name);
}
public void playMusic(String music_name){
System.out.println("播放音乐"+music_name);
}
}
Test_Phone类
import java.util.Enumeration;
import java.util.Scanner;
public class Test_Phone {
public static void main(String[] args) {
My_Phone ph=new My_Phone("苹果","iphoneX",8888,"ios","16G");
Scanner sc = new Scanner(System.in);
while (true){
System.out.println("请输入一个功能选项:");
System.out.println("=======1、输出信息==========");
System.out.println("=======2、打电话==========");
System.out.println("=======3、下载歌曲==========");
System.out.println("=======4、打游戏==========");
System.out.println("=======5、播放音乐==========");
System.out.println("=======6、关机==========");
int num = sc.nextInt();
switch (num){
case 1:
ph.about();
break;
case 2:
Scanner scanner = new Scanner(System.in);
String inputWord = scanner.next();
ph.call(inputWord);
break;
case 3:
Scanner sc_down_music = new Scanner(System.in);
String down_music = sc_down_music.next();
ph.downloadMUsic(down_music);
break;
case 4:
ph.playGame();
break;
case 5:
Scanner sc_music = new Scanner(System.in);
String play_music = sc_music.next();
ph.playMusic(play_music);
break;
case 6:
System.out.println("本次服务到此结束");
System.exit(0);
break;
default:
System.out.println("没有此功能");
}
}
}
}