In: Computer Science
1. Assume that total has already been declared as a double variable and received a value, and discountRate has been declared as a double variable, you don’t need to declare them again. You write one if statement (not multiple individual if statements) for following requirements.
when total is less than 50, set discountRate to 0.0;
when total is equal to or greater than 50 and less than 100, set discountRate to 0.05;
when total is equal to or greater than 100, set discountRate to 0.1.
in java
Java code:
public class Main
{
public static void main(String[] args){
//initializing sample total
and discountRate(only for you understanding)
double total=50,discountRate;
//checking if total is greater than
or equal to 100
if(total>=100)
//setting discountRate as 0.1
discountRate=0.1;
//checking if total is greater than
or equal to 50
else if(total>=50)
//setting discountRate as
0.05
discountRate=0.05;
else
//setting discountRate as 0.0
discountRate=0.0;
//printing discountRate(only for
you understanding)
System.out.println("discountRate="+discountRate);
}
}
Screenshot:
Output: