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
Select an option
1. for pine
2. for oak
3. for mahogany
2. use of a loop
3. Use of an if statement/ switch
4. correct output
import java.util.*;
class Furniture{
static double DeterminePriceOfTable(int wood) {
if (wood == 1)
return 100;
if (wood == 2)
return 225;
if (wood == 3)
return 310;
return 0;
}
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please select a wood:");
System.out.println("1. Pine");
System.out.println("2. Oak");
System.out.println("3. Mahogany");
System.out.print("Your choice: ");
int choice = keyboard.nextInt();
System.out.println();
if (choice >= 1 && choice <= 3) {
if (choice == 1)
System.out.println("Wood: Pine");
else if (choice == 2)
System.out.println("Wood: Oak");
else if (choice == 3)
System.out.println("Wood: Mahogany");
} else
System.out.println("Invalid wood code");
double tablePrice = DeterminePriceOfTable(choice);
System.out.println("Price of the table: $" + tablePrice);
keyboard.close();
}
}
Comments
Leave a comment