public class Phone { private String name; private double neicun; double yiyongneicun; double shengyvneicun; public String getName() { return name; } public void setName(String name) { this.name = name; } public double getNeicun() { return neicun; } public void setNeicun(double neicun) { this.neicun = neicun; } public double getYiyongneicun() { return yiyongneicun; } public void setYiyongneicun(double yiyongneicun) { this.yiyongneicun = yiyongneicun; } public void shengyvneicun() { neicun-=yiyongneicun;//==>neicun=neicun-yiyongneicun shengyvneicun=neicun; // if(shengyvneicun<0) // { // System.out.println("您的内存不足"); // } // else if(shengyvneicun==neicun) // { // System.out.println("您的内存已用完"); // } // else // { System.out.println("剩余内存:"+shengyvneicun+"G."); // } } public Phone(String name, double neicun) { super(); this.name = name; this.neicun = neicun; } public static void main(String[] args) { // TODO 自动生成的方法存根 Phone myphone=new Phone("三星",100); System.out.println("手机品牌是:"+myphone.getName()); System.out.println("内存是"+myphone.getNeicun()+"G的。"); myphone.yiyongneicun=2; System.out.println("手机已用内存;"+myphone.yiyongneicun+"G."); myphone.shengyvneicun(); //myphone.setYiyongneicun(1); } }
手机品牌是:三星
内存是100.0G的。
手机已用内存;2.0G.
剩余内存:98.0G.
解除代码中注释部分,运行出错,跪求老师讲解。
错误输出结果:
手机品牌是:三星
内存是100.0G的。
手机已用内存;2.0G.
您的内存已用完