Summert4stic
Newbie
- Registriert
- Okt. 2011
- Beiträge
- 5
Hallo, ich habe die Aufgabe einen Geldautomaten mit Eclipse zu programmieren, dabei soll der der Anfangsbetrag 1000€ betragen und man kann auszahlen, einzahlen, usw. Jedoch möchte ich, dass der Kontostand nur noch 500€ beträgt, wenn ich 500€ abbuche, nachdem ich mich wieder auslogge. Also das Programm soll nach jeder Ein- oder Auszahlung den aktuellen Kontostand speichern. Was muss ich einfügen und wo?
So sieht mein Programm im Moment aus:
import javax.swing.JOptionPane;
public class Geldautomat {
public static void main(String[]args){
JOptionPane.showMessageDialog(null,"Hallo, hier ist ihr Geldautomat");
JOptionPane.showInputDialog("Bitte EC Karte einschieben");
JOptionPane.showInputDialog("Bitte PIN eingeben");
do{
String[] options = { "Kontostand abfragen",
"Betrag auszahlen",
"Betrag einzahlen",
"Betrag auf die EC Karte buchen",
"Abbruch",};
String wahl = (String) JOptionPane.showInputDialog(null, "Was wollen sie tun?",
"Optionen", JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
int Kontostand=1000;
String Betrag;
int Betragint;
String Betrag2;
int Betrag2int;
String Betrag3;
int Betrag3int;
int erg;
int erg2;
if(wahl=="Kontostand abfragen"){
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt"+Kontostand + "€");
}
else if(wahl=="Betrag auszahlen"){
Betrag=JOptionPane.showInputDialog("Wie viel € möchten sie Auszahlen?");
Betragint=Integer.parseInt(Betrag);
erg=Kontostand-Betragint;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");}
else if(wahl=="Betrag einzahlen"){
Betrag2=JOptionPane.showInputDialog("Wie viel € möchten sie einzahlen?");
Betrag2int=Integer.parseInt(Betrag2);
erg=Kontostand+Betrag2int;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");}
else if(wahl=="Betrag auf die EC Karte buchen"){
Betrag3=JOptionPane.showInputDialog("Wie viel € möchten sie auf ihre EC Karte buchen?");
Betrag3int=Integer.parseInt(Betrag3);
erg=Kontostand-Betrag3int;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");
}
} while (JOptionPane.showInputDialog("Nochmal? [J/N]")
.equalsIgnoreCase("j"));
}
}
So sieht mein Programm im Moment aus:
import javax.swing.JOptionPane;
public class Geldautomat {
public static void main(String[]args){
JOptionPane.showMessageDialog(null,"Hallo, hier ist ihr Geldautomat");
JOptionPane.showInputDialog("Bitte EC Karte einschieben");
JOptionPane.showInputDialog("Bitte PIN eingeben");
do{
String[] options = { "Kontostand abfragen",
"Betrag auszahlen",
"Betrag einzahlen",
"Betrag auf die EC Karte buchen",
"Abbruch",};
String wahl = (String) JOptionPane.showInputDialog(null, "Was wollen sie tun?",
"Optionen", JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
int Kontostand=1000;
String Betrag;
int Betragint;
String Betrag2;
int Betrag2int;
String Betrag3;
int Betrag3int;
int erg;
int erg2;
if(wahl=="Kontostand abfragen"){
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt"+Kontostand + "€");
}
else if(wahl=="Betrag auszahlen"){
Betrag=JOptionPane.showInputDialog("Wie viel € möchten sie Auszahlen?");
Betragint=Integer.parseInt(Betrag);
erg=Kontostand-Betragint;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");}
else if(wahl=="Betrag einzahlen"){
Betrag2=JOptionPane.showInputDialog("Wie viel € möchten sie einzahlen?");
Betrag2int=Integer.parseInt(Betrag2);
erg=Kontostand+Betrag2int;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");}
else if(wahl=="Betrag auf die EC Karte buchen"){
Betrag3=JOptionPane.showInputDialog("Wie viel € möchten sie auf ihre EC Karte buchen?");
Betrag3int=Integer.parseInt(Betrag3);
erg=Kontostand-Betrag3int;
JOptionPane.showMessageDialog(null,"Ihr Kontostand beträgt nun" + erg + "€");
}
} while (JOptionPane.showInputDialog("Nochmal? [J/N]")
.equalsIgnoreCase("j"));
}
}