Created
February 17, 2023 04:06
-
-
Save iamkingalvarado/3abaf9288b1e378a9c0cb60ea7c590e8 to your computer and use it in GitHub Desktop.
Class6.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.thesocialnetwork | |
/** | |
* 0. What is an object? | |
* A structure with properties and methods | |
* | |
* 1.- Inheritance | |
* 2.- Polymorphism | |
* 3.- Abstraction | |
* 4.- Encapsulation | |
* | |
* | |
* Electronic | |
* Device | |
* (brand, model, width, height, color) | |
* | |
* Mobile Device (cameras, battery) Appliance (kwh) | |
* | |
* Phone Tablet Washer Fridge Microwave | |
* +call +draw +wash +freeze +heat | |
* | |
*/ | |
enum class Brand { | |
Samsung, | |
Apple; | |
fun brandInLowerCase(): String { | |
return this.toString().lowercase() | |
} | |
} | |
enum class Color { | |
Black, | |
Yellow, | |
Purple | |
} | |
data class ElectronicDevice( | |
val brand: Brand, | |
val model: String, | |
val width: Float, | |
val height: Float, | |
val color: Color | |
) | |
fun main() { | |
val tv = ElectronicDevice( | |
brand = Brand.Samsung, | |
model = "HD4K95J", | |
width = 180F, | |
height = 90F, | |
color = Color.Black | |
) | |
val iPhone = ElectronicDevice( | |
brand = Brand.Apple, | |
model = "iPhone 14 Pro Max", | |
width = 8F, | |
height = 12F, | |
color = Color.Purple | |
) | |
val iPad = ElectronicDevice( | |
brand = Brand.Apple, | |
model = "iPad Pro", | |
width = 16F, | |
height = 10F, | |
color = Color.Yellow | |
) | |
println(tv) | |
println(iPhone) | |
if (tv.brand == iPhone.brand) { | |
println("Device model ${tv.model} and ${iPhone.model} are the same brand") | |
} | |
if (iPhone.brand == iPad.brand) { | |
println("Device model ${iPhone.model} and ${iPad.model} are the same brand") | |
} | |
val dog = Dog( | |
DogBreed.Golden, | |
"Firulais", | |
"brown", | |
true, | |
10F, | |
20F, | |
1 | |
) | |
println(dog) | |
println(Brand.Samsung.brandInLowerCase()) | |
val streamPost = Post( | |
PostType.Stream, | |
arrayListOf( | |
Reactions.Hearth, | |
Reactions.Like, | |
Reactions.Hearth, | |
Reactions.Like, | |
Reactions.Dislike, | |
Reactions.Hearth, | |
Reactions.Like, | |
Reactions.Hearth, | |
Reactions.Like, | |
Reactions.Dislike | |
) | |
) | |
println(streamPost) | |
} | |
/** Declare a data class Post | |
* and with a property called "type" of an enum with 3 possible values | |
*/ | |
data class Dog( | |
val breed: DogBreed, | |
val name: String, | |
val color: String, | |
var isHungry: Boolean, | |
var height: Float, | |
var width: Float, | |
var age: Int | |
) | |
enum class DogBreed { | |
Golden | |
} | |
enum class PostType { | |
Link, | |
Stream, | |
Suggestion | |
} | |
enum class Reactions { | |
Like, | |
Hearth, | |
Dislike | |
} | |
data class Post( | |
val type: PostType, | |
val reactions: ArrayList<Reactions> | |
) | |
/** | |
* 2 object of class Human(properties), array of pets, Pet (type, name, age) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment