1 package demo; 2 3 public class dianfeiguanli { 4 private int shangyue; 5 private int benyue; 6 public dianfeiguanli(int shangyue , int benyue){ 7 this.shangyue = shangyue; 8 this.benyue = benyue; 9 } 10 11 public int getShangyue(){ 12 return shangyue; 13 } 14 public int getBenyue(){ 15 return benyue ; 16 } 17 public void setShangyue(int shangyue){ 18 this.shangyue = shangyue; 19 } 20 public void setBenyue(int benyue){ 21 this.benyue = benyue; 22 } 23 public void print(){ 24 System.out.println("shangyue"+shangyue+"benyue"+benyue); 25 } 26 }
1 package demo; 2 3 public class Testdianfeiguanli { 4 public static void main(String[] args) { 5 dianfeiguanli l1 = new dianfeiguanli(1200, 1450); 6 l1.setBenyue(1500); 7 System.out.println("电费:"+(l1.getBenyue()-l1.getShangyue())*1.2); 8 } 9 }
1 package demo; 2 3 public class yuanzhu { 4 private double r,h; 5 double PAI = 3.14; 6 double s; 7 double v; 8 public yuanzhu(double r,double h) { 9 this.r = r; 10 this.h = h; 11 } 12 public void s() { 13 s=r*r*PAI; 14 } 15 public void v() { 16 v=r*r*PAI*h; 17 } 18 public void print() { 19 System.out.println("圆的半径为:"+r+",圆的高为:"+h+",圆的底面积为:"+s+",圆的体积为:"+v); 20 } 21 }
1 package demo; 2 3 public class Testyuanzhu { 4 5 public static void main(String[] args) { 6 yuanzhu y1 = new yuanzhu(2.00,4.00); 7 y1.s(); 8 y1.v(); 9 y1.print(); 10 yuanzhu y2 = new yuanzhu(4.00,6.00); 11 y2.s(); 12 y2.v(); 13 y2.print(); 14 15 } 16 17 }
我只会这么一点点,这两个我也不怎会,那调用不知道怎么调,要多看看书啊,多看看程序。