S
Spellsleeper
Gast
Ich frage mich warum, wenn ich die Methode getWertPerCent/getGewichtPerCent (Das Denglisch ist nicht schön ich weiß, ist auch nur ein Prototyp) den Wert Infinity zurückgibt
Java:
package Data;
import java.util.ArrayList;
import java.util.Collections;
public class Kofferraum extends ArrayList<Koffer> {
private int kofferAnzahl, gewicht, wert;
private double verhaeltnis,gewichtPerCent,wertPerCent;
@Override
public boolean add(Koffer e) {
boolean b = super.add(e);
Collections.sort(this);
calcVals();
return b;
}
@Override
public boolean remove(Object o) {
Koffer e = (Koffer) o;
boolean b = super.remove(e);
Collections.sort(this);
calcVals();
return b;
}
@Override
public void clear() {
super.clear();
calcVals();
}
public void dispenseKoffer(int id, Kofferraum kr) {
kr.add(this.get(id));
this.remove(this.get(id));
}
public int getKofferAnzahl() {
return this.kofferAnzahl;
}
public int getGewicht() {
return this.gewicht;
}
public int getWert() {
return this.wert;
}
public double getVerhaeltnis() {
return this.verhaeltnis;
}
public double getWertPerCent() {
return this.wertPerCent;
}
public double getGewichtPerCent() {
return this.gewichtPerCent;
}
private void calcVals() {
int weight = 0, val = 0, quantity = 0;
for (Koffer k : this) {
weight += k.getGewicht();
val += k.getWert();
quantity++;
}
this.gewicht = weight;
this.wert = val;
this.kofferAnzahl = quantity;
this.verhaeltnis = (double) val / weight;
this.gewichtPerCent=(double)gewicht/((double)Transporter.gesammtGewicht/100);
this.wertPerCent=(double)wert/((double)Transporter.gesammtWert/100);
}
}
Java:
package Data;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
public class Transporter {
private Kofferraum linkerKofferraum;
private Kofferraum rechterKofferraum;
public static int gesammtWert,gesammtGewicht,gesammtKofferAnzahl,maxWertDiff=10000;
public static double maxWertDiffPerCent;
public Transporter(Kofferraum lKofferraum,Kofferraum rKofferraum){
this.linkerKofferraum=lKofferraum;
this.rechterKofferraum=rKofferraum;
this.gesammtWert=lKofferraum.getWert()+rKofferraum.getWert();
this.gesammtGewicht=lKofferraum.getGewicht()+rKofferraum.getGewicht();
this.maxWertDiffPerCent=(float)maxWertDiff/((float)gesammtWert/100);
this.gesammtKofferAnzahl=lKofferraum.getKofferAnzahl()+rKofferraum.getKofferAnzahl();
//Alle Koffer werden in den linken Kofferraum verfrachtet
while(rKofferraum.getKofferAnzahl()>0){
rKofferraum.dispenseKoffer(0, lKofferraum);
}
int[] ia=filterOptimumCombi();
}
//Ab hier wird noch gearbeitet
public int[] filterOptimumCombi(){
int[] bestCombi=null;
ArrayList<Kofferraum>possibleCombis=new ArrayList<Kofferraum>();
for(int i=0;i<linkerKofferraum.size();i++){
Kofferraum kr=new Kofferraum();
kr.add(linkerKofferraum.get(linkerKofferraum.size()-1));
}
for(Kofferraum kr:possibleCombis){
System.out.println(kr.getWertPerCent());
}
return bestCombi;
}
}