Answer to Question #268014 in Java | JSP | JSF for Candy

Question #268014

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


1
Expert's answer
2021-11-21T04:49:16-0500
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+"%");
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS