public class
Shoe implements Comparable
{
private
String brand;
private
int size;
private
String colour;
//Creates a
random shoe
public
Shoe()
{
String[] brands = {"Nike", "Adidas",
"Puma", "Reebok", "New Balance"};
String[] colours = {"Blue",
"Pink", "Yellow", "Teal", "White", "Black"};
brand =
brands[(int)(Math.random()
* brands.length)];
colour = colours[(int)(Math.random() * colours.length)];
size =
(int)(Math.random()*8)
+ 6; //6-13
}
public
String toString()
{
return
brand + ", " + colour + ", Size:
" + size;
}
public
String getBrand()
{
return
brand;
}
public
int getSize()
{
return
size;
}
public
String getColour()
{
return
colour;
}
@Override
public int compareTo(Object o)
{
Shoe
other = (Shoe)o;
if (!this.brand.equals(other.brand))
return this.brand.compareTo(other.brand);
else //same brands, so sort by shoe size
{
return ((Integer)this.size).compareTo(other.size); //clever
}
}
}
|