简体   繁体   English

我的Java程序给我99个错误

[英]My java program is giving me 99 wrong errors

I am fairly new to programming.I am currently studying java in my first year of college.I was given a group java project.My part of the project is giving me 96 different errors but none of the errors given actually are wrong.The project takes in between 1 and 7 command line arguments. 我对编程很陌生,我在大学一年级时正在学习Java,我被授予了一个Java小组项目,该项目的一部分给了我96个不同的错误,但给出的所有错误实际上都不是错误的。接受1到7个命令行参数。 It then does different things depending on what was entered.It overall analyses different parts of a file that represents the Lotto.I compile my program with the command line.I can post all of the errors if it is requested.First off here is my entire code but I had to take out a method so that it would fit in one post.The method I took out is error free as I have that checked already.It was the arguments method. 然后根据输入的内容执行不同的操作。它整体分析代表乐透的文件的不同部分。我使用命令行编译程序。如果有要求,我可以发布所有错误。首先是我的完整的代码,但我必须取出一个方法才能放在一篇文章中。我取出的方法没有错误,因为我已经检查过了。这是arguments方法。

import javax.swing.JOptionPane;
import java.util.*;
import java.io.*;
import java.text.*;
import java.lang.*;
public class Text1
{
  public static final String filename = "SampleLottoData.txt";
  public static void main(String [] args) throws IOException, ParseException, AssertionError 
  {
  File Numbers = new File(filename);
  Scanner in = new Scanner(Numbers);
  if(Numers.exists())
   {
   ArgumentCheck(args);
   if(args.length <= 5)
    int choice = Integer.parseInt(args[0]);
   if (args.length >= 2 && args.length <= 5)
    String drawtype = args[1].toUpperCase();
   if(args.length >= 3 %% args.length <= 5)
    int day = Integer.parseInt(args[2]);
   if(args.length == 4)
    int year = Integer.parseInt(args[3]);
   if(args.length == 1)
    JackpotOrBonus(args,in,choice);
     else if(args.length == 2)
      TypeOfDraw(args,in,choice,drawtype);
       else if(args.length == 3)
        DrawOnADay(args,in,choice,drawtype,day);
         else if(args.length == 4)
          DrawForAYear(args,in,choice,drawtype,day,year);
           else if(args.length == 5)
            BetweenTwoDates(args,in,choice,drawtype,day);
   }
  else JOptionPane.showMessageDialog(null,"The file " + filename + " doesn't exist");
}

  public static void JackpotOrBonus(String [] args,Scanner in,int choice) throws IOException
   {
    int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [] jackpot = new int[6], int bonus = 0;
    String data = "";
    String [] temp = new String[9];
     if(choice == 1)
      {
       while(in.hasNext())
       {
       data = in.nextLine();
       temp = data.split(",");
        for(int counter = 0;counter < jackpot.length;counter++)
        {
         jackpot[counter] = Integer.parseInt(temp[counter + 1]);
         jackpotnumbers[jackpot[counter] - 1]++;
         }
         }
         in.close();
         }
      else
       {
        while(in.hasNext())
        {
         data = in.nextLine();
         temp = data.split(",");  
         bonus = Integer.parseInt(temp[7]);
         bonusnumbers[bonus - 1]++;
        }
        in.close();
       }
    Printing(args,jackpotnumbers,bonusnumbers);    
   }


  public static void TypeOfDraw(String [] args,Scanner in,int choice,String drawtype) throws IOException
  { 
   int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [] jackpot = new int[6], int bonus = 0;
   String data = "";
   String [] temp = new String[9];
   if(choice == 1 || choice == 2)
    {
     while(in.hasNext())
     {
     data = in.nextLine();
     temp = data.split(",");
      if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
       for(int count = 0;count<jackpot.length;count++)
       {
       jackpot[count] = Integer.parseInt(temp[count + 1]);
       jackpotnumbers[jackpot[count] - 1]++;  
       }
     }
     in.close();
    }
     if(choice == 2)
      {
      while(in.hasNext())
       {
       data = in.nextLine();
       temp = data.split(",");
       bonus = Integer.parseInt(temp[7]);
        if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
         bonusnumbers[bonus - 1]++;  
       }
       in.close();
      }
     Printing(args,jackpotnumbers,bonusnumbers); 
  }


  public static void DrawOnADay(String [] args,Scanner in,int choice,String drawtype,int day) throws IOException
  {  
    int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [] jackpot = new int[6], int bonus = 0;
    String data = "",weekday;
    String [] temp = new String[9];
     if(choice == 1 || choice == 2)
      {
      while(in.hasNext())
       {
       data = in.nextLine();
       temp = data.split(",");
       weekday = convertDateToWeekDay(temp);
       if(weekday == day || day == 0);
        {
        if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
         for(int count = 0;count<jackpot.length;count++)
         {
         jackpot[count] = Integer.parseInt(temp[count + 1]);
         jackpotnumbers[jackpot[count] - 1]++;  
         }
        }
        in.close;();
       }
       if(choice == 2)
        {
        while(in.hasNext())
         {
         data = in.nextLine();
         temp = data.split(",");
         weekday = convertDateToWeekDay(temp);
         if(weekday == day || day == 0);
          {
          bonus = Integer.parseInt(temp[7]);
          if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
           bonusnumbers[bonus - 1]++;      
         }
       }
       in.close();
       }
     }
     Printing(args,jackpotnumbers,bonusnumbers); 
   }      

  public static void DrawsForAYear(String [] args,Scanner in,int choice,String drawtype,int day,int year) throws IOException
   {
    int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [] jackpot = new int[6], int bonus = 0;
    String data = "",weekday;
    String [] temp = new String[9];   
    String temporary = temp[0];
    String [] temps = temporary.split("/");
    int years = Integer.parseInt(temps[2]);
    weekday = convertDateToWeekDay(temp);
     while(in.hasNext())
      {
      data = in.nextLine();
      temp = data.split(",");
      String temporary = temp[0];
      String [] temps = temporary.split("/");
      int years = Integer.parseInt(temps[2]);
      weekday = convertDateToWeekDay(temp);
       if((year == years) && (temp[8].contentEquals(drawtype) || drawtype.contentEquals("A")) && (weekday == day || day == 0))
       {
        if (choice == 1 || choice == 2)
         {
         for(int count = 0;count<jackpot.length;count++)
         {
         jackpot[count] = Integer.parseInt(temp[count + 1]);
         jackpotnumbers[jackpot[count] - 1]++; 
         }
        }
        if(choice == 2)
         {
         bonus = Integer.parseInt(temp[7]);
         if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
         bonusnumbers[bonus - 1]++;    
         }
       }
      }
      in.close();
      EvenOrOdd(args,choice,in);
      Printing(args,jackpotnumbers,bonusnumbers,year); 
   }


  public static void EvenOrOdd(String [] args,int choice,Scanner in,int year)
  { 
   int length, number,odd = 0,even = 0,lowexceedshighr,lowexceedshighs,lowexceedshighlp1,lowexceedshighlp2;
   String data = "",weekday;
   String [] temp = new String[9];   
   if(choice == 1)
    length = 6;
     else 
      length = 7;
   while(in.hasNext())
    {
    int oddcounter = 0, evencounter = 0;
    data = in.nextLine();
    temp = data.split(",");   
    String temporary = temp[0];
    String [] temps = temporary.split("/");
    for(int counter = 0;counter<length;counter++)
    {
    number = Integer.parseInt(temp[counter + 1]);
     if(number % 2 == 0)
      evencounter++;
       else 
       oddcounter++;
    }
    if(evencounter == length)
     even++;
      else if(oddcounter == length)
       odd++;
   int years = Integer.parseInt(temps[2]);
   if (year == years)
    {
    int high = 36;
    String 39s = "22/08/1992", 42s = "24/09/1994", 45s = "4/11/2006";
    String datayear = temp[0];
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    Date datas = df.parse(datayear);
    Date 39ss = df.parse(39s);
    Date 42ss = df.parse(42s);
    Date 45ss = df.parse(45s);
    if(datas.equals(39ss) || (datas.after(39ss) && datas.before(42ss)))
     high = 39;
      else if(datas.equals(42ss) || (datas.after(42ss) && datas.before(45ss)))
       high  42;
        else if(datas.equals(45ss) || (datas.after(45ss)))
         high = 45;
    int limit = (high - 10);
    for(int count = 0;count<jackpot.length;count++)
    jackpot[count] = Integer.parseInt(temp[count + 1]);
    int lowwinning = 0,highwinning = 0,
    for(int counter = 0;counter<jackpot.length;counter++)
    {
     if(jackpot[counter] <= 10)
      lowwinning++;
       else if(jackpot[counter] >= limit)
        highwinning++;   
    }
    if (lowwining > highwinning)
    {
     if(temp[8].contentEquals("R"))
      lowexceedshighr++;
       else if(temp[8].contentEquals("S"))
        lowexceedshighs++;
         else if(temp[8].contentEquals("LP1"))
          lowexceedshighlp1++;
           else if(temp[8].contentEquals("LP2"))
            lowexceedshighlp2++;
    }
   }
   in.close();
   String results = "";
   if(choice == 1)
   {
    results = "All Jackpot numbers were even " + even + " times.\n";
    results += "All Jackpot numbers were odd " + odd + " times.\n";   
   }
  else
  {
   results = "All Jackpot and Bonus numbers were even " + even + " times.\n";
   results += "All Jackpot and Bonus numbers were odd " + odd + " times.\n";      
  }
  results += "In " + args[3] + " low winning numbers exceeded high winning numbers\n";
  results += lowexceedshighr + " in regular draws.\n";
  results += lowexceedshighs + " in special draws.\n";
  results += lowexceedshighlp1 + " in Lotto Plus 1 draws.\n";
  results += lowexceedshighlp2 + " in Lotto Plus 2 draws.";
  JOptionPane.showMessageDialog(null,results,"Analysing the Lotto",1);  
}


  public static void BetweenTwoDates(String [] args,Scanner in,int choice,String drawtype,int day) throws IOException, ParseException, AssertionError
  {
   int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [] jackpot = new int[6], int bonus = 0;
   String data = "",weekday;
   String [] temp = new String[9];
    while(in.hasNext())
    {
     data = in.nextLine();
     temp = data.split(",");
     String firstyear = args[3];
     String secondyear = args[4];
     String datayear = temp[0];
     DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
     Date first = df.parse(firstyear);
     Date second = df.parse(secondyear);
     Date datas = df.parse(datayear);
     weekday = convertDateToWeekDay(temp);
     if(weekday == day || day == 0);
     {
      if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
      {
       if((datas.equals(first)) || (datas.equals(second)) || ((datas.after(first)) && (datas.before(second))))
       {
        if(choice == 1 || choice == 2)
         {
         for(int count = 0;count<jackpot.length;count++)
         {
         jackpot[count] = Integer.parseInt(temp[count + 1]);
         jackpotnumbers[jackpot[count] - 1]++;  
         }
         }
       if(choice == 2)
        {
        bonus = Integer.parseInt(temp[7]);
        if(temp[8].contentEquals(drawtype) || drawtype.contentEquals("A"))
         bonusnumbers[bonus - 1]++;    
        }
      }       
    }
   }
   }
   in.close();
   Printing(args,jackpotnumbers,bonusnumbers); 
  } 



  public static int convertDateToWeekDay(String [] temp)
  {
    int result = 0; 
    int a, b, d, m, y, dayOfWeek;
    String date = temp[0];
    String [] dates = date.split("/");
    d = Integer.parseInt(dates[0]); 
    m = Integer.parseInt(dates[1]);
    y = Integer.parseInt(dates[2]);
    if (m == 1 || m == 2)
    {
      m += 12; y -=  1;
    }
    a = y % 100;  b = y / 100;
    dayOfWeek = ((d + (((m + 1)*26)/10)+ a + (a/4) + (b/4)) + (5*b)) % 7;
    switch(dayOfWeek)
    {
      case 0: result = 2;  break;
      case 4: result = 1; break;
    } 
    return result;
  } 


  public static void Printing(String [] args,int [] jackpotnumbers,int [] bonusnumbers)
  {
  String results = "";
  if(args.length == 1)
  {
  if(choice == 1)
        {
        results = "An Analysis of Jackpot Numbers for the entire file.\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }
        }
       else
        {
        results = "An Analsis of Bonus Numbers for the entire file.\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a bonus number " + bonusnumbers[counter] + "times.\n";
        }   
        }
   }
   if(args.length == 2)
   {
    if(choice == 1)
        {
        if((args[1].toUpperCase()).contentEquals("A"))
         results = "An Analysis of Jackpot Numbers for the entire file.\n\n";
          else if((args[1].toUpperCase()).contentEquals("R"))
           results = "An Analysis of Jackpot Numbers for all regular draws.\n\n";
            else if((args[1].toUpperCase()).contentEquals("S"))
             results = "An Analysis of Jackpot Numbers for all special draws.\n\n";
              else if((args[1].toUpperCase()).contentEquals("LP1"))
               results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws.\n\n";
                else
                 results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws.\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }
        }
       else
        {
        if((args[1].toUpperCase()).contentEquals("A"))
         results = "An Analsis of Jackpot and Bonus Numbers for the entire file.\n\n";
          else if((args[1].toUpperCase()).contentEquals("R"))
           results = "An Analysis of Jackpot and Bonus Numbers for all regular draws.\n\n";
            else if((args[1].toUpperCase()).contentEquals("S"))
             results = "An Analysis of Jackpot and Bonus Numbers for all special draws.\n\n";
              else if((args[1].toUpperCase()).contentEquals("LP1"))
               results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws.\n\n";
                else
                 results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws.\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a bonus number " + bonusnumbers[counter] + "times and a jackpot number " + jackpotnumbers[counter] + "times.\n";
        } 
     if(args.length == 3)
         { 
         int numb = Integer.parseInt(args[2]); 
        if(choice == 1)
         {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analysis of Jackpot Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
        if(numb == 2)
         results += " on Wednesday draws.\n\n\";
          else if(numb == 1)
           results += " on Saturday draws.\n\n\";
            else
             results += " for all draws.\n\n\";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }
        }
       else
        {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";
        if(numb == 2)
         results += " on Wednesday draws.\n\n";
          else if(numb == 1)
           results += " on Saturday draws.\n\n";
            else
             results += " for all draws.\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a bonus number " + bonusnumbers[counter] + "times and a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }   
        }
        }
         if(args.length == 5)
         { 
         int numb = Integer.parseInt(args[2]); 
        if(choice == 1)
         {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analysis of Jackpot Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
        if(numb == 2)
         results += " on Wednesday draws\n\n";
          else if(numb == 1)
           results += " on Saturday draws\n\n";
            else
             results += " for all draws\n\n";
          results += "for " + args[3] + ".\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }
        }
       else
        {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";        
        if(numb == 2)
         results += " on Wednesday draws";
          else if(numb == 1)
           results += " on Saturday draws";
            else
             results += " for all draws";
         results += "for " + args[3] + ".\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a bonus number " + bonusnumbers[counter] + "times and a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }   
        }
        }
     if(args.length == 5)
         { 
         int numb = Integer.parseInt(args[2]); 
        if(choice == 1)
         {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analysis of Jackpot Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
        if(numb == 2)
         results += " on Wednesday draws\n\n";
          else if(numb == 1)
           results += " on Saturday draws\n\n";
            else
             results += " for all draws\n\n";
          results += "between " + args[3] + " and " + args[4] + ".\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }
        }
       else
        {
         if((args[1].toUpperCase()).contentEquals("A"))
          results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
           else if((args[1].toUpperCase()).contentEquals("R"))
            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
             else if((args[1].toUpperCase()).contentEquals("S"))
              results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
               else if((args[1].toUpperCase()).contentEquals("LP1"))
                results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                 else
                  results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";        
        if(numb == 2)
         results += " on Wednesday draws";
          else if(numb == 1)
           results += " on Saturday draws";
            else
             results += " for all draws";
         results += "between " + args[3] + " and " + args[4] + ".\n\n";
        for(int counter = 0;counter<45;counter++)
        {
        int num = counter + 1;
        results+= num + " was a bonus number " + bonusnumbers[counter] + "times and a jackpot number " + jackpotnumbers[counter] + "times.\n";
        }   
        }
        }
    }   
   }
   JOptionPane.showMessageDialog(null,results,"Analysing the Lotto",1);   
  }
}

