班级不被认可

时间:2015-10-08 00:10:09

标签: java class compilation

我创建了一个方法类,用于测试月份和日期,并告诉您季节是什么。我创建了一个测试人员类,但出于某种原因,它不会从方法中识别getSeason()类,但它显示它们是连接的。

方法代码:

public class Season {
    private String season;

    public String getSeason(int month, int day) {
        if (month == 1 || month == 2 || month == 3) {
            season = "Winter";
        } else if (month == 4 || month == 5 || month == 6) {
            season = "Spring";
        } else if (month == 7 || month == 8 || month == 9) {
            season = "Summer";
        } else if (month == 10 || month == 11 || month == 12) {
            season = "Fall";
        }

        if (month % 3 == 0 && day >= 21) {
            if (season.equals("Winter")) {
                season = "Spring";
            } else if (season.equals("Spring")) {
                season = "Summer";
            } else if (season.equals("Summer")) {
                season = "Fall";
            } else {
                season = "Winter";
            }
        }
        return season;
    }
}

测试员代码:

import java.util.Scanner;

public class SeasonTester {
    public static void main(String[] args) {
        Season s = new getSeason();
        Scanner input = new Scanner(System.in);
    }
}

编译时,无法获取符号 - 类getSeason 错误

1 个答案:

答案 0 :(得分:0)

你在这里调用方法而不是构造函数:

    Season s = new getSeason();

应该是

    Season s = new Season();

然后你可以用这个来调用isntance方法:

s.getSeason();