Suppose that sale and bonus are double variables. Write an if...else statement that assigns a value to bonus as follows: If sale is greater than $20,000, the value assigned to bonus is 0.10; If sale is greater than $10,000 and less than or equal to $20,000, the value assigned to bonus is 0.05; otherwise, the value assigned to bonus is 0.
public class Q184589 {
public static void main(String[] args) {
//sale and bonus are double variables.
double sale=25000;
double bonus;
//Write an if...else statement that assigns a value to bonus as follows:
//If sale is greater than $20,000, the value assigned to bonus is 0.10;
if(sale>20000){
bonus=0.10;
}
//If sale is greater than $10,000 and less than or equal to $20,000, the
//value assigned to bonus is 0.05;
else if(sale>10000 && sale<=20000){
bonus=0.05;
}
// otherwise, the value assigned to bonus is 0.
else{
bonus=0.0;
}
System.out.println("The bonus is: "+bonus);
}
}
Comments
Leave a comment