用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

彩票

2020-01-12 作者: 朱文波30举报

[java]代码库

import java.io.*;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class buy_caipiao {
       public static void main(String[] args) throws IOException
       {
            money mon=new money();
            mon.pp();//显示欢迎界面
            mon.save_money(1,0);//1表示用户选择存钱,0表示存钱的多少
                mon.mainshow();//主菜单
       }
}
 
 
class money//决定用户操作类
{
     winning_number win_number=new winning_number();
     opinion_win ow=new opinion_win();
     public int yu_e=0, save=0,gett=0,b=1,c=0,ccc1=0,moneyshu=0;
     public String zhuan="";
     public void save_money(int ad,int add_money)throws IOException//存钱
     {
        if(ad==0)
        {
            yu_e+=add_money;
        }
        if(ad==1)
        {
        do{
        System.out.println("\n\n\t\t##########当前是存钱界面##########\n");
        win_number.ppshow();
        System.out.println("存钱数目必须是10的倍数并且存钱数目不能超过10000元,不能小于1元。\n请输入金额:(输入后请按回车键)");
        BufferedReader din =new BufferedReader(new InputStreamReader(System.in));
        zhuan=din.readLine();
         
         
        char[] zhuchar=null;
 
        try {
             zhuchar = (zhuan).toCharArray();
             if(zhuchar.length==0){//这个方法是以"\n"结束分隔的,如果你直接输入回车的时候,要加判断
                 zhuchar=new char[1];
                 zhuchar[0]='1';
             }
        } catch (Exception e) {
        }
            if(zhuchar[0] == '1' && zhuchar.length == 1)
            { c=1;
            show_cuowu();
            continue;}
        try{
        save=Integer.parseInt(zhuan);
        b=save%10;
        if(save<=10000&&save>=10&&b==0)
        {
            c=0;
            yu_e+=save;
            System.out.println("\n存钱成功!");
            show_moneyy();
        }
       else if(save>0&&b!=0)
        {
            c=1;
            System.out.println("\n\n!!!!!!!!!!!!存钱数目必须是10的倍数,请检查正确后再重新输入!!!!!!!!!!!!!\n\n");
        }
        else
        {
            System.out.println("\n\n!!!!!!!!!!!!您输入的金额数目超过存钱数目范围,请检查正确后再重新输入!!!!!!!!!!!!!\n\n");
            c=1;
                }
        }
       catch (Exception e)
       {
           c=dddd(zhuan,0);
       }
 
        }while(c==1);
        }
        }
     public int dddd(String zhuan,int moneyyy)throws IOException//判断用户是否输入正确
     {
        int q1=0;
           char[] zhuann = zhuan.toCharArray();
           if(zhuann[0]=='e'&&zhuann.length==1)
           {
            q1=2;//直接退出程序
            byebye(moneyyy);
 
            }
           else if(zhuann[0]=='f'&&zhuann.length==1)
            {q1=0;}//0返回用户主菜单
           else if(zhuann.length==9)
            {q1=3;}//0返回用户主菜单
            else
            {
            show_cuowu();
            q1=1;//1继续循环
            }
            return q1;
        }
     public void get_money()throws IOException//取钱
        {
        BufferedReader din =new BufferedReader(new InputStreamReader(System.in));
        do{
            c=0;
        System.out.println("\n\n\t\t##########当前是取钱界面##########\n");
        win_number.ppshow();
        System.out.println("取钱数目必须是10的倍数并且取钱数目不能超过您当前的余额,取钱数目不能小于10元。\n您当前的余额是:"+yu_e+"元。\n\t请输入取款金额:(输入后请按回车键)");
            String abcd=din.readLine();
             
            char[] zhuchar=null;
 
        try {
             zhuchar = (abcd).toCharArray();
             if(zhuchar.length==0){//这个方法是以"\n"结束分隔的,如果你直接输入回车的时候,要加判断
                 zhuchar=new char[1];
                 zhuchar[0]='1';
             }
        } catch (Exception e) {
        }
            if(zhuchar[0] == '1' && zhuchar.length == 1)
            { c=1;
            show_cuowu();
            continue;}
             
             
             
        try{
 
        gett=Integer.parseInt(abcd);
        b=gett%10;
        if(gett<=yu_e&&gett>=10&&b==0)
        {
            c=0;
            yu_e-=gett;
            System.out.println("取钱成功!\n\n");
            show_moneyy();
        }
        else if(gett>yu_e)
        {
            System.out.println("\n\n!!!!!!!!!!!!您输入的金额数目超过您当前余额数目范围,请检查正确后再重新输入!!!!!!!!!!!!!\n\n");
            c=1;
                }
        else if(gett<10)
        {
            System.out.println("\n\n!!!!!!!!!!!!您输入的金额数目不能小于10元。请检查正确后再重新输入!!!!!!!!!!!!!\n\n");
            c=1;
                }
        else
        {show_cuowu();
        c=1;}
        }
       catch(Exception e)
       {
             c=dddd(abcd,0);
        }
        }while(c==1);
        }
     public void show_cuowu()//提示错误
        {System.out.println("\n\n!!!!!!!!!!!!您输入的数据出现错误,请检查正确后再重新输入!!!!!!!!!!!!!\n\n");}
     public void show_moneyy()//显示余额
        {
            System.out.println("\n您当前的余额是:"+yu_e+"元。\n");
        }
     public void byebye(int moneyyy_y)throws IOException//再见方法
        {
            if(this.yu_e>0||moneyyy_y>0)
            {
            yu_e+=moneyyy_y;
            System.out.println("\t\t^_^您的余额是"+yu_e+"元,请取回!");
            save_money(0,-(yu_e));
            }
            System.out.println("\t\t^_^谢谢您的惠顾!欢迎您的下次光临!祝您财源滚滚!^_^");
            System.exit(0);
        }
     public void pp()throws IOException//首页欢迎界面
    {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        do
        {
            System.out.print("         ----------------------------欢迎来到福利彩票中心-------------------------\n\n");
            System.out.print("参与彩票中奖一次花费10元,请存钱才能参与中奖活动:\n");
            System.out.print("按 y 进入存钱界面,按 n 可退出中奖活动\n");
            System.out.println("是否继续参与中奖活动,请输入:(输入后请按回车键)");
        char[] zhuchar=null;
 
        try {
             zhuchar = (buffer.readLine()).toCharArray();
             if(zhuchar.length==0){//这个方法是以"\n"结束分隔的,如果你直接输入回车的时候,要加判断
                 zhuchar=new char[1];
                 zhuchar[0]='1';
             }
        } catch (Exception e) {
        }
            if(zhuchar[0] == 'y' && zhuchar.length == 1)
                ccc1 = 0;
            else
            if(zhuchar[0] == 'n' && zhuchar.length == 1)
                ccc1 = dddd("e", 0);
            else
                ccc1 = dddd("o", 0);
        } while(ccc1 == 1);
    }
 
     public void mainshow()throws IOException//用户主菜单
        {
            int q=1;
            do{
            System.out.println("\n\n\t\t########################################");
            System.out.println("\t\t###       当前是用户主菜单界面       ###");
            System.out.println("\t\t########################################");
            System.out.println("\t选择您要的服务:\t1.存钱\t2.取钱\t3.买彩票\t4.查看余额\t5.退出");
            System.out.println("请选择:(输入后请按回车键)");
            BufferedReader buffer =new BufferedReader(new InputStreamReader(System.in));
            Pattern p = null; //正则表达式
                        Matcher m = null; //操作的字符串
 
                        String    str=buffer.readLine();
            if(Pattern.compile(str).matcher("1").matches())//判断字符串变量str的值是否与"1"匹配
                        {
                save_money(1,0);//1/0表示判断是否用户操作存钱
                q=-1;
            }
            else if(Pattern.compile(str).matcher("2").matches()){
                if(yu_e>=10)
                {
                get_money();
                q=-1;
                }
                else {
                    System.out.println("\t\t您的余额不足!无法进行此操作!\n\n");
                    q=-1;
                }
            }
            else if(Pattern.compile(str).matcher("3").matches()){
                if(yu_e>=10)
                {
                   save_money(0,-10);
                   save_money(0,ow.opi(yu_e));//ow.opi(yu_e)传值给y_hu_s_ru()
                   q=-1;
                }
                else {
                    System.out.println("\t\t您的余额不足!无法进行此操作!\n\n");
                    q=-1;
                }
            }
            else if(Pattern.compile(str).matcher("4").matches()){
                show_moneyy();
                q=-1;
            }
            else if(Pattern.compile(str).matcher("5").matches()){
                byebye(0);
 
                }
 
            else{
                q=0;
                show_cuowu();
            }
            }while(q==0||q==-1);
        }
}
 
 
 
 
class winning_number//产生与显示中奖号码
            {
            String b="",e="";
            int[] nums = new int[5];
            int[] win_num()throws IOException
               {
                    Random rnd = new Random();
                    for(int i=0;i<5;i++)
                       {
                            nums[i]=-1;
                            nums[i]=rnd.nextInt(10);//随机产生1~10之间的整数
                           //System.out.println("中奖号码是:"+nums[i]);//显示中奖号码
                       }
                            return nums;
               }
             void play_win_num()//显示中奖的号码
                {
                         e="";
                        for(int i=0;i<5;i++)
                        {
                             b=Integer.toString(nums[i])+"  ";
                            e=e+b;
                       }
                             System.out.println("本次的中奖的号码如下:\n"+e);
                       }
            void ppshow()throws IOException
                        {System.out.println("\t(温馨提示: 按 e 并按回车键可退出参与这次中奖活动,按 f 并按回车键可返回用户主菜单.)\n");};
}
 
 
 
