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
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
char ch;
do {
System.out.print("1. for pine\n" +
"2. for oak\n" +
"3. for mahogany\n" +
"Enter: ");
int i = in.nextInt();
switch (i) {
case 1 -> {
System.out.println("Pine tables cost R 100");
}
case 2 -> {
System.out.println("Oak tables cost R 225");
}
case 3 -> {
System.out.println("Mahogany tables cost R 310");
}
default -> {
System.out.println("Input error! Tables cost R 0");
}
}
System.out.print("Do you want to repeat Y/N: ");
ch = (char) System.in.read();
} while (ch != 'N');
}
}
Comments
Leave a comment