Help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Help me

You are working on a eCommerce website and need to make a shipping cost calculator based on the order amount. The store uses the following cost structure: For orders in the US: - $75+ orders have free shipping - orders less than $75 have a shipping fee of 10% of the total order amount. For international orders, there is a 15% shipping fee, with a maximum of $50. This means that the maximum shipping fee for an international order is $50. You need to complete the given shippingCost() function, which takes the order amount and a Boolean indicating whether the order is international or not, and returns the shipping cost for that order. The return amount should be a Double. Sample Input: 140.0 true Sample Output: 21.0

30th Mar 2021, 7:07 PM
Robet Filipus Sinaga
Robet Filipus Sinaga - avatar
5 Answers
+ 1
Can you solve it with pen and paper?
30th Mar 2021, 7:20 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
fun shippingCost(amount: Double, international: Boolean): Double { if(amount >= 75 && international!=true){ return 0.0 } else if(amount < 75 && international!=true){ return 0.1*amount } else{ if ((0.15*amount)>50){ return 50.0 } else { return 0.15*amount } } }
16th Jul 2021, 9:18 PM
Skander THABET
Skander THABET - avatar
0
You must now how to solve it, before coding. Orherwise it’s impossible to code...
31st Mar 2021, 12:26 PM
Per Bratthammar
Per Bratthammar - avatar
0
fun shippingCost(amount: Double, international: Boolean): Double { if(amount>=1 && amount<=74 && international == false ) { return amount*0.10 } else if ( amount>=75 && international == false ) { return amount*0.0 } else if ( international == true && (amount/15)<50 ) { return amount*0.15 } else if ( international == true && (amount/15)>=50 ) { return 50.0 } else { println(" try again "); return 0.0 } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total, international)) }
7th May 2021, 3:04 PM
SAIKIRAN KOYYEDA
SAIKIRAN KOYYEDA - avatar
0
fun shippingCost(amount: Double, international: Boolean): Double { if (international == false) { if (amount >= 75.0) { return 0.0 } else { return 0.1*amount } } else { var tax = 0.15*amount if (tax > 50.0) { tax = 50.0 } return tax } } fun main(args: Array<String>) { val total = readLine()!!.toDouble() val international = readLine()!!.toBoolean() println(shippingCost(total,international)) }
2nd May 2022, 3:23 PM
BhanuTejaswini. Seshapalli