吉软_java57_第八次作业

package org.jsoft.homework;

public class Chang extends Shape{
    private int width;
    private int length;
    public int getWidth() {
        return width;
    }
    public void setWidth(int width) {
        this.width = width;
    }
    public int getLength() {
        return length;
    }
    public void setLength(int length) {
        this.length = length;
    }
    
}
 

 

package org.jsoft.homework;

public class Circle extends Shape{
    private int r;

    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }
}
 

 

 

package org.jsoft.homework;

public class Zheng extends Shape{
    private int sideLength;

    public int getSideLength() {
        return sideLength;
    }

    public void setSideLength(int sideLength) {
        this.sideLength = sideLength;
    }
}
 

 

package org.jsoft.homework;

import java.util.Scanner;

public class Shape {
    private int r;
    private int width;
    private int length;
    private int sideLength;

    public int getSideLength() {
        return sideLength;
    }

    public void setSideLength(int sideLength) {
        this.sideLength = sideLength;
    }
    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }
    
    public int getWidth() {
        return width;
    }
    public void setWidth(int width) {
        this.width = width;
    }
    public int getLength() {
        return length;
    }
    public void setLength(int length) {
        this.length = length;
    }
    public Shape getShape(Shape c,Shape j,Shape z){
        Scanner sc=new Scanner(System.in);
        int i1=sc.nextInt();
        if(i1==0){
            return c;
        }else if(i1==1){
            return j;
        }else if(i1==2){
            return z;
        }
        return null;
    }
    
}
 

 

package org.jsoft.homework;

import java.util.Scanner;

public class TX {
    public static void main(String[] args) {
        Shape c=new Circle();
            c.setR(2);
        Shape j=new Chang();
            j.setLength(4);
            j.setWidth(2);
        Shape z=new Zheng();
            z.setSideLength(2);
        Shape s=new Shape();
            s.getShape(c, j, z);    
    }
}
 

转载于:https://my.oschina.net/u/3716895/blog/1573712

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值