class y_hu_s_ru
{
     int[] haoma(int yu_ee1)throws IOException
    {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        money mon = new money();
        winning_number win_number=new winning_number();
        int p = 0;
        int d = -1,yu_e=0;;
        int dd = 0,cc=0;
        char q = ' ';
        int c[] = new int[5];
        do
        {
            if(p == 0)
            {
                System.out.println("\n\n\t\t##########当前是中奖彩票中心界面##########\n");
                win_number.ppshow();
                System.out.println("请输入 五 个您选中的数字从0~~9之间彩票号码(包括0和9),并且每个号码之间以空格隔开.");
            }
            System.out.println("请输入:(输入后请按回车键)");
            String s = buffer.readLine();
            char[] zhuchar=null;
 
        try {
             zhuchar = (s).toCharArray();
             if(zhuchar.length==0){//这个方法是以"\n"结束分隔的,如果你直接输入回车的时候,要加判断
                 zhuchar=new char[1];
                 zhuchar[0]='1';
             }
        } catch (Exception e) {
        }
            if(zhuchar[0] == '1' && zhuchar.length == 1)
            { p=0;
            mon.show_cuowu();
            continue;}
 
            String as[] = s.split(" ");
            yu_e=yu_ee1;
            cc=mon.dddd(s,(yu_e+10));
        if(cc==1)
        {p=0;
            continue;}
        if(cc==0)
 
       {
         p=1;
         c[0]=-2;
         break;
        }
            if(as.length == 5)//判断用户输入的是5个字符
            {
                for(int i = 0; i <= 4; i++)
                {
                    try
                    {
                        d = Integer.parseInt(as[i]);//用户输入的字符串转换成Int 类型
                        if(d >= 0 && d < 10)
                        {
                            c[i] = d;
                            if(i == 4)
                            {p = 1;}
                            continue;
                        }
                        else//用户输入的数字超过0~~10之间的范围
                        {
                        mon.show_cuowu();
                        p = 0;
                        }
                    }
                    catch(Exception e)//确定用户输入的是字符串
                    {
                        p = 0;
                        mon.show_cuowu();
                    }
                    break;
                }
            }
            else//用户输入的不是5个数字
            {
                p = 0;
                mon.show_cuowu();
                break;
            }
        } while(p == 0);
        return c;
    }
}
 
class opinion_win//计算中奖的号码
{
            winning_number win_number=new winning_number();
            y_hu_s_ru yhu=new y_hu_s_ru();
            int j=0,return_money=0,yu_ee=0;;
            int[] nums1=new int[5];
            int[] d=new int[5];
             
            int opi(int yu_e1) throws IOException{
                    yu_ee=yu_e1;
                   d=win_number.win_num();
                   nums1=yhu.haoma(yu_ee);
                   if(nums1[0]==-2)
                   {return_money=10;}
                   else
                   {
             for(int i=1,j=0,q;i<=5;i++)
             {
                   q=d[i-1];
                   for(int k=1;k<=5;k++)
                    {
                       if(q==nums1[k-1])
                      {
                        j++;//计算出买对有多少个中奖号码
                        nums1[k-1]=-1;q=-2;//防止再计算的已中奖号码
                      }
                   }
                    if(i==5)
                   {
                     win_number.play_win_num();
                     if(j==5)
                     {
                        System.out.println("您买中了全部号码。\n\t\t^_^恭喜你获得一等奖,中奖金额为230000000元");
                        return_money=230000000;
                        }
                    else if(j==4)
                     {
                        System.out.println("您买中了四个号码。\n\t\t^_^恭喜你获得二等奖,中奖金额为50000000元");
 
                        return_money=50000000;}
                     else if(j==3)
                     {
                        System.out.println("您买中了三个号码。\n\t\t^_^恭喜你获得三等奖,中奖金额为100000元");
 
                        return_money=100000;}
                     else if(j==2)
                        {
                            System.out.println("您买中了二个号码。\n\t\t^_^恭喜你获得鼓励奖,中奖金额为10000元");
 
                            return_money=10000;}
                    else
                     {System.out.println("\t\t^_^您好像没有中奖噢!谢谢您的参与,祝您下次好运!^_^");
 
                     return_money=0;}
                   }
              }
                   }
            return return_money;}
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...