java - 我的 java 程序给了我 99 个错误

标签 java error-handling compiler-errors

我对编程相当陌生。我目前正在大学第一年学习 java。我得到了一个 java 小组项目。我的项目部分给了我 96 个不同的错误,但给出的错误实际上没有一个是错误的该项目接受 1 到 7 个命令行参数。然后,它根据输入的内容执行不同的操作。它总体分析代表乐透的文件的不同部分。我使用命令行编译我的程序。如果需要,我可以发布所有错误。首先,这是我的整个代码,但我必须取出一个方法,以便它适合一篇文章。我取出的方法没有错误,因为我已经检查过。这是参数方法。

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);   
  }
}

我对长代码感到抱歉,但我不知道实际问题出在哪里。我也很抱歉它没有评论,最终版本将是。由于性格原因,我无法在这里发布所有错误限制。我如何向您显示错误是什么。有 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]);

如果您需要更多信息,请询问。任何帮助将不胜感激,因为我不知道现在该怎么做,而且我无法再次编写所有代码,因为该项目将于周二到期。

最佳答案

是的,你的代码看起来很困惑,看起来就像你在记事本上完成的,然后在 cmd 或其他东西中运行它,无论如何我能够删除语法错误。希望其他 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);
    }
}

祝你好运

关于java - 我的 java 程序给了我 99 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22413668/

相关文章:

java - 在 Swift 中使用反向传播的简单神经网络

java - 从自定义Listview中获取所有ImageView

java - 锁定一个方法直到另一个方法完成

c# - 无法反序列化值时,如何导致反序列化失败?

c - Flex 中的链接未完成问题

java - 有没有办法在构建 fragment 后调用方法?

cocoa - 现代 Cocoa 应用程序中的错误处理

完全导入时的 Solr 错误

asp.net - 在新计算机上编译ASP.NET网站时无法生成代码错误

compiler-errors - 为什么我的第一个使用dev-c++的程序无法正常工作?