为了账号安全,请及时绑定邮箱和手机立即绑定

请大家看一下哪里需要简化改正一下

package com;

import java.util.Scanner;

public class test1 {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
   Square square1 = new Circle();
   System.out.println("圆的面积为:"+square1.Area()+",圆的周长为:"+square1.Circumference());
   
   Square square2 = new Rectangle();
   System.out.println("矩形的面积为:"+square2.Area()+",矩形的周长为:"+square2.Circumference());
 }

}

abstract class Square{
 abstract float Area();
 abstract float Circumference();
}
class Circle extends Square{
 public int r;
 public float p = 3.14f;
 
 public Circle() {
  Scanner input = new Scanner(System.in);
  System.out.print("请输入圆的半径:");
  r = input.nextInt();
 }
 @Override
 float Area() {
  // TODO Auto-generated method stub
  return r*r*p;
 }

 @Override
 float Circumference() {
  // TODO Auto-generated method stub
  return p*r*2;
 }
 
}

class Rectangle extends Square{
 public int len,wid;
 public Rectangle() {
  // TODO Auto-generated constructor stub
  
  Scanner input = new Scanner(System.in);
  System.out.print("请输入矩形的长:");
  len = input.nextInt();
  System.out.print("请输入矩形的宽:");
  wid = input.nextInt();
 }
 @Override
 float Area() {
  // TODO Auto-generated method stub
  return len*wid;
 }

 @Override
 float Circumference() {
  // TODO Auto-generated method stub
  return (len+wid)*2;
 }
 
}


正在回答

1 回答

没毛病


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请大家看一下哪里需要简化改正一下

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信