Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.18 KB | None | 0 0
  1. package com.CedricKk.Java.GUI;
  2.  
  3. import java.io.*;
  4. import java.lang.Integer;
  5. import java.io.BufferedReader;
  6. import java.io.File;
  7. import java.io.FileNotFoundException;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. import java.io.Reader;
  11. import java.util.LinkedList;
  12.  
  13. /*******************************************
  14. * Kontomannager
  15. * Version 3.3
  16. * Author: Cedric Kienzler
  17. * all rights reserved
  18. * if you have any questions:
  19. * cedrickienzler1@googlemail.com
  20. ********************************************/
  21.  
  22. public class Konto {
  23.    
  24.     public static boolean first_run = true;
  25.     public static double version = 3.3;
  26.     public static double guthaben = 0 , einzahlen = 0 , auszahlen = 0;
  27.     public static int ID = 0, Kontonr = 0 , blz = 0;
  28.     public static String Geldinstitut , Kontoinhaber;
  29.     private static BufferedReader br = null;
  30.     public static String fehler , auswählen , temp1 = "abheben" , temp2 = "einzahlen" , temp3 = "anzeigen" , temp4 = "speichern";
  31.     public static String temp , dateiName, save1 , save2 , save3, save4 , save5 , save6 , save7, save8;
  32.    
  33.     public static void Varaiblen2String() {
  34.         save1 = Double.toString(guthaben);
  35.         save2 = Double.toString(einzahlen);
  36.         save3 = Double.toString(auszahlen);
  37.         save4 = Integer.toString(ID);
  38.         save5 = Integer.toString(Kontonr);
  39.         save6 = Integer.toString(blz);
  40.         save7 = Geldinstitut;
  41.         save8 = Kontoinhaber;
  42.     }
  43.    
  44.     public static void welcome() {
  45.        
  46.         int y = 0;
  47.         int z = 200000;
  48.        
  49.         System.out.println ("\n \n \n \n \n \n");
  50.        
  51.        
  52.         System.out.println ("                 Kontomannager ");
  53.         System.out.println ();  
  54.         System.out.println ("* Copyright (c) 2010 by Cedric Kienzler");
  55.         System.out.println ("* Version: " + version);
  56.         System.out.println ("* all rights reserved");
  57.         System.out.println ("* any questions?");
  58.         System.out.println ("* ask me! at:");
  59.         System.out.println ("* cedrickienzler1@googlemail.com");
  60.        
  61.         while (y == z) {
  62.             y++;
  63.         }
  64.         System.out.println ("\n \n \n \n \n \n");
  65.        
  66.        
  67.         System.out.println ("                 Kontomannager ");
  68.         System.out.println ();  
  69.         System.out.println ("* Copyright (c) 2010 by Cedric Kienzler");
  70.         System.out.println ("* Version 3.0");
  71.         System.out.println ("* all rights reserved");
  72.         System.out.println ("* any questions?");
  73.         System.out.println ("* ask me! at:");
  74.         System.out.println ("* cedrickienzler1@googlemail.com");
  75.        
  76.     }
  77.    
  78.     public static void error() {
  79.         System.err.println("Fehler:" + fehler);
  80.     }
  81.    
  82.     public static void reader() throws IOException {
  83.         br = new BufferedReader(new InputStreamReader( System.in ) );
  84.     }
  85.    
  86.     public static void festlegung_Konto() {
  87.         try {
  88.             ID++;
  89.            
  90.             reader();
  91.  
  92.             System.out.println ("\n \n \n \n \n");    
  93.  
  94.             System.out.println("Bitte geben sie den Kontoinhaber ein:");
  95.             Kontoinhaber = br.readLine();  
  96.  
  97.  
  98.             System.out.println ("\n \n");  
  99.  
  100.             System.out.println("Bitte geben sie das Geld Instutut ein:");
  101.             Geldinstitut = br.readLine();
  102.            
  103.             System.out.println ("\n \n ");
  104.            
  105.             System.out.println("Bitte geben sie ihre Kontonummer an:");
  106.             String userInput = br.readLine();
  107.            
  108.             Kontonr = Integer.parseInt(userInput);
  109.  
  110.             System.out.println ("\n \n ");
  111.            
  112.             System.out.println("Bitte geben sie die Bankleitzahl an:");
  113.             userInput = br.readLine();
  114.            
  115.             blz = Integer.parseInt(userInput);
  116.            
  117.             System.out.println ("\n \n ");
  118.            
  119.             System.out.println("Bitte geben sie ihren aktuellen Kontostand ein:");
  120.             userInput = br.readLine();
  121.            
  122.             guthaben = Integer.parseInt(userInput);
  123.            
  124.            
  125.            
  126.             }
  127.  
  128.             catch (IOException e) {
  129.                 //e.printStackTrace();
  130.                 System.out.println ("\n \n");  
  131.  
  132.                 fehler = "Fehler beim einlesen der Eingaben";
  133.                 error();
  134.                
  135.             }
  136.         }
  137.    
  138.     public static void ausgabe_Auswählen() {
  139.         System.out.println("Wenn sie einen Betrag einzahlen möchten, dan tippen sie bitte \n >>einzahlen<<");
  140.         System.out.println("Wenn sie einen Betrag auszahlen möchten, dann tippen sie bitte \n >>abheben<<");
  141.         System.out.println ("Um alle informationen über ihn Konto anzuzeigen, tippen sie bitte \n >>anzeigen<<");
  142.         System.out.println ("Wenn sie ihre eingaben speichern wollen, tippen sie bitte \n speichern");
  143.        
  144.         try {
  145.            
  146.             reader();
  147.            
  148.             auswählen = br.readLine();
  149.            
  150.         }
  151.         catch (IOException e) {
  152.             e.printStackTrace();
  153.             fehler = "Fehler beim einlesen ihrer Tastatureingabe";
  154.             error();
  155.         }
  156.    
  157.     }
  158.  
  159.     public static double abheben() {
  160.        
  161.         System.out.println ("\n \n ");
  162.         try {
  163.            
  164.             reader();
  165.            
  166.             System.out.println("Bitte geben sie den auszuzahlenden Betrag ein:");
  167.             String userInput = br.readLine();
  168.                    
  169.             auszahlen = Double.parseDouble(userInput);
  170.            
  171.             guthaben = guthaben - auszahlen;
  172.         }
  173.         catch (IOException e) {
  174.             e.printStackTrace();
  175.             fehler = "Fehler bei der eingabe des auszuzahlenen Betrages!";
  176.             error();
  177.         }
  178.        
  179.        
  180.         return auszahlen;
  181.     }
  182.    
  183.     public static double einzahlen() {
  184.        
  185.         guthaben = guthaben + einzahlen;
  186.        
  187.         return einzahlen;
  188.     }
  189.    
  190.     public static void ausgabe_Kontoinfo() {
  191.         System.out.println ("ID:" + ID);
  192.         System.out.println ("Kontoinhaber: " + Kontoinhaber);
  193.         System.out.println ("Bankleitzahl / Geldinstitut: " + blz + " / " + Geldinstitut );
  194.         System.out.println ("Kontonummer: " + Kontonr);
  195.         System.out.println (" \n Aktuelles Guthaben:" + guthaben);
  196.         System.out.println (" \n Letzte Transaktionen: ");
  197.         System.out.println ("Letze Einzahlung erfolgte in einer höhe von: "+ einzahlen + "Euro");
  198.         System.out.println ("Letze auszahlung erfolgte in einer höhe von: " + auszahlen + "Euro");
  199.        
  200.     }
  201.    
  202.     public static void speichern() {
  203.            
  204.         Varaiblen2String();
  205.        
  206.         try {  
  207.             System.out.println ("Geben sie bitte den Dateinamen ein, der auf '.txt' endet \n zum Beispiel: 'test.txt' ");
  208.             temp = br.readLine();
  209.             dateiName = temp;
  210.         }
  211.         catch (IOException e) {
  212.             System.out.println ("Fehler!");
  213.         }
  214.  
  215.         FileOutputStream schreibeStrom = null;
  216.         try {
  217.             schreibeStrom = new FileOutputStream(dateiName);
  218.         } catch (FileNotFoundException e) {
  219.             e.printStackTrace();
  220.         }
  221.         for (int i1=0; i1 < save1.length(); i1++){
  222.           try {
  223.             schreibeStrom.write((byte)save1.charAt(i1));
  224.         } catch (IOException e) {
  225.             e.printStackTrace();
  226.         }
  227.         }
  228.         for (int i2=0; i2 < save2.length(); i2++){
  229.           try {
  230.             schreibeStrom.write((byte)save2.charAt(i2));
  231.         } catch (IOException e) {
  232.             e.printStackTrace();
  233.         }
  234.         }
  235.         for (int i3=0; i3 < save3.length(); i3++){
  236.           try {
  237.             schreibeStrom.write((byte)save3.charAt(i3));
  238.         } catch (IOException e) {
  239.             e.printStackTrace();
  240.         }
  241.         }
  242.         for (int i4=0; i4 < save4.length(); i4++){
  243.           try {
  244.             schreibeStrom.write((byte)save4.charAt(i4));
  245.         } catch (IOException e) {
  246.             e.printStackTrace();
  247.         }
  248.         }
  249.         for (int i5=0; i5 < save5.length(); i5++){
  250.           try {
  251.             schreibeStrom.write((byte)save5.charAt(i5));
  252.         } catch (IOException e) {
  253.             e.printStackTrace();
  254.         }
  255.         }
  256.         for (int i6=0; i6 < save6.length(); i6++){
  257.           try {
  258.             schreibeStrom.write((byte)save6.charAt(i6));
  259.         } catch (IOException e) {
  260.             e.printStackTrace();
  261.         }
  262.         }
  263.         for (int i7=0; i7 < save7.length(); i7++){
  264.           try {
  265.             schreibeStrom.write((byte)save7.charAt(i7));
  266.         } catch (IOException e) {
  267.             e.printStackTrace();
  268.         }
  269.         }
  270.         for (int i8=0; i8 < save8.length(); i8++){
  271.           try {
  272.             schreibeStrom.write((byte)save8.charAt(i8));
  273.         } catch (IOException e) {
  274.             e.printStackTrace();
  275.         }
  276.         }
  277.  
  278.         try {
  279.             schreibeStrom.close();
  280.         } catch (IOException e) {
  281.             e.printStackTrace();
  282.         }
  283.  
  284.         System.out.println("Dateien erfolgreich gespeichert.");
  285.     }
  286.  
  287.    
  288.     public static void main (String[] args) {
  289.         welcome();
  290.            
  291.         festlegung_Konto();
  292.         while (true) {
  293.            
  294.             System.out.println ("\n \n \n \n \n \n");
  295.             ausgabe_Auswählen();
  296.            
  297.        
  298.         if (auswählen.equals(temp1)) {
  299.             abheben();         
  300.         }
  301.         else {
  302.             if (auswählen.equals(temp2)) {
  303.                 einzahlen();
  304.             }
  305.             else {
  306.                 if (auswählen.equals(temp3)) {
  307.                     ausgabe_Kontoinfo();
  308.                 }
  309.                 else {
  310.                     if (auswählen.equals(temp4)) {
  311.                         speichern();
  312.                     }
  313.                     else {
  314.                         fehler = "ungültige eingabe. Bitte eingabe überprüfen!";
  315.                         error();
  316.                     }
  317.                 }
  318.             }
  319.         }
  320.         }
  321.        
  322.     } //end of main
  323. } //end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement