package org.jsoft.duotai;
public abstract class Shape {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
abstract String display();
}
package org.jsoft.duotai;
public class Circle extends Shape {
private double radius;
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public Circle(double radius,double x,double y){
this.radius=radius;
}
@Override
String display() {
return getName()+"的半径为:"+getRadius();
}
}
package org.jsoft.duotai;
public class Rectangle extends Shape {
private double length;
private double width;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public Rectangle(double length,double width){
this.length=length;
this.width=width;
}
@Override
String display() {
return getName()+"的长为:"+getLength()+",宽为:"+getWidth();
}
}
package org.jsoft.duotai;
public class Square extends Shape {
private double length;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public Square(double length){
this.length=length;
}
@Override
String display() {
return getName()+"的边长为:"+getLength();
}
}
package org.jsoft.duotai;
import java.util.Scanner;
public class TS {
public static Shape getShape(int i){
Shape s1 = new Circle(1,0,0);
Shape s2 = new Rectangle(3,2);
Shape s3 = new Square(2);
switch(i){
case 0:
s1.setName("圆形");
return s1;
case 1:
s2.setName("矩形");
return s2;
case 2:
s3.setName("正方形");
return s3;
default:
return null;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("输入");
int i=sc.nextInt();
System.out.println(TS.getShape(i).display());
}
}