Answer to Question #303316 in Java | JSP | JSF for Anshuman

Question #303316

A showroom announces the discount (on the total cost of the items purchased) as per slabs provided below:


Total Cost and Discount in percentage :

Less than Rs. 3000 = No Discount

Rs. 3001 to Rs. 6000 = 10%

Rs. 6001 to Rs.10000 = 25%

Above Rs. 10,000 = 40%


Write a program to input the total cost from the user in main function and calculate and display the total amount to be paid by the customer after availing the discount. Implement the program using Class and Object.


1
Expert's answer
2022-02-27T03:55:13-0500
import java.util.Scanner;

public class Main {
    private int totalCost;

    public Main(int totalCost) {
        this.totalCost = totalCost;
    }

    public double getTotalAmount() {
        if (totalCost <= 3000) {
            return totalCost;
        } else if (totalCost <= 6000) {
            return totalCost * 0.9;
        } else if (totalCost <= 10000) {
            return totalCost * 0.75;
        } else {
            return totalCost * 0.6;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the total cost:");
        Main main = new Main(in.nextInt());
        System.out.println("The total amount to be paid: " + main.getTotalAmount());
    }
}

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