Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner
- class Square(side: Int){
- private var sideLength: Int = side //take the parameter of class square
- fun getSideLength() = "The length of the side is: $sideLength"
- fun computePerimeter(sideLen: Int, nSides: Int): Int {
- return sideLen * nSides
- }
- fun computeArea(sideLen: Int): Int {
- return sideLen * sideLen
- }
- }
- fun main(){
- val read = Scanner(System.`in`)
- print("Enter the side (m) of the Square : ")
- val sideM = read.nextInt()
- val call = Square(sideM) //create object
- println("Creating the square object...")
- Thread.sleep(3500) //make it looks like creating a real object.
- println(call.getSideLength())
- println("The perimeter of the square is: ${call.computePerimeter(sideM, 4)}")
- println("The area of the square is: ${call.computeArea(sideM)}m^2")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement