At 11:59 You can not use 'return maxArea( maxArea(shape 1 , shape 2) , shape 3) ' because maxArea(shape 1, shape 2) is returning 'Float' but the required parameter type for maxArea() function is "Shape".
@livebbott Жыл бұрын
Bhai kaha se padh raha hai poora course
@ananddangwal8424 Жыл бұрын
@@livebbott 'Kotlin newbie to pro' by Phillip lackner
@ananddangwal8424 Жыл бұрын
@@livebbott I also sometimes refer official documentation of Kotlin if I don't understand something. Baaki Chat Gpt toh hai hee doubts solve karne ke liye
@guy14074 жыл бұрын
time = 07:10 What you refer to you need to make "them" unique , is sometimes called the function "signature" meaning input parameters or output/return ones. For each implementation of the same function/method name, you must provide different input/output variable types or amount HTH
@dawiddebowski43464 жыл бұрын
Will your comment (12:04) really work? maxArea takes two Shapes and returns Double, and in the second calling of the function you'll pass Double and Shape.
@dawiddebowski43464 жыл бұрын
If the function returned Shape, it would have worked like that ;)
@PhilippLackner4 жыл бұрын
You're right, my bad, it should return shape in that case
@dawiddebowski43464 жыл бұрын
@@PhilippLackner okok, thanks, I thought for a moment, that I messed something up 😅😅
@TheImaginativeSachin2 жыл бұрын
it won't work i tried and failed😅
@str8busta2 жыл бұрын
Was confused how he got the menu in 7:58 For anyone wondering it's Ctrl + P (Parameter info)
@ekkawutemeelugsana70683 жыл бұрын
I think a much shorter way of this would be : Using Vararg I understand that this is for Constructor and Function overloading but this is a perfect use case for vararg right? Function overloading should be only be used when you have difference type of parameters isn't it? fun main() { val rect = Rectangle(5.0) val circle = Circle(3.0) val triangle = Triangle(7.0, 7.0, 7.0) println("The maximum area is ${maxArea(rect, circle, triangle)}") } fun maxArea(vararg shapes: Shape): Double { var maxArea = 0.0 shapes.forEach { when {it.area > maxArea -> { maxArea = it.area } } } return maxArea }
@ddnet_acclorite Жыл бұрын
Thanks, but i wrote a little bit easier solution: fun maxArea(vararg shapes: Shape): Double{ var maxArea = 0.0 for (i in shapes) { if (maxArea
@ahmadosama2652 Жыл бұрын
Well done bro!
@opeyemicoker9104 Жыл бұрын
cool, but he can't do that, because he hasn't talked about lambda functions
@opeyemicoker9104 Жыл бұрын
cool, I did it using extension function and overloading
@rashmikataria36424 жыл бұрын
why it is necessary to call primary constructor explicitly inside secondary constructor? and also, secondary const. can run without primary constructor or not?
@rashmikataria36424 жыл бұрын
@Jundran Jones thankyou so much budd!
@frzkh49563 жыл бұрын
In the maxarea() function you choose the type of the shape1 parameter (Shape), what does this mean, Can you explain more? please. thank you
@AniobiStanley Жыл бұрын
Shape is a class, and classes are blueprints for creating objects. The same way you could define parameter of type "Int" (since Int class is also a blueprint for creating objects), you can also define shape1 as an object of the Shape class.
@alh311 Жыл бұрын
Hello Philipp, My only question is how are you doing?
@Lapakias Жыл бұрын
Bro you are awesome!!!
@akanshakaushik46792 жыл бұрын
If I add secondary constructor: constructor(diameter:Int): this(diameter/2) in Circle class, I am seeing an error "there's a cycle in the delegation calls chain". Not understanding why getting it as the primary constructor accept Double
@AniobiStanley Жыл бұрын
In the "this()" part you have to define a relationship between the primary and the secondary constructors i.e. you should have something of the sort .toDouble
@gedalaarthika24976 ай бұрын
Rectangle area should be high right? area=25.
@AniobiStanley Жыл бұрын
fun printListItemsAlternating(list: List){ var i = 0 var j = list.size-1 var side = true //I used this variable to keep check of the side to pick from while (i
@bogite8734 Жыл бұрын
Homework ( I looked up how to do the repeat() function ) fun main() { alternating(listOf(1, 2, 3, 4, 5)) alternating(arrayOf(1, 2, 3, 4, 5)) } /* * [1, 2, 3, 4, 5] * 1, 5, 2, 4, 3 * * [1, 2, 3, 4] * 1, 4, 2, 3 * */ fun alternating (obj: List) { var step = 0 var direction = "up" repeat(obj.size) { if(direction == "up") { println(obj[0+step]) direction = "down" } else if (direction == "down") { println(obj[(obj.size-1)-step]) direction = "up" step += 1 } } } fun alternating (obj: Array) { var step = 0 var direction = "up" repeat(obj.size) { if(direction == "up") { println(obj[0+step]) direction = "down" } else if (direction == "down") { println(obj[(obj.size-1)-step]) direction = "up" step += 1 } } }
@name15662 жыл бұрын
i was thinking that huuhhhh.... i will end this series by 10 days but it will take atleast 20 days to complete amazing series on kotlin on yt
@AniobiStanley Жыл бұрын
//Using Two Pointers Technique fun printListItemsAlternating(list: List){ var i = 0 var j = list.size-1 var side = true //I used this variable to keep check of the side to pick from while (i
@designart49285 жыл бұрын
make more video bro,👍
@Dawking.5 жыл бұрын
Thanksss!!
@AniobiStanley Жыл бұрын
fun maxArea(shape1: Shape, shape2: Shape): Shape{ return if(shape1.area() > shape2.area()) shape1 else shape2 } fun maxArea(vararg shapes: Shape): Shape{ var max = 0.0 var maxShape : Shape = shapes[0] for (i in shapes){ if (i.area() > max) { max = i.area() maxShape = i } } return maxShape }
@jonievillejo6746 Жыл бұрын
fun main() { var myList = ListOf(1, 2, 3, 4, 5, 6, 7, 8) var myArray = arrayOf(1, 2, 3, 4, 5) reArranged(myList) reArranged(myArray) } fun reArranged(theList: List) { var low = 0 var high = theList.size - 1 var ctr = 0 println("List: " + theList) while ( low < high ) { println(theList[low]) println(theList[high]) low += 1 high -= 1 ctr += 1 } if (ctr != theList.count() && theList.count() % 2 != 0) println(theList[low]) } fun reArranged(theArray: Array) { var low = 0 var high = theArray.size - 1 var ctr = 0 println("Array: [${theArray.joinToString(", ")}]") while ( low < high ) { println(theArray[low]) println(theArray[high]) low += 1 high -= 1 ctr += 1 } if (ctr != theArray.count() && theArray.count() % 2 != 0) println(theArray[low]) } OUTPUT: List: [1, 2, 3, 4, 5, 6, 7, 8] 1 8 2 7 3 6 4 5 Array: [1, 2, 3, 4, 5] 1 5 2 4 3