吉软 2017年11月11日作业

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());
     }
}

123605_ScAP_3716245.png

转载于:https://my.oschina.net/u/3716245/blog/1573854

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值