mardi 29 septembre 2015

If Else: String Equality (Java)

Lab Description : Compare two strings to see if each of the two strings contains the same letters in the same order.

This is what I have so far far:

import static java.lang.System.*;

public class StringEquality
{
    private String wordOne, wordTwo;

    public StringEquality()
    {
    }

    public StringEquality(String one, String two)
    {
        setWords (wordOne, wordTwo);
    }

    public void setWords(String one, String two)
    {
        wordOne = one;
        wordTwo = two;
    }

    public boolean checkEquality()
    {
        if (wordOne == wordTwo)
        return true;
        else
        return false;
    }

    public String toString()
    {
        String output = "";
        if (checkEquality())
        output += wordOne + " does not have the same letters as " + wordTwo;
        else
        output += wordOne + " does have the same letters as " + wordTwo;
        return output;
    }

}

My runner looks like this:

import static java.lang.System.*;
public class StringEqualityRunner
{
    public static void main(String args[])
    {
        StringEquality test = new StringEquality();

        test.setWords(hello, goodbye);
        out.println(test);


    }
}

Everything is compiling except for the runner. It keeps saying that hello and goodbye aren't variables.

How can I fix this so that the program does not read hello and goodbye as variables, but as Strings?

Aucun commentaire:

Enregistrer un commentaire