Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having trouble with this code. In addition to what is already set, I need t

ID: 3651195 • Letter: I

Question

I am having trouble with this code. In addition to what is already set, I need to 1.Ask the user if they would like to purchase four chairs to go with their new table. 2. If so, add an additional $250 to the grand total. Below is what I have so far: import java.util.Scanner; public class Furniture { public static void main(String[] args) { int type; int price; int chairs=0; int yes=250; int no=0; String name; Scanner input= new Scanner(System.in); System.out.print("Table types 1.Pine 2.Oak 3.Mahogany "); System.out.println("Please enter your tree type:"); type=input.nextInt(); if(type==1) { name="Pine"; price=100; } else if(type==2) { name="Oak"; price=225; } else if(type==3) { name="Mahogany"; price=310; } else { price=0; name="Invalid"; } System.out.println(name+" table price $"+price); System.out.println("Would you like to buy four chairs? Enter (yes or no)"); } }

Explanation / Answer

You just need to add the following: String response=input.nextLine(); if(response.equals("yes")) { price+=250; } It gets the user's answer, checks if it is "yes", and if so will increase the price that the user has to pay. You may also want to do the following inside the if statement: name += " and four chairs"; That will concatenate " and four chairs to the end of the name.