0

I am currently trying to get my simple program to run,it is a t-shirt shop, it ask the users their name, how many shirts they want to buy, the color, and which size they want(sm,md,lg,xlg) and the price dependent on the size and displays the total then also gives the option to enter a promotional discount code at the end. So i am using if else statements for the sizes, and i have everything working till there but then I get to asking if they want to use a promotional code and it stops working.( Sorry in advance as this may be deemed messy code)

Why does my program not allow me to input after asking for the promotion code ?

How do I put a If If else statement( if this is possible) ,for example if you have a promotion code and if you enter the right code or else have a nice d...? I Appreciate any pointers and am open to criticism good or bad, Thanks.

import java.util.Scanner;

public class tShirt {

public static void main ( String [] args){

String name, color, code;
int quant, size, coupon;
double  Total;

Scanner reader = new Scanner(System.in);

System.out.println(" Hello Welcome to The One Stop T-Shirt Shop ");
System.out.println("            What is your name? ");

name = reader.nextLine();

System.out.print(name);
System.out.println ( ", How many t-Shirts would you like to purchase? ");

quant = reader.nextInt();

System.out.println(name + ", what color do want the " + quant + " t-shirt(s) to be? ");
color = reader.next();

System.out.println(name + ", Which size do you need the " + quant + " " + color + " t-shirt(s) to be ? " );
System.out.println("                                                    ");
System.out.println("Please enter the number that corresponds to the size ");
System.out.println(" 1   small     4.99 ");
System.out.println(" 2   medium    5.99 ");
System.out.println(" 3   large     6.99 ");
System.out.println(" 4   x large   7.99 ");

size = reader.nextInt();

if(size == 1)
{

   System.out.println(name + ", Your " + quant + " " + color + " small t-Shirts come to a Total of : ");
   System.out.printf("% .2f %n", Total = 4.99 * quant );

} 
else
if( size == 2)
{

  System.out.println(name + ", Your " + quant + " " + color + " medium t-Shirts come to a Total of : ");
  System.out.printf("% .2f %n", Total =  5.99 * quant );

}
else
if ( size == 3 )
{
  System.out.println(name + ", Your " + quant + " " + color + " large  t-Shirts come to a Total of : ");
  System.out.printf("% .2f %n", Total = 6.99 * quant );

}
else

if  ( size == 4 )
{


  System.out.println(name + ", Your " + quant + " " + color + " xlarge t-Shirts come to a Total of : ");
  System.out.printf("% .2f %n", Total = 7.99 * quant );

 }

 else{
   System.out.println(name + ", Sorry you have entered an unknown size ");

 }


  System.out.println(" Do you have a promotional coupon ? 1 for yes 2 for no");

  coupon = reader.nextInt();

  if( coupon == 1){

    System.out.println(" Please enter the promotional coupon code to recieve a discount");
    code = reader.nextLine();

    if(code == "finalexam")

      System.out.println(" You will recieve a discount");

    else 
      System.out.println("Have a good day");

    }
  }
}
Jim Kiley
  • 3,564
  • 3
  • 26
  • 43
Jordan
  • 1
  • 2
  • To answer the title of the question... `if (value) { if (value2) {`... Nothing is wrong with that – OneCricketeer Apr 27 '17 at 03:04
  • Yes, you've got two significant errors in your program. You'll need to read _both_ the questions that have been mentioned as duplicates - one describes each error. Come back here and comment if either one is not clear. – Dawood ibn Kareem Apr 27 '17 at 03:09
  • After reading through those 2 post i have found the problem and now the program works completely, appreciate the extremely fast and extremely pinpoint accurate answers. – Jordan Apr 27 '17 at 03:27

0 Answers0