Chào các bạn! Truyen4U chính thức đã quay trở lại rồi đây!^^. Mong các bạn tiếp tục ủng hộ truy cập tên miền Truyen4U.Com này nhé! Mãi yêu... ♥

Ngoại Lệ

/*

 * SoAm.java

 *

 * Created on March 17, 2011, 7:37 AM

 *

 * To change this template, choose Tools | Template Manager

 * and open the template in the editor.

 */

package lab05;

/**

 *

 * @author pvhoai

 */

public class SoAm extends Exception{

    /** Creates a new instance of SoAm */

    public SoAm() {

    }

    public SoAm(String str) {

        super(str);

    }

}

/*

 * HinhTron.java

 *

 * Created on March 17, 2011, 7:38 AM

 *

 * To change this template, choose Tools | Template Manager

 * and open the template in the editor.

 */

package lab05;

import java.util.Scanner;

/**

 *

 * @author pvhoai

 */

public class HinhTron {

    /** Creates a new instance of HinhTron */

    float banKinh;

    public HinhTron() {

        banKinh = 0;

    }

    public HinhTron(float r) {

        banKinh = r;

    }

    public float ktSoAm() throws SoAm{

        if(banKinh<=0){

            throw new SoAm("ban kinh bi am roi");

        } else{

            return banKinh;

        }

    }

    public float tinhDienTich(){

        float dt;

        dt = 3.14f*banKinh*banKinh;

        return dt;

    }

    public float tinhChuVi(){

        float cv;

        cv = 2f*3.14f*banKinh;

        return cv;

    }

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        Scanner sc =new Scanner(System.in);

        System.out.println("Nhap vao ban kinh hinh tron: ");

        float bk = sc.nextFloat();

        HinhTron ht = new HinhTron(bk);

        try{

            ht.ktSoAm();

            System.out.println("Dien tich la: "+ht.tinhDienTich());

            System.out.println("Chu vi la: "+ht.tinhChuVi());

        }catch(SoAm e){

            e.printStackTrace();

        }

    }

}

Bạn đang đọc truyện trên: Truyen4U.Com

Tags: