猿问

各位大神看看有没有改进的地方

class Squre extends shapeDome{

    private int chang;

    private int kuan;

  

public int getChang() {

return chang;

}

public void setChang(int chang) {

this.chang = chang;

}

public int getKuan() {

return kuan;

}

public void setKuan(int kuan) {

this.kuan = kuan;

}


public void girth() {

setChang(10);

setKuan(5);

        int girth =2*(getChang()+getKuan());

        System.out.println("周长为"+girth);

}


public void area() {

setChang(10);

setKuan(5);

int area=getChang()*getKuan();

System.out.println("面积为"+area);

}

}

class Circle extends shapeDome{

    private int banjing;

    public int getBanjing() {

return banjing;

}

    public void setBanjing(int banjing) {

this.banjing = banjing;

}

public void girth() {

    setBanjing(5);

    double girth=3.14*getBanjing();

    System.out.println("周长为"+girth);

}

public void area() {

    setBanjing(5);

    double area=3.14*getBanjing()*getBanjing();

    System.out.println("面积为"+area);

}

}

public abstract class shapeDome {

   public abstract void girth();

   public abstract void area();

}


public class Initalshap {


public static void main(String[] args) {

    Squre s=new Squre();

    s.getChang();

    s.getKuan();

    s.girth();

    s.area();

    Circle c=new Circle();

    c.getBanjing();

    c.girth();

    c.area();

}

}


慕哥1464261
浏览 1294回答 1
1回答

一曝十寒

public void area() { setChang(10); setKuan(5); int area=getChang()*getKuan(); System.out.println("面积为"+area); } }可以改为 public void area(int A,int B) { setChang(A); setKuan(B); int area=getChang()*getKuan(); System.out.println("面积为"+area); } }其余类似自己改。还有一点命名长宽用英文吧,不会就下个有道词典,命名规范一点。
随时随地看视频慕课网APP

相关分类

Java
我要回答