首页 技术 正文
技术 2022年11月11日
0 收藏 592 点赞 3,718 浏览 3486 个字

帮朋友改的一个订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(); }}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918