I am sorry for the long code but I have no idea where any problems actually are.I am also sorry its not commented, the final version will be.I am not able to post all of the errors here due to the character limit.How can I show ye what the errors are.There are 96 errors but none of them seem valid at all.The errors are different versions of the following: 很长的代码,我很抱歉,但我不知道实际上有什么问题。我也很抱歉,它没有被评论,最终版本将是。由于字符数的限制,我无法在此处发布所有错误。我可以告诉你这些错误是什么。有96个错误,但似乎都没有,这些错误是以下版本的不同版本:

Text1.java:541: error: unclosed string literal
             results += " for all draws.\n\n\";
Text1.java:391: error: <identifier> expected
   int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [
] jackpot = new int[6], int bonus = 0;
Text1.java:391: error: ';' expected
   int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [
] jackpot = new int[6], int bonus = 0;
Text1.java:391: error: illegal start of expression
   int [] jackpotnumbers = new int[45], int [] bonusnumbers = new int[45], int [
] jackpot = new int[6], int bonus = 0;
Text1.java:349: error: not a statement
    for(int counter = 0;counter<jackpot.length;counter++)
Text1.java:23: error: '.class' expected
    int year = Integer.parseInt(args[3]);

If you need more information just ask.Any help would be hugely appreciated as I have no idea what to do now and I can't write all of that code again as the project is due on Tuesday. 如果您需要更多信息,请询问。任何帮助将不胜感激,因为我不知道现在该怎么办,并且由于该项目将于周二到期,因此我无法再次编写所有代码。

ye your code looked messed up looks like you did it on notepad and run it in cmd or something anyway i was able to remove the syntax errors. 是的,您的代码看上去很混乱,就像您在记事本上完成并以cmd或其他方式运行它一样,我能够消除语法错误。 Hopefully the code will be readable to fellow stackoverflow users and help you with that 99 problems so you can move on to fixing the real thing. 希望这些代码对其他stackoverflow用户而言都是可读的,并且可以帮助您解决这99个问题,以便您可以继续解决实际问题。

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import javax.swing.JOptionPane;

public class Text1 {
    public static final String filename = "SampleLottoData.txt";

    public static void main(String[] args) throws IOException, ParseException,
            AssertionError {
        File Numbers = new File(filename);
        Scanner in = new Scanner(Numbers);
        if (Numbers.exists()) {
            // ArgumentCheck(args);
            if (args.length <= 5) {
                int choice = Integer.parseInt(args[0]);
                if (args.length >= 2 && args.length <= 5) {
                    String drawtype = args[1].toUpperCase();

                    if (args.length >= 3 && args.length <= 5) {
                        int day = Integer.parseInt(args[2]);

                        if (args.length == 4) {
                            int year = Integer.parseInt(args[3]);

                            if (args.length == 1) {
                                JackpotOrBonus(args, in, choice);
                            } else if (args.length == 2) {
                                TypeOfDraw(args, in, choice, drawtype);
                            } else if (args.length == 3) {
                                DrawOnADay(args, in, choice, drawtype, day);
                            } else if (args.length == 4) {
                                DrawsForAYear(args, in, choice, drawtype, day,
                                        year);
                            } else if (args.length == 5) {
                                BetweenTwoDates(args, in, choice, drawtype, day);
                            }
                        }
                    }
                }
            }
        } else
            JOptionPane.showMessageDialog(null, "The file " + filename
                    + " doesn't exist");
    }

    public static void JackpotOrBonus(String[] args, Scanner in, int choice)
            throws IOException {
        int[] jackpotnumbers = new int[45];
        int[] bonusnumbers = new int[45];
        int[] jackpot = new int[6];
        int bonus = 0;
        String data = "";
        String[] temp = new String[9];
        if (choice == 1) {
            while (in.hasNext()) {
                data = in.nextLine();
                temp = data.split(",");
                for (int counter = 0; counter < jackpot.length; counter++) {
                    jackpot[counter] = Integer.parseInt(temp[counter + 1]);
                    jackpotnumbers[jackpot[counter] - 1]++;
                }
            }
            in.close();
        } else {
            while (in.hasNext()) {
                data = in.nextLine();
                temp = data.split(",");
                bonus = Integer.parseInt(temp[7]);
                bonusnumbers[bonus - 1]++;
            }
            in.close();
        }
        Printing(args, jackpotnumbers, bonusnumbers, bonus);
    }

    public static void TypeOfDraw(String[] args, Scanner in, int choice,
            String drawtype) throws IOException {
        int[] jackpotnumbers = new int[45];
        int[] bonusnumbers = new int[45];
        int[] jackpot = new int[6];
        int bonus = 0;
        String data = "";
        String[] temp = new String[9];
        if (choice == 1 || choice == 2) {
            while (in.hasNext()) {
                data = in.nextLine();
                temp = data.split(",");
                if (temp[8].contentEquals(drawtype)
                        || drawtype.contentEquals("A"))
                    for (int count = 0; count < jackpot.length; count++) {
                        jackpot[count] = Integer.parseInt(temp[count + 1]);
                        jackpotnumbers[jackpot[count] - 1]++;
                    }
            }
            in.close();
        }
        if (choice == 2) {
            while (in.hasNext()) {
                data = in.nextLine();
                temp = data.split(",");
                bonus = Integer.parseInt(temp[7]);
                if (temp[8].contentEquals(drawtype)
                        || drawtype.contentEquals("A"))
                    bonusnumbers[bonus - 1]++;
            }
            in.close();
        }
        Printing(args, jackpotnumbers, bonusnumbers, bonus);
    }

