帮朋友改的一个订pizza的作业
大概要求就是输入判断,选择pizza的个数和种类,然后返回一个价格
代码放在下面,如果有刚学Java的同学可以参考一下,没有什么难度
public class Pizza { public static void main(String[] args) {
// TODO Auto-generated method stub
String Ifm="M";
String ifm="m";
String Ifv="V";
String ifv="v";
String Ifh="H";
String ifh="h";
System.out.println("Welcome to the Java and a Slice Pizza Parlor.");
System.out.print("Please enter a name for our transaction records:"); Scanner a=new Scanner(System.in);
String name=a.nextLine();
System.out.println("Thank you,"+name); System.out.println("Which type of pizza would you like?");
System.out.println("---------------------------------");
System.out.println("[M] Mega-Meaty");
System.out.println("[V] Very Vegetarian");
System.out.println("[H] Heaping Hawaiian");
System.out.println("---------------------------------");
System.out.print("Enter pizza choice:");
Scanner b=new Scanner(System.in);
String type=b.nextLine(); if(type.equals(ifh)||type.equals(Ifh)||type.equals(ifv)||type.equals(Ifv)||type.equals(ifm)||type.equals(Ifm)) {
if(type.equals(ifh)||type.equals(Ifh))
{String newtype="Heaping Hawaiian";
System.out.println("Price list for pizza type:"+newtype);}
else if(type.equals(ifm)||type.equals(Ifm))
{String newtype="Mega-Meaty";
System.out.println("Price list for pizza type:"+newtype);}
else if(type.equals(ifv)||type.equals(Ifv))
{String newtype="Very Vegetarian";
System.out.println("Price list for pizza type:"+newtype);}
}
else {
System.out.println("I'm sorry, BadUser, but that is an invalid choice");
System.out.println("Goodbye.");
return;
} System.out.println("---------------------------------");
double prize12=0;
double prize16=0;
if(type.equals(ifh)||type.equals(Ifh))
{
prize12=10.50;
prize16=14.50;}
else if(type.equals(ifv)||type.equals(Ifv))
{
prize12=9.50;
prize16=13.50;
}
else
{
prize12=11.5;
prize16=15.5;
}
System.out.println("12-inch: $"+prize12);
System.out.println("16-inch: $"+prize16);
System.out.println("---------------------------------");
System.out.println("What size pizza would you like?");
System.out.print("Enter size in inches:");
Scanner c=new Scanner(System.in);
int size=c.nextInt(); if((size!=12&&size!=16))
{
System.out.println("I'm sorry, BadUser, but that is an invalid choice");
System.out.println("Goodbye.");
return;
} //ѡ��pizza����
System.out.println("How many pizzas would you like?");
System.out.print("Enter number between 1 and 12:");
Scanner d=new Scanner(System.in);
int number=d.nextInt();
if((number<1)&&number>12)
{
System.out.println("I'm sorry, BadUser, but that is an invalid choice");
System.out.println("Goodbye.");
return;
} System.out.println("Would you like to add Cheezy Bread to that, for a $3.00 charge?");
System.out.print("Please enter Y for yes or N for no:");
Scanner e=new Scanner(System.in);
String sure=e.nextLine();//����һ���ַ�
String Ify="Y";
String ify="y";
String Ifn="N";
String ifn="n";
if((type.equals(ify)||type.equals(Ify)||type.equals(ifn)||type.equals(Ifn)))
{
if(type.equals(ify)||type.equals(Ify))
{;}
else
{
System.out.println("I'm sorry, BadUser, but that is an invalid choice");
System.out.println("Goodbye.");
return;
}
}
System.out.println("---------------------------------");
System.out.println(" Thank you,"+name+". Here is a record of your purchase.");
System.out.println("---------------------------------");
System.out.println(number+" "+size+"-inch Heaping Hawaiian pizzas.");
if((type.equals(ify)||type.equals(Ify)))
{
System.out.println("1 order Cheezy Bread.");
}
System.out.println("---------------------------------");
double totalprize=0;
if(size==12)
{totalprize=prize12*number;}
else {totalprize=prize16*number;}
if(type.equals(ify)||type.equals(Ify))
{totalprize+=3.00;}
System.out.println("Total cost:"+totalprize);
a.close();
b.close();
c.close();
d.close();
e.close(); }}