我目前正试图让我的简单程序运行,它是一个T恤店,它询问用户他们的名字,他们想买多少衬衫,颜色,以及他们想要的尺寸(sm,md) ,lg,xlg)和价格取决于尺寸并显示总数,然后还提供了在最后输入促销折扣代码的选项。 所以我正在使用if else语句的大小,我有一切工作到那里,但后来我问他们是否想要使用促销代码,它停止工作。(提前抱歉,因为这可能被视为凌乱的代码)< / p>
为什么我的程序在要求提升代码后不允许我输入?
如何添加If If else语句(如果可以的话),例如,如果您有促销代码,并且输入正确的代码或者有一个不错的代码......? 我赞赏任何指示,并且批评好坏,谢谢。
import java.util.Scanner;
公共课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");
}
}
}