首页 > 代码库 > Java实验题3_3_林大锐格平台

Java实验题3_3_林大锐格平台

import java.util.Scanner;
abstract class Shape{
    abstract float GetArea();
    abstract float GetPerimeter();
}
class Rectangle{
    private double x,y;
    public Rectangle(int i, int j) {
		x=i;
		y=j;
	}
	public float GetArea(){
		return (float)(x*y);
	}
	public float GetPerimeter(){
		return (float)((x+y)*2) ;
	}
	//write code here
	
}
class Circle{
	private double a;
    public Circle(int i) {
		a=i;
	}
	public float GetArea(){
		return (float)(a*3.14*a);
	}
	public float GetPerimeter(){
		return (float)(3.14*2*a);
	}
    //write code here
	
}
public class Main{
    public static void main(String[] args){
    	Scanner sca = new Scanner(System.in);
    	int a = sca.nextInt();
    	int b = sca.nextInt();
    	int r = sca.nextInt();
        Rectangle aa = new Rectangle(a,b);
        System.out.println(aa.GetArea());
        System.out.println(aa.GetPerimeter());
        Circle c = new Circle(r);
        System.out.println(c.GetArea());
        System.out.println(c.GetPerimeter());
    }
}

  

Java实验题3_3_林大锐格平台