Java第四次作业
public class manage{ private int l; private int n; public manage() { } public manage(int l,int n) { this.l=l; this.n=n; } public int getshow1() { return l; } public void setshow1(int l) { this.l=l; }//设置上月电费情况 public int getshow2() { return n; } public void setshow2(int n) { if(n%100==0) this.n=n; else n=n-n%100+100; }//设置本月电费情况 public void things() { System.out.println("上月电费情况"+l+",本月电费情况"+n); } public static void main(String args[]) { manage m1 = new manage(1000,1200); m1.things(); System.out.println("本月缴费情况"+(m1.n-m1.l)*1.2); manage m2 = new manage(1200,1450); m2.things(); System.out.println("本月缴费情况"+(m2.n-m2.l)*1.2); } } 复制代码 2、 编写“圆柱体”类及其测试类。 复制代码 public class cylinder { private int r; private int h; public cylinder(int r,int h) { this.r = r; this.h = h; } public int getRadius() { return r; } public void setRadius(int r) { this.r=r; }//设置半径 public double gerHeight() { return h; } public void setHeight(int h) { this.h=h; }//设置高度 public void BaseArea() { System.out.println("底面积"+3.14*r*r); } public void Volumr() { System.out.println("体积"+3.14*r*r*h); } public void All() { System.out.println("圆底半径,"+r+",高"+h+",底面积"+3.14*r*r+",体积"+3.14*r*r*h); } public static void main(String args[]) { cylinder c1= new cylinder(5,6); c1.BaseArea(); c1.Volumr(); c1.All(); cylinder c2= new cylinder(7,8); c2.BaseArea(); c2.Volumr(); c2.All(); } } 复制代码 3、编写“四则运算类”及其测试类。 复制代码 package leven; import java.util.*; public class operation { private int num1; private int num2; private String opera; public operation(int num1,int num2,String opera) { this.num1=num1; this.num2=num2; this.opera=opera; } public int getNum1() { return num1; } public void setNum1(int num1) { this.num1=num1; } public int getNum2() { return num2; } public void setNum2(int num1, int num2) { this.num2=num2; } public void Plus() { System.out.println(num1+num2); } public void Subtract() { System.out.println(num1-num2); } public void Multiply() { System.out.println(num1*num2); } public void Divide() { System.out.println(num1/num2); } public static void main(String args[]) { int i,j; String k; Scanner sc = new Scanner(System.in); i=sc.nextInt(); j=sc.nextInt(); k=sc.next(); operation o1 = new operation(i,j, k); System.out.println("请输入两个数和一个操作符号:"); if(k=="+") o1.Plus(); if(k=="-") o1.Subtract(); if(k=="*") o1.Multiply(); if(k=="/") o1.Divide(); } }