    public static void DrawOnADay(String[] args, Scanner in, int choice,
            String drawtype, int day) throws IOException {
        int[] jackpotnumbers = new int[45];
        int[] bonusnumbers = new int[45];
        int[] jackpot = new int[6];
        int bonus = 0;
        String data = "";
        int weekday;
        String[] temp = new String[9];
        if (choice == 1 || choice == 2) {
            while (in.hasNext()) {
                data = in.nextLine();
                temp = data.split(",");
                weekday = convertDateToWeekDay(temp);
                if (weekday == day || day == 0)
                    ;
                {
                    if (temp[8].contentEquals(drawtype)
                            || drawtype.contentEquals("A"))
                        for (int count = 0; count < jackpot.length; count++) {
                            jackpot[count] = Integer.parseInt(temp[count + 1]);
                            jackpotnumbers[jackpot[count] - 1]++;
                        }
                }
                in.close();
            }
            if (choice == 2) {
                while (in.hasNext()) {
                    data = in.nextLine();
                    temp = data.split(",");
                    weekday = convertDateToWeekDay(temp);
                    if (weekday == day || day == 0)
                        ;
                    {
                        bonus = Integer.parseInt(temp[7]);
                        if (temp[8].contentEquals(drawtype)
                                || drawtype.contentEquals("A"))
                            bonusnumbers[bonus - 1]++;
                    }
                }
                in.close();
            }
        }
        Printing(args, jackpotnumbers, bonusnumbers, bonus);
    }

    public static void DrawsForAYear(String[] args, Scanner in, int choice,
            String drawtype, int day, int year) throws IOException,
            ParseException {
        int[] jackpotnumbers = new int[45];
        int[] bonusnumbers = new int[45];
        int[] jackpot = new int[6];
        int bonus = 0;
        String data = "";
        int weekday;
        String[] temp = new String[9];
        String temporary = temp[0];
        String[] temps = temporary.split("/");
        int years = Integer.parseInt(temps[2]);
        weekday = convertDateToWeekDay(temp);
        while (in.hasNext()) {
            data = in.nextLine();
            temp = data.split(",");
            temporary = temp[0];
            temps = temporary.split("/");
            years = Integer.parseInt(temps[2]);
            weekday = convertDateToWeekDay(temp);
            if ((year == years)
                    && (temp[8].contentEquals(drawtype) || drawtype
                            .contentEquals("A"))
                    && (weekday == day || day == 0)) {
                if (choice == 1 || choice == 2) {
                    for (int count = 0; count < jackpot.length; count++) {
                        jackpot[count] = Integer.parseInt(temp[count + 1]);
                        jackpotnumbers[jackpot[count] - 1]++;
                    }
                }
                if (choice == 2) {
                    bonus = Integer.parseInt(temp[7]);
                    if (temp[8].contentEquals(drawtype)
                            || drawtype.contentEquals("A"))
                        bonusnumbers[bonus - 1]++;
                }
            }
        }
        in.close();
        EvenOrOdd(args, choice, in, years);
        Printing(args, jackpotnumbers, bonusnumbers, year);
    }

