QUESTION IMAGE
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);
}
}
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\).
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
1600