Hallo,
habe foglendes Problem:
Und zwar wird bei meinem Programm der Inhalt des Hashtables nicht ausgegeben. Nur folgendes:
saft@82ba41
saft@923e39
saft@130c19b
usw.
Also die Werte nach "Orangensaft" kann man ja nicht ausgeben?
Aber wie schaffe ich es das die Saftarten Orangensaft, Apfelsaft usw. ausgegeben werden?
Kann mir jemand helfen?
habe foglendes Problem:
Und zwar wird bei meinem Programm der Inhalt des Hashtables nicht ausgegeben. Nur folgendes:
saft@82ba41
saft@923e39
saft@130c19b
usw.
Code:
import java.util.*;
import IOTools.*;
class saft {
private String typ; private double vol, preis;
public saft (String typ, double vol, double preis){
this.typ = typ;
this.vol = vol;
this.preis = preis;
}
public String getTyp(){
return typ;
}
public double getVol(){
return vol;
}
public double getPreis(){
return preis;
}
}
public class Saftladen_Neu {
private double ges_vol, ges_preis;
public void bestellen(Hashtable sortiment) {
System.out.print("Welchen Saft?:\t");
String typ = ReadSimple.readString();
if (sortiment.get(typ) != null){
saft current = (saft)sortiment.get(typ); // Hilfsvariable (geht ohne new ?)
System.out.print("Wieviel Flaschen ?:\t");
int anzahl = Integer.parseInt(ReadSimple.readString()); // mit der scheiß ReadInteger gibts Bugs
ges_vol = ges_vol + (anzahl*current.getVol());
ges_preis = ges_preis + (anzahl*current.getPreis());
}
else
System.out.println("Den Saft hamma ned.");
System.out.print("Weitere Saefte kaufen (j/n) ?");
if ((ReadSimple.readString()).equalsIgnoreCase("J"))
bestellen(sortiment);
else
System.out.println("Gesamt-Menge: "+ges_vol+" Liter\nGesamtpreis: "+ges_preis+" eur");
}
public static void main (String []args){
Hashtable my_sortiment = new Hashtable();
my_sortiment.put("Orangensaft", new saft("Orangensaft", 0.75 , 0.89));
my_sortiment.put("Apfelsaft", new saft("Apfelsaft", 1.0 , 1.29));
my_sortiment.put("Tomatensaft", new saft("Tomatensaft", 0.5 , 0.75));
my_sortiment.put("Multivitaminsaft", new saft("Multivitaminsaft", 0.7 , 1.19));
System.out.println ("Folgende Saefte habe wir im Angebot: \n");
for (Enumeration e = my_sortiment.elements();
e.hasMoreElements () ;) {
System.out.print (e.nextElement());
if (e.hasMoreElements ())
System.out.println (" ");
else
System.out.println ();
}
Saftladen_Neu mcd_Juices = new Saftladen_Neu();
mcd_Juices.bestellen(my_sortiment);
}
}
Aber wie schaffe ich es das die Saftarten Orangensaft, Apfelsaft usw. ausgegeben werden?
Kann mir jemand helfen?