?? righttriangle.java
字號:
import java.util.Scanner ;
import java.lang.Math ;
public class RightTriangle {
private double base = 0.0 ;
private double height = 0.0 ;
RightTriangle() {
base = askForDoubleVersion2("Enter base of triangle: ") ;
height = askForDoubleVersion2("Enter height of triangle: ") ;
}
RightTriangle (double base, double height) {
setBase (base) ;
setHeight (height) ;
}
public static double askForDoubleVersion2(String message) {
Scanner keyboard ;
double aValue ;
keyboard = new Scanner(System.in) ;
System.out.print(message) ;
aValue = keyboard.nextDouble() ;
return aValue ;
}
public double getBase() {
return base ;
}
public double getHeight() {
return height ;
}
public boolean isValid() {
boolean returnValue = false ;
if ((base > 0.0) && (height > 0.0))
returnValue = true ;
return returnValue ;
}
public void setBase(double inBase) {
if (inBase > 0)
base = inBase ;
}
public void setHeight(double inHeight) {
if (inHeight > 0)
height = inHeight ;
}
double returnArea() {
double area ;
area = (base * height) * 0.5 ;
return area ;
}
double returnPerimeter() {
double perimeter ;
double hypotenuse ;
hypotenuse = Math.sqrt((base * base) + (height * height)) ;
perimeter = base + height + hypotenuse ;
return perimeter ;
}
}
public class RightTriangleMain {
public static int compareTriangles(RightTriangle left, RightTriangle right) {
int returnValue = 0 ;
if ( (left.getBase() == right.getBase() ) && (left.getHeight() == right.getHeight() ) )
returnValue = 1 ;
return returnValue ;
}
public static void main(String[] args) {
RightTriangle left = null ;
RightTriangle right = null ;
int comparisonResult = -1 ;
left = new RightTriangle() ;
if (left.isValid() ) {
right = new RightTriangle(4.0,5.0) ;
if (right.isValid() ) {
if ( (comparisonResult = compareTriangles(left,right)) == 1)
System.out.println("Triangles are equal") ;
else
System.out.println("Triangles are not equal") ;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -