Home > Back-end >  Turn to for help
Turn to for help

Time:09-17

Write programs, define a class square (square), the member data and function requirements as follows,
Data members: float radius side length (representative),
Constructor: square (float d), the data members of the radius value is set to the value of the parameter d
A member function: float generating (), calculate the perimeter (the perimeter of the square of L=4 * r), and the class defined in the main function of an object, call the function test,


What a great god can help thank you very much

CodePudding user response:

 
Public class Square {
//a member variable
Private float radius;

//the constructor
Square (float, d) {
Enclosing the radius=d;
}

//calculate the perimeter function
Float generating () {
Return the radius * 4;
}

Public static void main (String [] args) {
Square Square=new Square (5);
System. The out. Println (" is the perimeter of the square is: "+ square. Generating ());

}

}



CodePudding user response:

Thank you thank you
  • Related