Please help, trying to get this code to work and everything works up until the a
ID: 3651443 • Letter: P
Question
Please help, trying to get this code to work and everything works up until the adding of the chairs and the shipping. What am I doing wrong?! //import scanner import java.util.Scanner; public class Furniture { //create main method within the class public static void main(String[] args) { //declare variables and strings int price; int type; int chairs; String name; //scanner object Scanner input=new Scanner(System.in); //Tree type System.out.print("Table types 1.Pine 2.Oak 3.Mahogany "); System.out.println("Please enter the type of wood:"); type=input.nextInt(); //if/else statements 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"; } //output System.out.println(name+" table will cost $" +price); //add chairs System.out.println("Would you like to buy four chairs? Enter (yes or no)"); chairs=input.nextLine(); if(response.equals("yes")) { price+=250; name +=" and four chairs"; } //Shipping System.out.println("Does your order need to be shipped out of state? Enter (yes or no)"); shipping=input.nextLine(); if(response.equals("yes")) { price+=150; } else { price+=25; } } }Explanation / Answer
Please rate...
program Furniture.java
==================================================
//import scanner
import java.util.Scanner;
public class Furniture
{
//create main method within the class
public static void main(String[] args)
{
//declare variables and strings
int price;
int type;
String chairs;
String name;
//scanner object
Scanner input=new Scanner(System.in);
Scanner input1=new Scanner(System.in);
Scanner input2=new Scanner(System.in);
//Tree type
System.out.print("Table types 1.Pine 2.Oak 3.Mahogany ");
System.out.println("Please enter the type of wood:");
type=input.nextInt();
//if/else statements
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"; }
//output
System.out.println(name+" table will cost $" +price);
//add chairs
System.out.println("Would you like to buy four chairs? Enter (yes or no)");
chairs=input1.nextLine();
if(chairs.equals("yes")) { price+=250; name +=" and four chairs"; }
//Shipping
System.out.println("Does your order need to be shipped out of state? Enter (yes or no)");
String shipping=input2.nextLine();
if(shipping.equals("yes")) { price+=150; }
else { price+=25; }
System.out.println("Total cost is: "+price);
}
}
======================================================
Sample output: