Skip to content

Instantly share code, notes, and snippets.

Created June 24, 2016 18:13
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 anonymous/7250e8d177dfa065d8d82278a8ee1c74 to your computer and use it in GitHub Desktop.
Save anonymous/7250e8d177dfa065d8d82278a8ee1c74 to your computer and use it in GitHub Desktop.
import java.awt.Color;
public class Cat {
private String name;
private Color color;
private Double length;
private Double height;
private Double weight;
private Double strength;
public Cat() {
name = "noname";
color = Color.BLACK;
weight = 6.5;
length = 1.0;
height = 0.4;
strength = 0.5 * weight * length * height;
}
public Cat(String name, Color color, Double weight, Double length,
Double height) {
this.name = name;
this.color = color;
this.weight = weight;
this.length = length;
this.height = height;
strength = 0.5 * weight * length * height;
}
public String getName() {
return name;
}
public Boolean jumpTo(Furniture fur) {
if (fur.getHeight() < (10 * length * height * weight))
return true;
return false;
}
}
public abstract class Furniture {
private Color color;
private String material;
private Double length;
private Double height;
public Furniture(Color color, String material, Double length, Double height) {
this.setColor(color);
this.setMaterial(material);
this.setLength(length);
this.setHeight(height);
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material;
}
public Double getLength() {
return length;
}
public void setLength(Double length) {
this.length = length;
}
public Double getHeight() {
return height;
}
public void setHeight(Double height) {
this.height = height;
}
}
public class Table extends Furniture {
private Integer legs;
public Table(Integer legs, Color color, String material, Double length,
Double height) {
super(color, material, length, height);
this.legs = legs;
}
}
public class Run {
public static void main(String... args) {
Cat cat = new Cat();
Table table = new Table(4, Color.decode("#302013"), "Wood", 50., 30.);
System.out.println("Cat leap "
+ (cat.jumpTo(table)
? "successfully complited"
: "ended in failure"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment