- 1

# [SOLVED] Parking Fee(Kotlin) - I need help anyone.

Case 1 and 2 are successful but I don't know what is wrong. Please help. Here is my attempt:- https://code.sololearn.com/c0spe4fMPNll/?ref=app

21st Feb 2021, 8:51 AM
~SonnyEzeoke~ + 3
There are a number of problems with your logic. 48 hrs returns 27 instead of 30 4 hrs returns 5 instead of 4. Read through the description again to fully understand the requirements. Each day (24hr) charge 15 + .5 for each extra hr, so 50 hrs = 31 if not a full day (24hr), then charge 1 for the first 5 hrs & .5 for each hour after. 8 hrs = 6.5 4 hrs = 4
21st Feb 2021, 9:04 AM
Rik Wittkopp + 22
Here my code for that problem : fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours <= 5){ var result: Double = hours * 1.0 total = result } else if (hours > 5 && hours < 24){ var result: Double = (hours - 5.0) * 0.5 total = 5.0 + result } else { var result: Double = (15.0 * Math.floor(hours /24.0)) + ((hours% 24.0)*0.5) total = result } println(total) }
24th Feb 2021, 4:41 AM
Ihsan + 11
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var day = hours /24 if(hours > 24){ total = 15*day + (hours%24)*0.5 }else if(hours > 5 && hours < 24){ total = 5 + (hours - 5)*0.5 }else if(hours > 0 && hours < 5) { total = hours * 1.0 } else{ total =1.0 } println(total) }
12th Mar 2021, 7:42 AM
Ramshek Rana + 3
This is mine. I hope this can help you fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var day : Int = hours/24 var addhours : Int = hours%24 total = when { hours >5 && hours <24 -> 5.0+(hours-5)*0.5 hours >= 24 -> (addhours*0.5) + (day*15) else -> hours*1.0 } println(total) }
6th Mar 2021, 2:09 PM
M. Huda Saputra + 3
Just want to share my solution: fun main(args: Array<String>) { var hours = readLine()!!.toDouble() var total: Double = 0.0 if(hours <= 5) { total = hours *1.0 } else if (hours > 5 && hours < 24) { total = 5.0 + (hours - 5) * 0.5 } else { total = Math.floor(hours/24) * 15.0 + (hours%24) * 0.5 } println(total) }
30th Dec 2022, 7:36 AM
Mohamed Maooshe + 2
Here is the most elegant solution I can figure out: //Created by Jacob Lynn 12/6/2021 fun main(args: Array<String>) { var hours = 48 //We do not need to initialize total as it will be initialized the first time it is utilized, however since I am incrementing rem I need to initialize it at the beginning var total: Double var rem: Double = 0.0 /*The problem can be focused on a set of conditions that if one is satisfied the result can be found.*/ //First we need to find how periods of 24 hours the car was parked, then with the remaining hours multiple by 50 cents. if (hours >= 24){ rem = Math.floor(hours.toDouble()/24) * 15 hours = hours%24 total = rem + (hours*0.5) println("End of 24 IF statement subtotal:\$rem hours:\$hours") } //Very straight forward, if not 24 check if more than 5. Charging a block amount for the first 5 then .5 for any remaining hours else if (hours >= 5){ rem+= 5 hours-= 5 total = rem + (hours*0.5) println("End of 5 IF statement subtotal:\$rem hours:\$hours total:\$total") } else { total = rem + (hours*1) } //The println can be a powerful debugging tool println("subtotal:\$rem hours:\$hours total:\$total") } Actual Code Below ---------------------------------------------------------------- fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double var rem: Double = 0.0 if (hours >= 24){ rem = Math.floor(hours.toDouble()/24) * 15 hours = hours%24 total = rem + (hours*0.5) } else if (hours >= 5){ rem+= 5 hours-= 5 total = rem + (hours*0.5) } else { total = rem + (hours*1) } println(total) }
6th Dec 2021, 4:05 PM
Jacob Lynn + 1
if hrs > 24 Use hrs / 24 to get your days Use hrs %24 to get your residual else hrs < 24 if hrs > 5 (hrs -5)* 0.5 +5 else hrs *1
21st Feb 2021, 6:10 PM
Rik Wittkopp + 1
Here is my code! fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours <= 5 ) { total = hours.toDouble() } else if(hours in 6..23) { total = ((hours-5)* 0.5 + 5).toDouble() }else { total = (((hours/24) * 15) + ((hours%24)*0.5)).toDouble() } println(total) }
10th Aug 2022, 3:37 AM
Zendy Kurnia 0
13th Mar 2021, 1:14 PM
ARAVIND RAVINDRAN 0
fun main() { val hours = readLine()!!.toInt() var total: Double = 0.0 val day = hours /24 if(hours > 24){ total = 15*day + (hours%24)*0.5 }else if(hours in 6..23){ total = 5 + (hours - 5)*0.5 }else { if((hours > 0) && (hours < 5)) { total = hours * 1.0 } else{ total =1.0 } } println(total) }
29th Jul 2021, 10:09 AM
Aashik J Krishnan 0
fun main(args: Array<String>) { var years = readLine()!!.toInt() val days = 365 var litres = 15 var result = years * days * litres println(result) } Here is my water consumption code, It basically calculates the number of litres per day in a given number of years
15th Sep 2021, 10:35 AM
Bhekumuzi Khumalo 0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours in 1..5 || hours in 6..23 || hours == 24){ when(hours){ in 1..5 -> total = hours * 1.0 in 6..23 -> total = ((hours-5)*0.5)+5.0 24 -> total = 15.0 } }else if(hours%24 == 0){ total = 15.0 + hours%24 * 15.0 }else if (hours>24){ total = (hours/24*15)+(hours%24*0.5) } println(total) }
20th Oct 2021, 9:08 AM
Constantine Kulzhinskiy 0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var days = hours / 24 total = when { hours >= 24 -> (15.0 * days) + 0.5 * (hours % 24) hours <= 5 -> 1.0 * hours else -> 5.0 + 0.5 * (hours - 5.0) } println(total) }
26th Dec 2021, 11:50 AM
Ricardo Mello 0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours < 24.0) { total = 5.0 + (hours - 5)*0.5 } else { total = 15.0 * (hours/24) + (hours%24)*0.5 } println(total) } I have no idea why it does not work for case 4
26th Dec 2021, 10:53 PM
Piotr Jeszkie 0
Oh. I did not check how it works for less than 5 🤦🏽‍♂️
26th Dec 2021, 10:56 PM
Piotr Jeszkie 0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours <= 5){ total = hours * 1.0 } else if (hours > 5 && hours < 24){ total = (hours - 5.0) * 0.5 + 5.0 } else { total = (15.0 * Math.floor(hours /24.0)) + ((hours% 24.0)*0.5) } println(total) }
15th Jan 2022, 7:08 PM
Francis Njeri 0
This is my version (the key for this one is really the modulo operator to ensure the full day fees are properly being calculated): fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var total1: Double = 0.0 var total2: Double = 0.0 var total3: Double = 0.0 var total4: Double = 0.0 var days = hours / 24 var x = 0 if (hours in 1..5) { total1 = hours.toDouble() println(total1) } else if (hours <= 23) { total2 = ((hours - 5) * 0.5.toDouble()) println(total2 + 5) } else if (hours > 23) { x = hours % 24 total3 = (15 * days) + (0.5 * x) println(total3) } }
28th Jan 2022, 7:09 PM
Matthew Mulvey
0
fun main() { var hours = readLine()!!.toInt() var total: Double = 0.0 if(hours>23){ var days:Int = hours/24 //for the integer part var extraHours = hours-(24*days) total = (days*15)+(extraHours*0.5) }else if(hours>4 && hours<24){ var extraHours = hours-5 total = 5+(extraHours*0.5) }else{ total = hours.toDouble() } println(total) }
20th Feb 2022, 10:52 AM
Aarón Chávez
0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 if (hours<=5) {total = 1.0*hours} else if (hours>5 && hours<24) {total = 5 + 0.5*(hours-5)} else if (hours>24 && hours/24!=0) {total = 15.0*(hours/24) + 0.5*(hours-(24*(hours/24)))} println(total) } Hmm i used math to solve , anyway it's take me 3 hours to think a way how to calculate this
14th Jul 2022, 12:13 PM
Vu Ba Luc 0
fun main(args: Array<String>) { var hours = readLine()!!.toInt() var total: Double = 0.0 var day = hours /24 if(hours > 24){ total = 15*day + (hours%24)*0.5 }else if(hours > 5 && hours < 24){ total = 5 + (hours - 5)*0.5 }else if(hours > 0 && hours < 5) { total = hours * 1.0 } else{ total =1.0 } println(total) } Try this🙂
26th Aug 2022, 8:32 AM 