xlnc
xlnc

Reputation: 47

Cannot find symbol error

thank you in advance for helping out with this relatively simple (I hope) problem that I seem to be encountering. whenever I try to compile my programming assignment, I am met with a "cannot find symbol error." I point out where the error occurs in the code itself. Thanks again!

    public class SSN
{
    private int one;
    private int two;
    private int three;

    public SSN(int first, int second, int third) throws Exception
    {
        if(first > 99 || first < 1 || second > 999 || second < 1 || third > 9999 || third < 1)
        {

        }
        else
        {
            one = first;
            two = second;
            three = third;
        }
    }

    //method that turns ###-##-#### string into 3 int SSN object
    public static SSN valueOf(String ssn)
    {

    String firstpart;
    firstpart = ssn.substring(0, 2);
    String secondpart;
    secondpart = ssn.substring(4, 5);
    String thirdpart;
    thirdpart = ssn.substring(7, 10);

    int One = Integer.parseInt(firstpart);
    int Two = Integer.parseInt(secondpart);
    int Three = Integer.parseInt(thirdpart);

    System.out.println(firstpart);

        //This is where the cannot find symbol error occurs (return SSN(One, Two, Three),                                       //and I am clueless as to why.
        //Any insight as to why this error is occurring would be much appreciated!

    return SSN(One, Two, Three);
    }


    public String toString()
    {
        return one + "-" + two + "-" + three;
    }

}

Upvotes: 0

Views: 702

Answers (3)

OscarRyz
OscarRyz

Reputation: 199324

The compiler si looking for a method named "SSN" but there is not such method ( the compiler can't find that symbol ) You were trying to create a new object not invoking a method thus you need to inlcude the new keyword as Erik and SLaks said.

return new SSN( One, Two, Three );

Upvotes: 0

Erik
Erik

Reputation: 91330

return new SSN(One, Two, Three);
       ^^^

Upvotes: 1

SLaks
SLaks

Reputation: 888107

You're trying to create a new SSN(...) by calling the constructor.

Upvotes: 0

Related Questions