1A) Write an application for a furniture company; the program determines the pri
ID: 3622376 • Letter: 1
Question
1A)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 for the wood chosen as well as the price of the table. Pine tables cost $100, oak tables cost $225, and mahogany tables cost $310. If the user enters an invalid wood code, set the price to 0. Save your file as Furniture.java.
1B)
Add a prompt to the above application to ask the user to specify a (1) large or (2) small table. Add $35 to the price of any large table. Save your file as Furniture2.java.
Explanation / Answer
This program will PWN your classmates; import java.util.*; public class Furniture { public static void main(String[] args) { int tree = 0; Scanner scan = new Scanner(System.in); System.out.println("Enter 1 for pine 2 for oak 3 for mahogany"); try { tree = scan.nextInt(); } catch(Exception e) { System.out.println("Invalid input. Only numbers are accepted"); } int cost = 0; if(tree == 1) cost = 100; else if(tree == 2) cost = 225; else if(tree == 3) cost = 310; else cost = 0; String tab = ""; if(tree == 1) tab = "Pine"; else if(tree == 2) tab = "Oak"; else if(tree == 3) tab = "Mahogany"; System.out.println("This " + tab + " table will cost you $" + cost); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.