Advertisement
fannyxmikasa

area of square

Nov 10th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.85 KB | None | 0 0
  1. import java.util.Scanner
  2. class Square(side: Int){
  3.     private var sideLength: Int = side //take the parameter of class square
  4.     fun getSideLength() = "The length of the side is: $sideLength"
  5.  
  6.     fun computePerimeter(sideLen: Int, nSides: Int): Int {
  7.         return sideLen * nSides
  8.     }
  9.     fun computeArea(sideLen: Int): Int {
  10.         return sideLen * sideLen
  11.     }
  12. }
  13. fun main(){
  14.     val read = Scanner(System.`in`)
  15.     print("Enter the side (m) of the Square : ")
  16.     val sideM = read.nextInt()
  17.     val call = Square(sideM) //create object
  18.  
  19.     println("Creating the square object...")
  20.     Thread.sleep(3500) //make it looks like creating a real object.
  21.     println(call.getSideLength())
  22.     println("The perimeter of the square is: ${call.computePerimeter(sideM, 4)}")
  23.     println("The area of the square is: ${call.computeArea(sideM)}m^2")
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement