2 dyxm21 dyxm21 于 2016.04.22 18:25 提问

写接口,求大神源码⋯⋯

求大神源码⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯图片说明

2个回答

hcb9291
hcb9291   2016.04.22 19:42

import java.util.Scanner;
interface Shape {
/*
*
*/
double getArea();

double getCircumsta();

}

class Triangle implements Shape {
/*
*
*/
private double sideA;
private double sideB;
private double sideC;
private boolean flage;

Triangle(double a, double b, double c) {
    this.sideA = a;
    this.sideB = b;
    this.sideC = c;
    if ((a + b > c && a - b < c) || (a - c > b && a + c > b)
            || (b + c > a && b - c < a)) {
        this.flage = true;
    } else {
        this.flage = false;
    }
}

public double getArea() {
    if (flage) {
        double s = sideA + sideB + sideC;
        return Math.sqrt(s * (s - sideA) * (s - sideB) * (s - sideC));

    } else {
        System.out.println("不能构成三角形");
        return 0.0;
    }

}

public double getCircumsta() {
    if (flage) {

        return sideA + sideB + sideC;
    }

    else {
        System.out.println("不能构成三角形");

        return 0.0;
    }

}

}

class RecTangle implements Shape {
/*
*
*/
private double sideA;
private double sideB;

RecTangle(double a, double b) {
    this.sideA = a;
    this.sideB = b;
}

public double getArea() {//实现接口方法

    return sideA * sideB;
}

public double getCircumsta() {//实现接口方法
    return 2 * (sideA + sideB);
}

}

public class T1 {
/*
*
*/
public static void main(String[] args) {
Scanner myInput = new Scanner(System.in);

    System.out.println("请输入需要计算的三角形的三边长:");
    System.out.println("第一边:");
    double a = myInput.nextDouble();
    System.out.println("第二边:");
    double b = myInput.nextDouble();
    System.out.println("第三边:");
    double c = myInput.nextDouble();

    Triangle myTri = new Triangle(a, b, c);//创建一个三角形对象

    System.out.println("请输入需要计算的长方形的边长:");
    System.out.println("长:");
    double length = myInput.nextDouble();
    System.out.println("宽:");
    double wide = myInput.nextDouble();

    RecTangle myRec = new RecTangle(length,wide);//创建一个长方形对象



    System.out.println("三角形周长:" + myTri.getCircumsta());
    System.out.println("三角形面积:" + myTri.getArea());

    System.out.println("长方形周长:" + myRec.getCircumsta());
    System.out.println("长方形面积:" + myRec.getArea());

    myInput.close();//资源回收
}

}
不知道和不和你的意。。。。。。


wojiushiwo945you
wojiushiwo945you   Ds   Rxr 2016.04.22 21:16
 其实不太认同你直接求答案的作法啊,多学一门语言,多一份机会啊。大学有时间专研一门语言,就有可能成为职业的呢。我就是大三自学Java的,然后毕业就从事Java开发,真心来说Java前景还是不错的啊。
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!