写了一个有参无返回值的方法代码,求大神写一个有参有返回值的代码(目前什么情况下用有参有返回值的方法,什么情况下用无参无返回值的方法还不是太清楚)
package shape;
public abstract class Shape {
// double i = 0;
// double j = 0;
//public abstract double perimeter(double length,double wide);
public abstract void perimeter(double length,double wide);
public abstract void perimeter(double radious);
public abstract void area(double length,double wide);
public abstract void area(double radius);
}
package shape;
public class Rectangle extends Shape{
public void perimeter(double length, double wide) {
// TODO Auto-generated method stub
double perimeter =(length + wide)*2;
//return 0;
System.out.println("矩形的周长为:" + perimeter);
}
public void area(double length,double wide) {
// TODO Auto-generated method stub
double area = length*wide;
System.out.println("矩形的面积为:" + area);
//return area;
}
public void perimeter(double radious) {
// TODO Auto-generated method stub
//return 0;
}
public void area(double radius) {
// TODO Auto-generated method stub
//return 0;
}
}
package shape;
public class Circle extends Shape{
public void perimeter(double length, double wide) {
// TODO Auto-generated method stub
// return 0;
}
public void perimeter(double radious) {
// TODO Auto-generated method stub
double perimeter = 2*Math.PI*radious;
System.out.println("园的周长为:" + perimeter);
// return perimeter;
}
public void area(double length, double wide) {
// TODO Auto-generated method stub
// return 0;
}
public void area(double radius) {
// TODO Auto-generated method stub
double area = Math.PI*Math.pow(radius, 2);
System.out.println("圆的的面积为:" + area);
// return area;
}
}
package shape;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape sh = new Rectangle();
sh.perimeter(5, 4);
sh.area(5, 4);
Shape sh1 = new Circle();
sh1.perimeter(5);
sh1.area(5);
}
}