    public static void EvenOrOdd(String[] args, int choice, Scanner in, int year)
            throws ParseException {
        int length, number, odd = 0, even = 0, lowexceedshighr = 0, lowexceedshighs = 0, lowexceedshighlp1 = 0, lowexceedshighlp2 = 0;
        String data = "", weekday;
        String[] temp = new String[9];
        int[] jackpot = new int[6];
        if (choice == 1)
            length = 6;
        else
            length = 7;
        while (in.hasNext()) {
            int oddcounter = 0, evencounter = 0;
            data = in.nextLine();
            temp = data.split(",");
            String temporary = temp[0];
            String[] temps = temporary.split("/");
            for (int counter = 0; counter < length; counter++) {
                number = Integer.parseInt(temp[counter + 1]);
                if (number % 2 == 0)
                    evencounter++;
                else
                    oddcounter++;
            }
            if (evencounter == length)
                even++;
            else if (oddcounter == length)
                odd++;
            int years = Integer.parseInt(temps[2]);
            if (year == years) {
                int high = 36;
                String s39 = "22/08/1992";
                String s42 = "24/09/1994";
                String s45 = "4/11/2006";
                String datayear = temp[0];
                DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                Date datas = df.parse(datayear);
                Date ss39 = df.parse(s39);
                Date ss42 = df.parse(s42);
                Date ss45 = df.parse(s45);
                if (datas.equals(ss39)
                        || (datas.after(ss39) && datas.before(ss42)))
                    high = 39;
                else if (datas.equals(ss42)
                        || (datas.after(ss42) && datas.before(ss45)))
                    high = 42;
                else if (datas.equals(ss45) || (datas.after(ss45)))
                    high = 45;
                int limit = (high - 10);
                for (int count = 0; count < jackpot.length; count++)
                    jackpot[count] = Integer.parseInt(temp[count + 1]);
                int lowwinning = 0, highwinning = 0;
                for (int counter = 0; counter < jackpot.length; counter++) {
                    if (jackpot[counter] <= 10)
                        lowwinning++;
                    else if (jackpot[counter] >= limit)
                        highwinning++;
                }
                if (lowwinning > highwinning) {
                    if (temp[8].contentEquals("R"))
                        lowexceedshighr++;
                    else if (temp[8].contentEquals("S"))
                        lowexceedshighs++;
                    else if (temp[8].contentEquals("LP1"))
                        lowexceedshighlp1++;
                    else if (temp[8].contentEquals("LP2"))
                        lowexceedshighlp2++;
                }
            }
            in.close();
            String results = "";
            if (choice == 1) {
                results = "All Jackpot numbers were even " + even + " times.\n";
                results += "All Jackpot numbers were odd " + odd + " times.\n";
            } else {
                results = "All Jackpot and Bonus numbers were even " + even
                        + " times.\n";
                results += "All Jackpot and Bonus numbers were odd " + odd
                        + " times.\n";
            }
            results += "In " + args[3]
                    + " low winning numbers exceeded high winning numbers\n";
            results += lowexceedshighr + " in regular draws.\n";
            results += lowexceedshighs + " in special draws.\n";
            results += lowexceedshighlp1 + " in Lotto Plus 1 draws.\n";
            results += lowexceedshighlp2 + "in Lotto Plus 2 draws.";
            JOptionPane.showMessageDialog(null, results, "", 1);
        }

    }

    public static void BetweenTwoDates(String[] args, Scanner in, int choice,
            String drawtype, int day) throws IOException, ParseException,
            AssertionError {
        int[] jackpotnumbers = new int[45];
        int[] bonusnumbers = new int[45];
        int[] jackpot = new int[6];
        int bonus = 0;
        String data = "";
        int weekday = 0;
        String[] temp = new String[9];
        while (in.hasNext()) {
            data = in.nextLine();
            temp = data.split(",");
            String firstyear = args[3];
            String secondyear = args[4];
            String datayear = temp[0];
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            Date first = df.parse(firstyear);
            Date second = df.parse(secondyear);
            Date datas = df.parse(datayear);
            weekday = convertDateToWeekDay(temp);
            if (weekday == day || day == 0)
                ;
            {
                if (temp[8].contentEquals(drawtype)
                        || drawtype.contentEquals("A")) {
                    if ((datas.equals(first)) || (datas.equals(second))
                            || ((datas.after(first)) && (datas.before(second)))) {
                        if (choice == 1 || choice == 2) {
                            for (int count = 0; count < jackpot.length; count++) {
                                jackpot[count] = Integer
                                        .parseInt(temp[count + 1]);
                                jackpotnumbers[jackpot[count] - 1]++;
                            }
                        }
                        if (choice == 2) {
                            bonus = Integer.parseInt(temp[7]);
                            if (temp[8].contentEquals(drawtype)
                                    || drawtype.contentEquals("A"))
                                bonusnumbers[bonus - 1]++;
                        }
                    }
                }
            }
        }
        in.close();
        Printing(args, jackpotnumbers, bonusnumbers, weekday);
    }

    public static int convertDateToWeekDay(String[] temp) {
        int result = 0;
        int a, b, d, m, y, dayOfWeek;
        String date = temp[0];
        String[] dates = date.split("/");
        d = Integer.parseInt(dates[0]);
        m = Integer.parseInt(dates[1]);
        y = Integer.parseInt(dates[2]);
        if (m == 1 || m == 2) {
            m += 12;
            y -= 1;
        }
        a = y % 100;
        b = y / 100;
        dayOfWeek = ((d + (((m + 1) * 26) / 10) + a + (a / 4) + (b / 4)) + (5 * b)) % 7;
        switch (dayOfWeek) {
        case 0:
            result = 2;
            break;
        case 4:
            result = 1;
            break;
        }
        return result;
    }

