java实验报告——手机类

实验报告

(1)定义一个手机类,定义若干属性,方法和构造方法;

(2)定义测试类,其中定义多个手机类对象,并设置不同的初始值;

(3)调用手机类的相关方法,测试该类的功能。

public class S3_3 {
    static class Mobile{
        String brand;
        String type;
        int price;
        String size;
        int pixel;
        public Mobile(){

        }
        public Mobile(String brand,String type,int price,String size,int pixel){
            super();
            this.brand=brand;
            this.type=type;
            this.price=price;
            this.size=size;
            this.pixel=pixel;
        }
        public void call(){
            System.out.println("使用"+this.brand+this.type+"的手机打电话");
        }
        public void network(){
            System.out.println("使用"+this.brand+this.type+"的手机上网");
        }
        public void playgame(){
            System.out.println("使用"+this.brand+this.type+"的手机玩游戏");
        }
    }
}
public class S3_3Test extends S3_3{
    public static void main(String[] args) {
        Mobile[] mobiles=new Mobile[3];
        mobiles[0]=new Mobile("苹果","12pro ",8000,"150*50",1200);
        mobiles[1]=new Mobile("三星","note20",6000,"140*40",1100);
        mobiles[2]=new Mobile("华为","mate40",9000,"160*60",1500);
        System.out.println("\t\t手机信息一览表");
        System.out.println("品牌\t型号\t\t价格\t\t尺寸\t\t像素");
        System.out.println("-------------------------------------");
        for(int i=0;i<mobiles.length;i++){
            System.out.println(mobiles[i].brand+"\t"+mobiles[i].type+"\t"+mobiles[i].price+"\t"+mobiles[i].size+"\t"+mobiles[i].pixel);
        }
        System.out.println("-------------------------------------");
        mobiles[2].network();
        mobiles[0].playgame();
    }
}

在这里插入图片描述

  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值