Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

jump to level 1 type the programs output public class costcalculator { …

Question

jump to level 1
type the programs output
public class costcalculator {
public static int calculatecost(int age, int units) {
int cost;
if (age >= 18 && age < 28) {
if (units > 1) {
cost = (units - 1) * 400;
}
else {
cost = 0;
}
}
else {
if (units < 17) {
cost = units * 400;
}
else {
cost = (units - 16) * 300 + 500;
}
}
return cost;
}
public static void main(string args) {
int costreturned = calculatecost(19, 5);
system.out.println(costreturned);
}
}

Explanation:

Step1: Analyze the age condition

The age is 19, which satisfies \(18\leq age < 28\).

Step2: Analyze the units condition

The units is 5, which satisfies \(units>1\).

Step3: Calculate the cost

According to the formula \(cost=(units - 1)\times400\), substitute \(units = 5\) into it: \(cost=(5 - 1)\times400=4\times400 = 1600\).

Answer:

1600