附带输入参数的作业代码
package com.imocc;
import java.util.*;
public abstract class Shape {
public abstract void Zc();
public abstract void Mj();
public class Rectangle extends Shape {
int c,k;
public Rectangle(int c,int k){
this.c=c;
this.k=k;
}
public void Zc() {
// TODO Auto-generated method stub
double Zc=2*(c+k);
System.out.println("长方形的周常为:"+Zc);
}
public void Mj() {
// TODO Auto-generated method stub
double Mj=c*k;
System.out.println("长方形的面积:"+Mj);
}
}
public class Circle extends Shape {
int r;
public Circle(int r){
this.r=r;
}
public void Zc() {
// TODO Auto-generated method stub
double Zc=r*2*3.14;
System.out.println("圆的周常为:"+Zc);
}
public void Mj() {
// TODO Auto-generated method stub
double Mj = r * r * 3.14;
System.out.println("圆形的面积为:" + Mj);
}
}
public void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入圆的半径");
Scanner input = new Scanner(System.in);
int r = input.nextInt();
Shape z= new Circle(r);
z.Zc();
z.Mj();
System.out.println("请输入长方形的长和宽");
Scanner input1 = new Scanner(System.in);
int a = input1.nextInt();
Scanner input2 = new Scanner(System.in);
int b = input2.nextInt();
Shape z1=new Rectangle(a,b);
z1.Zc();
z1.Mj();
}
}