Visual Studio Code Java:找不到符号(类名)?

时间:2017-11-12 12:36:36

标签: java

所以我有一个使用两个类的相对简单的程序。当我编译我想要运行的类时,我得到一个错误,说找不到符号" Fighter"这是我使用对象的类的名称。两个类都在同一个包中。 注意它在NetBeans中运行良好,但我更喜欢使用VSC。

这是我的代码。

我正在上课:

package project;

import java.util.ArrayList;
import java.util.Scanner;


public class Division
{
     public static Scanner scanner = new Scanner(System.in);

    public static void main(String args[])
    {


        ArrayList<Fighter> fighters = new ArrayList();

        fighters.add(new Fighter("Conor McGregor", 29, "Ireland", 21, 3));
        fighters.add(new Fighter("Gunnar Nelson", 28, "Iceland", 16, 3));
        fighters.add(new Fighter("Stipe Miocic", 33, "USA", 17, 2));
        fighters.add(new Fighter("Cody Garbrandt", 26, "USA", 11, 0));
        fighters.add(new Fighter("Demetrious Johnson", 30, "USA", 27, 2));
        fighters.add(new Fighter("Jose Aldo", 31, "Brazil", 26, 3));
        fighters.add(new Fighter("George St Pierre", 40, "Canada", 25, 2));
        fighters.add(new Fighter("Fabricio Werdum", 40, "Brazil", 22, 7));
        fighters.add(new Fighter("Michael Bisping", 39, "United Kingdom", 30, 7));


        displayAllFighters(fighters);


    }

    //Adds fighter to ArrayList
    public static void addFighter(ArrayList<Fighter> fighters)
    {
        System.out.print("Please enter fighters name: \t");
        String name = scanner.nextLine();

        System.out.print("\nPlease enter fighters age: \t");
        int age = scanner.nextInt();

        scanner.nextLine();

        System.out.print("\nPlease enter fighters country: \t");
        String country = scanner.nextLine();

        System.out.print("\nPlease enter amount of wins: \t");
        int wins = scanner.nextInt();

        System.out.print("\nPlease enter amount of losses: \t");
        int losses = scanner.nextInt();

        fighters.add(new Fighter(name, age, country, wins, losses));

        System.out.println("Fighter Added!");
    }

    //Removes a fighter from ArrayList
    public static void removeFighter(ArrayList<Fighter> fighters)
    {
        System.out.print("Please enter the name of the fighter you wish to remove: \t");
        String name = scanner.nextLine();

        for (Fighter fighter : fighters)
        {
            if (fighter.getName() == name)
            {
                fighters.remove(fighter);
            }
        }
    }

    public static void displayAllFighters(ArrayList<Fighter> fighters)
    {
        for (Fighter fighter : fighters)
        {
            System.out.println(fighter);
            System.out.println("==========================================");
        }
    }

    public static int countWinPercentLowerThan(ArrayList<Fighter> fighters , int value)
    {
        int count = 0;

        for (Fighter fighter : fighters)
        {
            if (fighter.getPercent() < value)
            {
                count++;
            }
        }
        return count;
    }

    public static int countWinPercentGreaterThan(ArrayList<Fighter> fighters , int value)
    {
        int count = 0;

        for (Fighter fighter : fighters)
        {
            if (fighter.getPercent() > value)
            {
                count++;
            }
        }
        return count;
    }

}

未被识别的班级。

package project;

public class Fighter
{
    private String name;
    private int age;
    private String country;
    private int wins;
    private int losses;

    public Fighter(String name, int age, String country, int wins, int losses)
    {
        this.name = name;
        this.age = age;
        this.country = country;
        this.wins = wins;
        this.losses = losses;
    }

    public Fighter(String name)
    {
        this.name = name;
        this.age = 0;
        this.country = "TBA";
        this.wins = 0;
        this.losses = 0;
    }

    public String getName()
    {
        return this.name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public int getAge()
    {
        return this.age;
    }

    public void setAge(int age)
    {
        this.age = age;
    }

    public String getCountry()
    {
        return this.country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public int getWins()
    {
        return this.wins;
    }

    public void setWins(int wins)
    {
        this.wins = wins;
    }

    public int getLosses()
    {
        return this.losses;
    }

    public void setLosses(int losses)
    {
        this.losses = losses;
    }

    public String toString()
    {
        return "Fighter Name: " + this.name + ".\nFighter age: " + this.age + ".\nFighter nation: " + this.country + ".\nFighter wins: " + this.wins + ".\nFighter losses: " + this.losses + ".";
    }

    public void updateWin()
    {
        this.wins++;
    }

    public void updateLosses()
    {
        this.losses++;
    }

    public double getPercent()
    {
        int totalFights = this.wins + this.losses;
        double percent = this.wins * 100/totalFights;
        return percent;
    }

}

先谢谢你了!

0 个答案:

没有答案