Write an if-else statement that outputs the discount
The communication company offers a discount to customer who is taking at least 12-
month plan. The discount arrangement is as below: Business customer:
12/18 months 15% discount
24 months 25% discount
Non-Business customer
12/18 months 10% discount
24 months 15% discount
The variables customerType is of type char, period is of type int and discount is of
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("Business customer? (Y/N): ");
char customerType=in.next().charAt(0);
System.out.print("Enter period: ");
int period=in.nextInt();
int discount=0;
if (customerType=='Y'){
if(period>=12 && period<=18){
discount=15;
}
else if(period==24){
discount=25;
}
}
else if (customerType=='N'){
if(period>=12 && period<=18){
discount=10;
}
else if(period==24){
discount=15;
}
}
else{
System.out.println("Invalid input");
}
System.out.println("Discount = "+discount+"%");
}
}
Comments
Leave a comment