public class Ji { private float num1; private float num2; private float num3; public float getNum1(){ return num1; } public void setNum1(float num1){ if(num1<10){ System.out.println("输入有误,最低为10"); num1=10f; }else { this.num1=num1; } this.num1=num1; } public float getNum2(){ if(num2<15){ System.out.println("输入有误,最低为15"); num2=15f; }else { this.num2=num2; } return num2; } public void setNum2(float num2){ this.num2=num2; } public float getNum3(){ return num3; } public void setNum3(float num3){ if(num3<20){ System .out.println("输入有误,最低为20 "); num3=20f; }else { this.num3=num3; } this.num3=num3; } }
分隔符------------------------------------------------------------
public class Adc { public static void main(String[] args) { Ji ji = new Ji(); ji.setNum1(5.0f); ji.setNum2(6.0f); ji.setNum3(7.0f); System.out.println("num1=" + ji.getNum1() + " num2=" + ji.getNum2() + " num3=" + ji.getNum3()); } }
分隔符---------------------下面为控制台输出部分
输入有误,最低为10
输入有误,最低为20
输入有误,最低为15
num1=10.0 num2=15.0 num3=20.0
进程已结束,退出代码0
没明白你意思
set里写你要修改的数值,get写要得到的数值,这样做来封装类
按照顺序应该是
输入有误,最低为10
输入有误,最低为15
输入有误,最低为20
num1=10.0 num2=15.0 num3=20.0
进程已结束,退出代码0