Home > Back-end >  For a great god
For a great god

Time:04-27

Try programming the Rect rectangle class defined in A bag, in the class for the rectangular area, the method of Test classes defined in package B, in the main () function is called A package area method;

CodePudding user response:

Public class Rectangle {
Private float length;//long variables
Private float width;//wide variable
The public a Rectangle (float length, float width) {
This. Length=length;
This. Width=width;
}
Public float getGirth () {
Return (length + width) * 2;
}//o circumference method
Public float getArea () {
Return the length * width;
}//quadrature method
Public static void main (String [] args) {
Scanner in=new Scanner(System.in);//call input method
System. The out. Println (" please enter a long rectangular: ");
Float a=in nextFloat ();
System. The out. Println (" please enter the rectangular wide: ");
Float b=in nextFloat ();
System. The out. Println (" rectangular circumference is: "+ new Rectangle (a, b). GetGirth ());
System. The out. Println (" Rectangle area is: "+ new Rectangle (a, b). GetArea ());
}
}

CodePudding user response:

Directly in baidu, you bring out the main method in the test class
  • Related