Hallo zusammen ich hänge gerade bei einer Umsetzung die ich mir selber überlegt habe.
Ich habe eine Klasse Properties:
Eine Klasse Organ:
Und eine Klasse Heart die von Organ erbt:
Wie kann ich in der Klasse Heart über Properties bei dem Attribut "weight" den Wert 300 zuweisen? Ich müsste ja nur was in der Klasse Heart dazu schreiben oder? Nur ich komme leider nicht darauf
. Hoffe mir kann jemand weiterhelfen
Ich habe eine Klasse Properties:
Java:
public class Properties {
protected String name = "";
protected int weight = 0;
protected String health = "";
protected String dnaSequence = "";
public Properties(String name, int weight, String health
, String dnaSequence ){
this.name = name;
this.weight = weight;
this.health = health;
this.dnaSequence = dnaSequence;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getHealth() {
return health;
}
public void setHealth(String health) {
this.health = health;
}
public String getDnaSequence() {
return dnaSequence;
}
public void setDnaSequence(String dnaSequence) {
this.dnaSequence = dnaSequence;
}
}
Eine Klasse Organ:
Java:
public abstract class Organ {
protected boolean transplantable = false;
protected boolean transplanted = false;
protected Properties properties;
public Organ(boolean transplantable, boolean transplanted,
Properties properties){
this.transplantable = transplantable;
this.transplanted = transplanted;
this.properties = properties;
}
public boolean isTransplantable() {
return transplantable;
}
public void setTransplantable(boolean transplantable) {
this.transplantable = transplantable;
}
public boolean isTransplanted() {
return transplanted;
}
public void setTransplanted(boolean transplanted) {
this.transplanted = transplanted;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
}
Und eine Klasse Heart die von Organ erbt:
Java:
public class Heart extends Organ{
public Heart(boolean transplantable, boolean transplanted,
Properties properties) {
super(transplantable, transplanted, properties);
}
}
Wie kann ich in der Klasse Heart über Properties bei dem Attribut "weight" den Wert 300 zuweisen? Ich müsste ja nur was in der Klasse Heart dazu schreiben oder? Nur ich komme leider nicht darauf