- 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
5 Answers
+ 1
Can you solve it with pen and paper?
+ 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
}
}
}
0
You must now how to solve it, before coding. Orherwise itâs impossible to code...
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))
}
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))
}