Skip to content

Instantly share code, notes, and snippets.

@QuanSai
Created November 20, 2012 04:45
Show Gist options
  • Save QuanSai/4116109 to your computer and use it in GitHub Desktop.
Save QuanSai/4116109 to your computer and use it in GitHub Desktop.
Klingon Species for girl
package joanna;
public class Joanna
{
public static void main (String [] args)
{
Species s1 = new Species(), s2 = new Species();
s1.setSpecies("Klingon Ox", 10, 15);
s2.setSpecies("Klingon Ox", 10, 15);
testEqualsOperator(s1,s2);
testEqualsMethod(s1,s2);
System.out.println("Now change one Klingon Ox.");
s2.setSpecies("klingon ox", 10, 15);
testEqualsMethod(s1,s2);
}
private static void testEqualsOperator(Species s1, Species s2)
{
if (s1 == s2)
System.out.println("Match with ==.");
else
System.out.println("Do Not match with ==.");
}
private static void testEqualsMethod (Species s1, Species s2)
{
if (s1.equals(s2))
System.out.println("Match with the method equals.");
else
System.out.println("Do Not match with the method equals.");
}
}
package joanna;
public class Species
{
String name;
int nNum1, nNum2;
public void setSpecies(String klingon_name, int num1, int num2)
{
this.name = klingon_name;
this.nNum1 = num1;
this.nNum2 = num2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment