29.7k views
23 votes
I need help with this program. I need code for this . Java if statements Determine the amount of discount a person should receive. If the bill is more than 2000, then the person should receive a 15% discount. If the bill is 2000 dollars or less, the person does not receive a discount of any kind. Sample Data: 500 2500 4000 333.33 95874.2154 Sample Output= Enter the original bill amount :: 500 Bill after discount :: 500.00 Enter the original bill amount :: 2500 Bill after discount :: 2125.00 Enter the original bill amount :: 4000 Bill after discount :: 3400.00 Enter the original bill amount :: 333.333 Bill after discount :: 333.33 Enter the original bill amount :: 95874.2154 Bill after discount :: 81493.08

User Hsh
by
3.0k points

1 Answer

4 votes

Answer:

The program in Java is as follows:

import java.util.Scanner;

public class MyClass {

public static void main(String args[]) {

double bill;

Scanner input = new Scanner(System.in);

System.out.print("Enter the original bill amount : ");

bill = input.nextDouble();

if(bill>2000){

bill-=0.15*bill;

}

System.out.println("Bill after discount: " + bill);

}

}

Step-by-step explanation:

This declares bill as double

double bill;

This lets the program accept input

Scanner input = new Scanner(System.in);

This prompts user for the original bill amount

System.out.print("Enter the original bill amount : ");

This gets the bill from the user

bill = input.nextDouble();

This checks if the input bill is greater than 2000

if(bill>2000){

If yes, the bill after discount is calculated as follows:

bill-=0.15*bill;

}

This prints the bill after discount

System.out.println("Bill after discount: " + bill);

User Astreal
by
3.2k points