    public static void Printing(String[] args, int[] jackpotnumbers,
            int[] bonusnumbers, int choice) {
        String results = "";
        if (args.length == 1) {
            if (choice == 1) {
                results = "An Analysis of Jackpot Numbers for the entire file.\n\n";
                for (int counter = 0; counter < 45; counter++) {
                    int num = counter + 1;
                    results += num + " was a jackpot number "
                            + jackpotnumbers[counter] + "times.\n";
                }
            } else {
                results = "An Analsis of Bonus Numbers for the entire file.\n\n";
                for (int counter = 0; counter < 45; counter++) {
                    int num = counter + 1;
                    results += num + " was a bonus number "
                            + bonusnumbers[counter] + "times.\n";
                }
            }
        }
        if (args.length == 2) {
            if (choice == 1) {
                if ((args[1].toUpperCase()).contentEquals("A"))
                    results = "An Analysis of Jackpot Numbers for the entire file.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("R"))
                    results = "An Analysis of Jackpot Numbers for all regular draws.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("S"))
                    results = "An Analysis of Jackpot Numbers for all special draws.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("LP1"))
                    results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws.\n\n";
                else
                    results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws.\n\n";
                for (int counter = 0; counter < 45; counter++) {
                    int num = counter + 1;
                    results += num + " was a jackpot number "
                            + jackpotnumbers[counter] + "times.\n";
                }
            } else {
                if ((args[1].toUpperCase()).contentEquals("A"))
                    results = "An Analsis of Jackpot and Bonus Numbers for the entire file.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("R"))
                    results = "An Analysis of Jackpot and Bonus Numbers for all regular draws.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("S"))
                    results = "An Analysis of Jackpot and Bonus Numbers for all special draws.\n\n";
                else if ((args[1].toUpperCase()).contentEquals("LP1"))
                    results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws.\n\n";
                else
                    results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws.\n\n";
                for (int counter = 0; counter < 45; counter++) {
                    int num = counter + 1;
                    results += num + " was a bonus number "
                            + bonusnumbers[counter]
                            + "times and a jackpot number "
                            + jackpotnumbers[counter] + "times.\n";
                }
                if (args.length == 3) {
                    int numb = Integer.parseInt(args[2]);
                    if (choice == 1) {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analysis of Jackpot Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += "on Wednesday draws.\n\n";
                        else if (numb == 1)
                            results += " on Saturday draws.\n\n";
                        else
                            results += " for all draws.\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    } else {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += " on Wednesday draws.\n\n";
                        else if (numb == 1)
                            results += " on Saturday draws.\n\n";
                        else
                            results += " for all draws.\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a bonus number "
                                    + bonusnumbers[counter]
                                    + "times and a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    }
                }
                if (args.length == 5) {
                    int numb = Integer.parseInt(args[2]);
                    if (choice == 1) {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analysis of Jackpot Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += " on Wednesday draws\n\n";
                        else if (numb == 1)
                            results += " on Saturday draws\n\n";
                        else
                            results += " for all draws\n\n";
                        results += "for " + args[3] + ".\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    } else {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += " on Wednesday draws";
                        else if (numb == 1)
                            results += " on Saturday draws";
                        else
                            results += " for all draws";
                        results += "for " + args[3] + ".\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a bonus number "
                                    + bonusnumbers[counter]
                                    + "times and a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    }
                }
                if (args.length == 5) {
                    int numb = Integer.parseInt(args[2]);
                    if (choice == 1) {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analysis of Jackpot Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += " on Wednesday draws\n\n";
                        else if (numb == 1)
                            results += " on Saturday draws\n\n";
                        else
                            results += " for all draws\n\n";
                        results += "between " + args[3] + " and " + args[4]
                                + ".\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    } else {
                        if ((args[1].toUpperCase()).contentEquals("A"))
                            results = "An Analsis of Jackpot and Bonus Numbers for the entire file";
                        else if ((args[1].toUpperCase()).contentEquals("R"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all regular draws";
                        else if ((args[1].toUpperCase()).contentEquals("S"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all special draws";
                        else if ((args[1].toUpperCase()).contentEquals("LP1"))
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 1 draws";
                        else
                            results = "An Analysis of Jackpot and Bonus Numbers for all Lotto Plus 2 draws";
                        if (numb == 2)
                            results += " on Wednesday draws";
                        else if (numb == 1)
                            results += " on Saturday draws";
                        else
                            results += " for all draws";
                        results += "between " + args[3] + " and " + args[4]
                                + ".\n\n";
                        for (int counter = 0; counter < 45; counter++) {
                            int num = counter + 1;
                            results += num + " was a bonus number "
                                    + bonusnumbers[counter]
                                    + "times and a jackpot number "
                                    + jackpotnumbers[counter] + "times.\n";
                        }
                    }
                }
            }
        }
        JOptionPane.showMessageDialog(null, results, "Analysing the Lotto", 1);
    }
}

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM