Answer to Question #312712 in Java | JSP | JSF for secret

Question #312712

Write an application for Furniture Company Sdn Bhd, the program determines the total price of a table. Ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany and prompt the user to enter the number of a table. The output is the name of the wood chosen as well as the price of the table. Pine table cost RM100, oak tables cost RM225, and mahogany tables cost RM310. If the user enters an invalid wood code, set the price to 0. 

Furniture Company Sdn Bhd also gives an appreciation for the member card holder with 6% off from the total price. The above price is exclude government tax RM 5.60.

Save the file as Furniture.java.      



1
Expert's answer
2022-03-16T14:48:48-0400
public class Furniture {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Choose the number of table:");
        System.out.println("1. Pine\n2. Oak\n3. Mahogany ");
        int number = Integer.parseInt(scanner.nextLine());

        System.out.println("Do you have the member card? 1.Yes  2.No");
        System.out.println("Choose the number:");
        boolean isMember = Integer.parseInt(scanner.nextLine()) == 1;
        double sum = 0;

        for(int i = 0; i < 2; i++) {
            switch(number) {
                case 1:
                    sum = 100;
                    break;
                case 2:
                    sum = 225;
                    break;
                case 3:
                    sum = 310;
                    break;
                default:
                    System.out.println("The wrong number. Please enter again.");
                    number = Integer.parseInt(scanner.nextLine());
            }
        }

        if (sum != 0) {
            if (isMember) {
                sum = sum - sum * 0.06;
            }
            System.out.println(sum + 5.60);
        } else {
            System.out.println("The table is not chosen.");
        }
    }
}

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