编写一个称作hypotenuse的Java程序,继承自下图表示的三角形类,并能从已知直角三角形的直角边计算最长边。
该类实现了一个接口 calc
Interface calc{
     abstract float hypotenuseLong();

解决方案 »

  1.   

    不知道,你要的是不是这个:
    package com.test;public class Hypotenuse implements Calc {  private float a; //直边1
      private float b; //直边2
      
      public Hypotenuse(float a,float b){
        this.a =a;
        this.b=b;
      }
      public float hypotenuseLong() {   
        
        return (new Float(Math.sqrt(a*a+b*b))).floatValue();
      }
      public float getA() {
        return a;
      }
     
      public void setA(float a) {
        this.a = a;
      }
     
      public float getB() {
        return b;
      }
      
      public void setB(float b) {
        this.b = b;
      }
      public static void  main(String[] arg){
        Hypotenuse hypotenuse=new Hypotenuse(3,4);
        System.out.println(hypotenuse.hypotenuseLong());
      }
    }