帮朋友改的一个订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();


    
    }

}
View Code

优质内容筛选与推荐>>
1、GIMP笔记
2、数据量大分批执行处理
3、HZNU 2019 校赛-Little Sub and Triples(小撒布与三数数对)(初见难收的非算法题类型之一)
4、一起谈.NET技术,系统架构技能之设计模式—代理模式
5、JavaScript异步加载与同步加载


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn