RexyBadDog

Kotlin ClassTask_2020_06_24 (Simple Classes)

Jun 24th, 2020 (edited)
2,130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.75 KB | None | 0 0
  1. package com.hackeru.mykotlinapp
  2. //targil 26/06/2020:
  3. class ClassTask_2020_06_24 {
  4.     fun main() {
  5.         val nerd = ComputerTeacher("zeev", "mendeli")
  6.         val pewDiePie = Gamer("Felix", "Arvid")
  7.         val myMan = BusinessMan("steve", "jobs")
  8.         nerd.talk()
  9.         nerd.walk()
  10.         nerd.eat()
  11.         pewDiePie.playGame()
  12.         pewDiePie.talk()
  13.         pewDiePie.walk()
  14.         pewDiePie.eat()
  15.         myMan.makeBusiness()
  16.         myMan.talk()
  17.         myMan.walk()
  18.         myMan.eat()
  19.     }
  20. }
  21.  
  22. open class Person(val firstName: String, val lastName: String) {
  23.     fun talk() {
  24.         println("$firstName $lastName saying: \"blah blah blah...\"")
  25.     }
  26.  
  27.     open fun walk() {
  28.         println("$firstName $lastName is walking")
  29.     }
  30.  
  31.     fun eat() {
  32.         println("$firstName $lastName is eating")
  33.     }
  34. }
  35.  
  36. class ComputerTeacher : Person {
  37.     var subject: String = "Computers"
  38.  
  39.     constructor (firstName: String, lastName: String) : super(firstName, lastName) {
  40.         this.subject = subject
  41.     }
  42.  
  43.     fun teachComputer() {
  44.         println("$subject class is thought by teacher: $firstName $lastName")
  45.     }
  46. }
  47.  
  48. class Gamer : Person {
  49.     var subject: String = "Gamer"
  50.  
  51.     constructor (firstName: String, lastName: String) : super(firstName, lastName) {}
  52.  
  53.     fun playGame() {
  54.         println("$firstName $lastName is a $subject playing Call of Duty III: Modern Warfare!")
  55.     }
  56. }
  57.  
  58. class BusinessMan : Person {
  59.     var subject: String = "BusinessMan"
  60.  
  61.     constructor (firstName: String, lastName: String) : super(firstName, lastName) {}
  62.  
  63.     fun makeBusiness() {
  64.         println("$firstName $lastName is a $subject making tons of $$$$$$$")
  65.     }
  66.     override fun walk() {
  67.         println("$firstName $lastName dont need to walk, he has BMW!")
  68.     }
  69. }
Add Comment
Please, Sign In to add comment