zoukankan      html  css  js  c++  java
  • 编写的一个“手机”的类

      尝试编写一个类,定义一个修饰权限为private的成员变量,定义两个成员方法,一个方法实现为此成员变量赋值,另一个成员方法获取这个成员变量的值,保证其它类继承该类时能获取该类的成员变量的值。

    编写的一个手机类:

      1 package org.hanqi.pn0120;
      2 
      3 public class Phone {
      4 
      5     private  String pinpai;
      6     
      7     private  double neicun;
      8     
      9     public String getPinpai() {
     10         return pinpai;
     11     }
     12 
     13     public void setPinpai(String pinpai) {
     14         this.pinpai = pinpai;
     15     }
     16 
     17     public double getNeicun() {
     18         return neicun;
     19     }
     20 
     21     public void setNeicun(double neicun) {
     22         this.neicun = neicun;
     23     }
     24     
     25     private  double yiyongnc;
     26     
     27     public double yiyongnc()
     28     {
     29         return  this.yiyongnc;
     30     }
     31     
     32     private  double shengyunc;
     33     
     34 //    public double shnegyunc()
     35 //    {
     36 //            return  this.shengyunc;
     37 //    }
     38          
     39     public void yunxingsudu(double shengyunc )
     40     {
     41         if( shengyunc>0)
     42         {
     43             System.out.println("手机正常运行,运行速度较快!");
     44         }
     45         else if(shengyunc==0)
     46         {
     47             System.out.println("手机内存不足,运行速度减慢,请及时清理!");
     48         }
     49         else
     50         {
     51             System.out.println("表闹了,你手机超神了!");
     52         }
     53         
     54     }
     55     
     56     public void xiazai(double yiyongnc)
     57     {
     58         double shengyunc=neicun-yiyongnc;
     59         
     60         if(yiyongnc>0&&yiyongnc<16)
     61         {            
     62             System.out.println("手机剩余内存"+shengyunc+"G");
     63         }
     64         else if(yiyongnc==16)
     65         {
     66             System.out.println("手机内存不足,剩余"+shengyunc+"G内存");
     67         }
     68         else
     69         {
     70             System.out.println("手机穿越了!");
     71         }
     72         
     73         
     74     }
     75 
     76     public Phone(String pinpai, double neicun) {
     77         super();
     78         this.pinpai = pinpai;
     79         this.neicun = neicun;
     80     }
     81     
     82     public  static void  main(String[] args)
     83     {
     84         Phone myPhone=new  Phone("iphone5",16);
     85         
     86         System.out.println("手机是"+myPhone.getPinpai());
     87         
     88         System.out.println("手机内存是"+myPhone.getNeicun()+"G");
     89         
     90         myPhone.yunxingsudu(4);
     91         
     92         myPhone.yunxingsudu(0);
     93         
     94         myPhone.yunxingsudu(20);
     95         
     96         myPhone.xiazai(12);
     97         
     98         myPhone.xiazai(16);
     99         
    100         myPhone.xiazai(25);
    101     }
    102     
    103 }
    Phone

  • 相关阅读:
    Redis是可以安装成windows服务-开机自启 win7 64位
    lnmp 一键安装包 nginx配置tp5 phpinfo模式 隐藏index.php
    Redis PHP通用类
    Swoole2.0协程客户端连接池的实现
    Tomcat 部署项目无法加载静态资源
    IntelliJ IDEA 的下载和安装
    Redis 配置内容总结
    Eclipse 中 Spring 项目的 XML 配置文件报错 Referenced file contains errors
    Eclipse 中 Maven 项目 pom.xml 提示错误 org.codehaus.plexus.archiver.jar.Manifest.write(java.io.PrintWriter)
    文本编辑器 EditPlus 的激活与设置
  • 原文地址:https://www.cnblogs.com/arxk/p/5248942.html
Copyright © 2011-2022 走看看