This has been answered once, but I\'m having issues getting the answer to work r
ID: 3540821 • Letter: T
Question
This has been answered once, but I'm having issues getting the answer to work right. I have this code going, but I also need to be able to add the ablility to ask the user if they would like to purchase four chairs to go with their new table, and if so, add an additional $250 to the grand total.
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
import java.util.Scanner;
public class Furniture
{
public static void main(String[] args)
{
int type,chair;
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("would like to purchase four chairs to go with their new table.. press 1 for Yes or 0 for No");
chair=input.nextInt();
if(chair==1)
{
price = price+250
System.out.println(name+" table price $"+price);
}
else if(chair==0)
{
System.out.println(name+" table price $"+price);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.