Skip to content

Instantly share code, notes, and snippets.

@parisbutterfield
Created May 12, 2016 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parisbutterfield/0b623544755f5f3c72e0d3fb37759e0b to your computer and use it in GitHub Desktop.
Save parisbutterfield/0b623544755f5f3c72e0d3fb37759e0b to your computer and use it in GitHub Desktop.
HBCExample.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
//Shoe size - 5 color is Brown
//Shoe size - 6 color is White
//Shoe size - 9 color is Black
//Shoe size - 10 color is Orange
//Shoe size - 12 color is Purple
//Shoe size - 12 color is Yellow
//Shoe size - 15 color is Blue
//Shoe size - 15 color is Blue
//Shoe size - 15 color is Red
//Shoe size - 17 color is Tan
//Clothing size - L color is Black
//Clothing size - L color is Brown
//Clothing size - L color is Red
//Clothing size - L color is White
//Clothing size - M color is Orange
//Clothing size - M color is Tan
//Clothing size - S color is Yellow
//Clothing size - XL color is Purple
//Clothing size - XXL color is Blue
//Clothing size - XXXL color is Blue
public class HBCExample {
public static void main (String [] args) {
HBCExample example = new HBCExample();
List <Shoe> shoes = new ArrayList<Shoe>();
shoes.add(example.new Shoe("Blue", 15));
shoes.add(example.new Shoe("Red", 15));
shoes.add(example.new Shoe("Yellow", 12));
shoes.add(example.new Shoe("Orange", 10));
shoes.add(example.new Shoe("Purple", 12));
shoes.add(example.new Shoe("White", 6));
shoes.add(example.new Shoe("Brown", 5));
shoes.add(example.new Shoe("Tan", 17));
shoes.add(example.new Shoe("Black", 9));
shoes.add(example.new Shoe("Blue", 15));
List <Clothing> clothing = new ArrayList<Clothing>();
clothing.add(example.new Clothing("Blue", "XXL"));
clothing.add(example.new Clothing("Red", "L"));
clothing.add(example.new Clothing("Yellow", "S"));
clothing.add(example.new Clothing("Orange", "M"));
clothing.add(example.new Clothing("Purple", "XL"));
clothing.add(example.new Clothing("White", "L"));
clothing.add(example.new Clothing("Brown", "L"));
clothing.add(example.new Clothing("Tan", "M"));
clothing.add(example.new Clothing("Black", "L"));
clothing.add(example.new Clothing("Blue", "XXL"));
Collections.sort(shoes, new Comparator() {
public int compare(Object o1, Object o2) {
Integer x1 = ((Shoe) o1).getNumSize();
Integer x2 = ((Shoe) o2).getNumSize();
int sComp = x1.compareTo(x2);
if (sComp != 0) {
return sComp;
} else {
String x3 = ((Shoe) o1).getColor();
String x4 = ((Shoe) o2).getColor();
return x3.compareTo(x4);
}
}
});
Collections.sort(clothing, new Comparator() {
public int compare(Object o1, Object o2) {
String x1 = ((Clothing) o1).getTextSize();
String x2 = ((Clothing) o2).getTextSize();
int sComp = x1.compareTo(x2);
if (sComp != 0) {
return sComp;
} else {
String x3 = ((Clothing) o1).getColor();
String x4 = ((Clothing) o2).getColor();
return x3.compareTo(x4);
}
}
});
for (Object s : shoes.toArray()) {
System.out.println( "Shoe size - " + ((Shoe)s).getNumSize() + " color is " + ((Shoe)s).getColor());
}
for (Object s : clothing.toArray()) {
System.out.println( "Clothing size - " + ((Clothing)s).getTextSize() + " color is " + ((Clothing)s).getColor());
}
}
class Clothing extends Product {
public Clothing(String color, String size) {
this.setColor(color);
this.setTextSize(size);
}
public String getType() {
return "CLOTHING";
}
}
class Shoe extends Product {
public Shoe(String color, int size) {
// TODO Auto-generated constructor stub
this.setNumSize(size);
this.setColor(color);
}
public String getType() {
return "SHOE";
}
}
abstract class Product {
private String color;
private int numSize;
private String textSize;
public String getType;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getNumSize() {
return numSize;
}
public void setNumSize(int numSize) {
this.numSize = numSize;
}
public String getTextSize() {
return textSize;
}
public void setTextSize(String textSize) {
this.textSize = textSize;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment