+ 3
Kotlin End of Module Project 17
possible error? Sorry, but I'm not sure where to post this. In the end of module project Parking Fee, the test results seems to be wrong. In case 2, where the input is 42, the expected answer is 24 but I'm thinking it should be 26.5. Is the test flawed, or is it me with who is mistaken? 24 hours = $15 5 hours * $1.0 = $5 13 hours * $0.5 = $6.5 -------------------------------------- 42 hours = $26.5
14 Réponses
+ 7
Since the first 24 hours includes those more expensive first 5 hours, Simba's answer is correct. To get your $26.50, they would have specified a different price for the first day versus the others.
+ 3
For 42 hours, the bill should be
15*(42/24)+((42%24)*0.5) = 24.0
+ 1
fun main(args: Array<String>) {
var hours = readLine()!!.toInt()
var total: Double = 0.5
var first = 5
var day = 24
var x = hours - first
var z = hours - day
var y = x * total + first
var dayy = z * total + 15
if ( hours < 24){
println (y)
}
else {
println (dayy)
}
}
0
But after dividing by 24 for each full day, the first five hours of each day is$1.0
0
I have completed the course and modified my code to pass it, but the logic seems wrong.
0
It looks like there are two ways of looking at the problem: First is your solution, which is charging only $0.5 for every hour after %24 (which is not specifically expressed in the problem), or secondly, starting each day from scratch after %24 is applied.
In the real world, the second way is more profitable..😁, but the first way is more economical for the customer.
0
can samone help my in project25
0
shipping fee problem:
check if local or international.
if local(false):
if greater than 75
cost = 0
else
cost = order * 0.10
if international(true):
cost = order* 0.15
if cost greater than 50.0
cost = 50.0
0
I tried to write a branchless solution (no if-else statements). Not really for readability but only as a novelty to see if it could be done. Found out that Java and Kotlin does not automatically cast booleans into 1 or 0. Had to do a
bar = ? 1 : 0
Thinking back on being able to add booleans in Python and C and C++ implementation of booleans, I am curious on the design rationale (pros and cons) of such decisions...
0
thanks but international is. input?
0
international is true, local is false.
0
Better to find the solution on your own. But if you are really stuck, this is my solution.
It is basically nested if-else pattern.
outer if-else is:
if(international==true){
}else{
}
then you add your if-else for each section.
/*Solution*/
fun shippingCost(total: Double, international: Boolean): Double {
var fee: Double = 0.0
if(international==true){
if(total*0.15<50.0){
fee = total*0.15
}else{
fee = 50.0
}
}else{
if(total>75.0){
fee = 0.0
}else{
fee = total*0.10
}
return fee
}
0
thanks my frend. you are the best
0
Я отдельно считал для каждого случая. Все работает
fun main(args: Array<String>) {
var hours = readLine()!!.toInt()
var total: Double = 0.0
when{
hours >= 24 -> total = hours/24*15 + hours%24 * 0.5
hours <= 5 -> total = 0.0 + hours
hours < 24 -> total = 5.0 + (hours-5)/2.0
}
print(total)
}