I';我有一些错误-Java程序

I';我有一些错误-Java程序,java,class,compiler-errors,cannot-find-symbol,Java,Class,Compiler Errors,Cannot Find Symbol,这真的很奇怪,我为这个程序编写了一个类,并准备测试它如何从文件中读取数据,但我得到了一个“找不到符号”错误,它指的是第一个扫描器中的“新”。第二个Scanner变量中的“=”也会出现同样的错误,并且稍后会有一组无法找到所有“候选信息[i]”对象的符号。我不知道我的错误在哪里。顺便说一下,我正在使用记事本+,也在使用记事本++编译和运行它 import java.util.Scanner; //I'm only gonna need scanner for this project I think

这真的很奇怪,我为这个程序编写了一个类,并准备测试它如何从文件中读取数据,但我得到了一个“找不到符号”错误,它指的是第一个扫描器中的“新”。第二个Scanner变量中的“=”也会出现同样的错误,并且稍后会有一组无法找到所有“候选信息[i]”对象的符号。我不知道我的错误在哪里。顺便说一下,我正在使用记事本+,也在使用记事本++编译和运行它

import java.util.Scanner; //I'm only gonna need scanner for this project I think
import java.io.*;

public class HuntowskiSamuel //This is what the file name should be as well as the class name
{
    public static void main (String [] args) throws IOException
    {
    File CFile = new File("cipcs115.txt"); //This will be the file and scanner variable used to pull the data for the candidates
    Scanner scan = new Scanner(Cfile);

    File CfileReadIn = new File("cipcs115.txt"); //While this file and scanner will be used to pull the number of candidates from the same file...hopefully
    Scanner scanReadIn = new Scanner(CFileReadIn);

    String StateName = "No name yet"; //This is where the state value will be held, that controls the input of the file
    int NumberOfCandidates = 0; // This will pull the number of candidates for the array size
    String garbage = "Empty"; //This is where the ReadIn scanner can dump excess stuff

    StateName = scanReadIn.next(); //The prime read for the while loop

    int NumberOfLettersEntered [] = new int [8]; //Since we only have the letters L, C, V, S, D, P, Q, and X (others/errors) that were entered, IN THAT ORDER. Its not graceful but it works

    while(StateName != "END_OF_FILE") //While we haven't reached the end of the file
    {
        for(int i = scanReadIn.nextInt(); i > 0; i--) //Read in the number of candidates, then run the loop that number of times
        {
            NumberOfCandidates++; //Every time this loop runs, it means there is one more candidate for the total amount
            garbage = scanReadIn.nextLine(); //This will take all the important info and dump it, seeing as we only need the number of candidates and the state name
        }
        StateName = scanReadIn.next(); //Pull the next state name
    }

    Candidate_Info Candidates [] = new Candidate_Info [NumberOfCandidates]; //This creates an array of the exact size of the number of candidates in the file

    for(int i = 0; i < NumberOfCandidates; i++) //Running the constructor for each and every candidate created
    {
        Candidate_Info [i] = Candidate_Info();
    }

    StateName = scan.next(); //Prime read for the data taking loop

    while(StateName != "END_OF_FILE") //The same as the other loop, only using the real file and scanner variables
    {
        int CandidateNumber = 0; //This will keep the array number straight from 0 to however many candidates - 1

        for(int i = 0; i < scan.nextInt(); i++) //This will loop for each of the candidates in ONE STATE, it pulls the number of candidates as an int
        {
            Candidate_Info[CandidateNumber].setState(StateName);
            Candidate_Info[CandidateNumber].setName(scan.next());
            Candidate_Info[CandidateNumber].setOffice(scan.next());
            Candidate_Info[CandidateNumber].setParty(scan.next().charAt(0)); //This might not work because it is just a single character versus the string that it would be passed
            Candidate_Info[CandidateNumber].setVotes(scan.nextInt());
            Candidate_Info[CandidateNumber].setSpent(scan.nextDouble());
            Candidate_Info[CandidateNumber].setMotto(scan.nextLine());
            CandidateNumber++;
        }
        StateName = scan.next();
    }
}
}
import java.util.Scanner//我想这个项目只需要扫描仪
导入java.io.*;
公共类HuntowskiSamuel//这是文件名和类名的名称
{
公共静态void main(字符串[]args)引发IOException
{
File CFile=new File(“cipcs115.txt”);//这将是用于提取候选数据的文件和扫描变量
扫描仪扫描=新扫描仪(Cfile);
File CfileReadIn=new File(“cipcs115.txt”);//而此文件和扫描程序将用于从同一文件中提取候选文件的数量……希望如此
Scanner scanReadIn=新扫描仪(CFileReadIn);
String StateName=“还没有名字”;//这是保存状态值的位置,用于控制文件的输入
int NumberOfCandidates=0;//这将提取数组大小的候选数量
String garbage=“Empty”//这是ReadIn扫描程序可以转储多余内容的地方
StateName=scanReadIn.next();//while循环的主读取
int NumberOfLettersEntered[]=new int[8];//因为我们只有按顺序输入的字母L、C、V、S、D、P、Q和X(其他/错误)。这并不优雅,但它可以工作
while(StateName!=“文件的结尾”)//当我们还没有到达文件的结尾时
{
for(int i=scanReadIn.nextInt();i>0;i--)//读取候选数量,然后运行该数量的循环
{
NumberOfCandidates++;//每次运行此循环时,意味着总量中还有一个候选项
垃圾=scanReadIn.nextLine();//这将获取所有重要信息并将其转储,因为我们只需要候选数量和州名称
}
StateName=scanReadIn.next();//提取下一个状态名
}
Candidate_Info Candidates[]=new Candidate_Info[NumberOfCandidates];//这将创建一个数组,其中包含文件中候选数量的精确大小
for(int i=0;i
这是我编写的类的代码

//Samuel James Huntowski
// started: 11-18-2014
// last modified: 11-18-2014

public class Candidate_Info
{
private String State; //All the variables that were given to me in the specification
private String Name_of_Candidate; 
private String Election_Office;
private char Party;
private int Number_of_Votes;
private double Dollars_Spent;
private String Motto;

private final double DOLLARS_SPENT_MIN = 0.0; //Mutator method for Dollars_Spent must check to see if greater then this value

private final int NUMBER_OF_ATTRIBUTES = 7; //for use in the equals method

public Candidate_Info()
{
    State = "No state assigned"; //Giving empty values to all of the variables
    Name_of_Candidate = "No name yet"; 
    Election_Office = "No office assigned";
    Party = 'X';
    Number_of_Votes = 0;
    Dollars_Spent = 0.0;
    Motto = "No motto yet";
}

//These are all of the Accessor Methods 

public String getState()
{
    return State;
}

public String getName()
{
    return Name_of_Candidate;
}

public String getOffice()
{
    return Election_Office;
}

public char getParty()
{
    return Party;
}

public int getVotes()
{
    return Number_of_Votes;
}

public double getSpent()
{
    return Dollars_Spent;
}

public String getMotto()
{
    return Motto;
}

//Mutator methods will go here

public void setState(String newState)
{
    State = newState;
    System.out.println("The candidate's state is now set to " + newState + ".");
}

public void setName(String newName)
{
    Name_of_Candidate = newName;
    System.out.println("The candidate's name is now set to " + newName + ".");
}

public void setOffice(String newOffice)
{
    Election_Office = newOffice;
    System.out.println("The candidate's office is now set to " + newOffice + ".");
}

public void setParty(char newParty)
{
    if(!((newParty == 'd') || (newParty == 'r') || (newParty == 'i') || (newParty == 'o'))) //If the value of newParty DOES NOT EQUAL 'o', 'd', 'r', or 'i' then do the next set of code
    {
        System.out.println("Invalid party input. Candidate's party remains unchanged. Please try again.");
    }
    else
    {
        Party = newParty;
        System.out.println("The candidate's party is now set to " + newParty + ".");
    }
}

public void setVotes(int newNumberOfVotes)
{
    Number_of_Votes = newNumberOfVotes;
    System.out.println("The candidate's number of votes is now set to " + newNumberOfVotes + ".");
}

public void setSpent(double newDollarsSpent)
{
    if(newDollarsSpent < DOLLARS_SPENT_MIN) //If the amount of money spent is less then zero (Which just wouldn't make sense, so that's why I set the variable to zero)
    {
        System.out.println("New amount of dollars spent is invalid. Candidate's dollars spent remains unchanged. Please try again.");
    }
    else
    {
        Dollars_Spent = newDollarsSpent;
        System.out.println("The candidate's dollars spent is now set to " + newDollarsSpent + ".");
    }
}

public  void setMotto(String newMotto)
{
    Motto = newMotto;
    System.out.println("The candidate's motto is now set to \"" + newMotto + "\"");
}

public void displayAll()
{
    System.out.println(State + "\t" + Name_of_Candidate + "\t" 
    + Election_Office + "\t" + 
    Party + "\t" + Number_of_Votes + 
    "\t" + Dollars_Spent + "\t" + Motto); //Display all info separated by tabs
}

public String toString()
{
    String ReturnThis = (State + "\t" + Name_of_Candidate + "\t" + 
    Election_Office + "\t" + Party + 
    "\t" + Number_of_Votes + "\t" + 
    Dollars_Spent + "\t" + Motto); //same as displayAll() just in one string

    return ReturnThis;
}

public boolean equals(Candidate_Info PassedCandidate)
{
    boolean TF [] = new boolean [NUMBER_OF_ATTRIBUTES]; //An array of booleans that match the number of attributes above

    boolean finalResult; //This will hold the final boolean result of all the below calculations

    if(State.equals(PassedCandidate.getState())) TF[0] = true; //This isn't the most graceful method of doing this, but it works
    else TF[0] = false;

    if(Name_of_Candidate.equals(PassedCandidate.getName())) TF[1] = true;
    else TF[1] = false;

    if(Election_Office.equals(PassedCandidate.getOffice())) TF[2] = true;
    else TF[2] = false;

    if(Party == PassedCandidate.getParty()) TF[3] = true;
    else TF[3] = false;

    if(Number_of_Votes == PassedCandidate.getVotes()) TF[4] = true;
    else TF[4] = false;

    if(Dollars_Spent == PassedCandidate.getSpent()) TF[5] = true;
    else TF[5] = false;

    if(Motto.equals(PassedCandidate.getMotto())) TF[6] = true;
    else TF[6] = false;

    if(TF[0] && TF[1] && TF[2] && TF[3] && TF[4] && TF[5] && TF[6]) finalResult = true; //If ALL OF THE ATTRIBUTES equal the attributes of the passed candidate, therefore making all the TF variables true, then they are equal
    else finalResult = false;

    return finalResult;
}
}
//塞缪尔·詹姆斯·亨托夫斯基
//开始日期:2014年11月18日
//最后修改日期:2014年11月18日
公开课考生信息
{
私有字符串状态;//规范中提供给我的所有变量
_候选者的私有字符串名称_;
私人选举办公室;
私人党;
私人整数票数;
私人双美元支出;
私人弦乐格言;
private final double double double double double double double double double double double double double double double double double double double double double double double double double double doub
私有final int NUMBER_OF_ATTRIBUTES=7;//用于equals方法
公开候选人信息()
{
State=“No State assigned”;//为所有变量提供空值
Name\u of_Candidate=“还没有名字”;
选举办公室=“未分配办公室”;
党='X';
投票数=0;
花费的美元=0.0;
座右铭=“还没有座右铭”;
}
//这些都是访问器方法
公共字符串getState()
{
返回状态;
}
公共字符串getName()
{
返回候选人的姓名;
}
公共字符串getOffice()
{
选举办公室;
}
公共党()
{
返回方;
}
公众投票
{
返回投票数;
}
公共双getexplored()
{
归还花费的美元;
}
公共字符串getmont()
{
回归座右铭;
}
//这里将使用Mutator方法
公共void设置状态(字符串newState)
{
状态=新闻状态;
System.out.println(“候选人的状态现在设置为“+newState+”);
}
public void setName(字符串newName)
{
候选人的姓名=新姓名;
System.out.println(“候选人的姓名现在设置为“+newName+”);
}
公共无效设置办公室(字符串新办公室)
{
选举办公室=新办公室;
System.out.println(“候选人的办公室现在设置为“+newOffice+”);
}
公共无效设置方(char newParty)
{
if(!((newParty=='d')| |(newParty=='r')| |(newParty=='i')| |(newParty=='o'))//如果newParty的值不等于'o'、'd'、'r'或'i',则执行下一组代码
{
System.out.println(“无效的参与方输入。候选人的参与方保持不变。请重试”);
}
其他的
{
政党=新政党;
System.out.println(“
import java.util.Scanner; //I'm only gonna need scanner for this project I think
import java.io.*;

public class HuntowskiSamuel //This is what the file name should be as well as the class name
{
    public static void main (String [] args) throws IOException
    {
    File cFile = new File("cipcs115.txt"); //This will be the file and scanner variable used to pull the data for the candidates
    Scanner scan = new Scanner(cFile);

    File cFileReadIn = new File("cipcs115.txt"); //While this file and scanner will be used to pull the number of candidates from the same file...hopefully
    Scanner scanReadIn = new Scanner(cFileReadIn);

    String stateName = "No name yet"; //This is where the state value will be held, that controls the input of the file
    int numberOfCandidates = 0; // This will pull the number of candidates for the array size
    String garbage = "Empty"; //This is where the ReadIn scanner can dump excess stuff

    stateName = scanReadIn.next(); //The prime read for the while loop

    int numberOfLettersEntered [] = new int [8]; //Since we only have the letters L, C, V, S, D, P, Q, and X (others/errors) that were entered, IN THAT ORDER. Its not graceful but it works

    while(stateName != "END_OF_FILE") //While we haven't reached the end of the file
    {
        for(int i = scanReadIn.nextInt(); i > 0; i--) //Read in the number of candidates, then run the loop that number of times
        {
            numberOfCandidates++; //Every time this loop runs, it means there is one more candidate for the total amount
            garbage = scanReadIn.nextLine(); //This will take all the important info and dump it, seeing as we only need the number of candidates and the state name
        }
        stateName = scanReadIn.next(); //Pull the next state name
    }

    Candidate_Info candidates [] = new Candidate_Info [numberOfCandidates]; //This creates an array of the exact size of the number of candidates in the file

    for(int i = 0; i < numberOfCandidates; i++) //Running the constructor for each and every candidate created
    {
        candidates[i] = new Candidate_Info();
    }

    stateName = scan.next(); //Prime read for the data taking loop

    while(stateName != "END_OF_FILE") //The same as the other loop, only using the real file and scanner variables
    {
        int candidateNumber = 0; //This will keep the array number straight from 0 to however many candidates - 1

        for(int i = 0; i < scan.nextInt(); i++) //This will loop for each of the candidates in ONE STATE, it pulls the number of candidates as an int
        {
            candidates[candidateNumber].setState(stateName);
            candidates[candidateNumber].setName(scan.next());
            candidates[candidateNumber].setOffice(scan.next());
            candidates[candidateNumber].setParty(scan.next().charAt(0)); //This might not work because it is just a single character versus the string that it would be passed
            candidates[candidateNumber].setVotes(scan.nextInt());
            candidates[candidateNumber].setSpent(scan.nextDouble());
            candidates[candidateNumber].setMotto(scan.nextLine());
            candidateNumber++;
        }
        stateName = scan.next();
    }
}
}