Java語言程式設計(基礎篇)第10版 課後習題13.1答案

來源:互聯網
上載者:User

標籤:rgs   ret   led   private   java   第一個   etc   new t   輸入   

import java.util.*;

abstract class GeometricObject{

  private String color;

 private  boolean filled;  

public String getColor()

{   return color;  }

 public void setColor(String color)

{   this.color = color;  }

 public boolean isFilled()

{   return filled;  }  

public void setFilled(boolean filled)

{   this.filled = filled;  }  

public abstract double getArea();

 public abstract double getPerimeter();

}

class Triangle extends GeometricObject{

 private double oneSide;

 private double twoSide;

 private double threeSide;

 public void setOneSide(double oneSide) {   

this.oneSide = oneSide;  

}

 public void setTwoSide(double twoSide)

{   this.twoSide = twoSide;  }

 public void setThreeSide(double threeSide)

{   this.threeSide = threeSide;  }  

public double getArea()

 {  

 double p = (oneSide + twoSide +threeSide) / 2;   return Math.sqrt(p * (p - oneSide) * (p - twoSide) * (p - threeSide) );  

}

 public double getPerimeter()

 {   return oneSide + twoSide + threeSide;  }

 public String toString()

{  return "area = " + getArea() + "  perimeter" + getPerimeter() + "  color = " + getColor() +"  isFalled = " +  isFilled();  }

}

public class title13_1

{

 public static void main(String[] args)

{   Triangle value = new Triangle();   

System.out.println("請使用者輸入第一個三角形邊:");

  Scanner input = new Scanner(System.in);

  value.setOneSide(input.nextDouble());  

 System.out.println("請使用者輸入第二個三角形邊:");  

 value.setTwoSide(input.nextDouble());   

System.out.println("請使用者輸入第三個三角形邊:");   

value.setThreeSide(input.nextDouble());  

 System.out.println("請使用者輸入顏色:");  

 value.setColor(input.next());

  System.out.println("請使用者輸入是否填充:");  

 value.setFilled(input.nextBoolean());  

 System.out.println("最後結果:  " + value.toString());

 }

}

Java語言程式設計(基礎篇)第10版 課後習題13.1答案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.