import java.util.Scanner; public class driver{ public static void main(String[] args){ phone p1 = new phone(); phone p2 = new phone(); p1.brand="苹果"; p1.type="iphone"; p1.os="ios"; p1.price=2000; p1.memory=60; p1.call="好友布里茨"; p1.game="拳皇"; p1.music="青花瓷"; p2.brand="苹果"; p2.type="iphone10"; p2.os="ios"; p2.price=9000; p2.memory=120; p2.call="好友诺提勒斯"; p2.game="切西瓜"; p2.music="兔子舞"; int x; Scanner sc = new Scanner(System.in); System.out.println("请输入数字查看手机配置与功能:1 or 2"); x=sc.nextInt(); switch (x){ case 1: p1.about(); p1.call(); p1.playgame(); p1.downloadmusic(); p1.playmusic();break; case 2: p2.about(); p2.call(); p2.playgame(); p2.downloadmusic(); p2.playmusic();break; } } } class phone{ String brand; String type; int price; String os; int memory; String call; String game; String music; public void about(){ System.out.println("品牌:"+brand); System.out.println("型号:"+type); System.out.println("操作系统:"+os); System.out.println("价格:"+price); System.out.println("内存:"+memory); System.out.println(" "); System.out.println(" "); } public void call(){ System.out.println("正在使用手机拨号功能,正在给"+call+"进行拨号"); } public void playgame(){ System.out.println("您所玩的游戏是:"+game); } public void downloadmusic(){ System.out.println("正在下载音乐:"+music); } public void playmusic(){ System.out.println("正在播放音乐:"+music); } }
【案例3-3】查看手机配置与功能
最新推荐文章于 2024-08-10 17:50:46 发布