Answer to Question #312072 in Java | JSP | JSF for Mia

Question #312072

write an application for a furniture company; the program determines the price of a table. ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany. the output is the name of the wood chosen as well as the price of the table. pine tables cost r 100, oak tables cost r 225, and mahogany tables cost r 310. if the user enters an invalid wood code, set the price to 0 and allow the user to select an option up to 3 times . save the file as furniture.java. marks allocation 1. presentation of a menu - 10 select an option 1. for pine 2. for oak 3. for mahogany 2. use of a loop - 10 3. use of an if statement/ switch - 10 4. correct output "-10"


1
Expert's answer
2022-03-16T14:49:03-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());
        int 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) {
            System.out.println(sum);
        } 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