Created
December 16, 2011 02:08
-
-
Save takuma7/1484092 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PlaneFigure{ | |
public static final String TYPE="plane figure"; | |
public float getArea(float base, float height); | |
} | |
class Figure{ | |
String type="figure"; | |
public String getType(){ | |
return type; | |
} | |
} | |
class Triangle extends Figure implements PlaneFigure{ | |
String figureName ="triangle"; | |
public String getFigureName(){ | |
return figureName; | |
} | |
public float getArea(float base, float height){ | |
float area = base * height/2; | |
return area; | |
} | |
} | |
class Rectangle extends Figure implements PlaneFigure{ | |
String figureName="rectangle"; | |
public String getFigureName(){ | |
return figureName; | |
} | |
public float getArea(float base, float height){ | |
float area = base*height; | |
return area; | |
} | |
} | |
class Test{ | |
public static void main(String[] args){ | |
PlaneFigure figure1=new Triangle(); | |
PlaneFigure figure2=new Rectangle(); | |
float area1 = figure1.getArea(10.0f, 12.0f); | |
System.out.println("the area of figure1 is " + area1); | |
float area2 = figure2.getArea(10.0f, 12.0f); | |
System.out.println("the area of figure2 is " + area2); | |
System.out.println("figure1 is " + figure1.TYPE); | |
System.out.println(((Triangle)figure1).getFigureName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment