Advertisement
Guest User

Funzt endlich Lucas

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Rechner {
  4.     public static void main(String[] args){
  5.        
  6.         //Wariablen Erstellen und Scanner erstellen
  7.         double Zahl1, Zahl2, Ergebniss1, Antwort;
  8.         int Zahl3, Ergebniss2, Zahl4;
  9.         String s1 = null;
  10.         String s2;
  11.        
  12.        
  13.         Scanner scan = new Scanner(System.in);
  14.        
  15.         System.out.println("Willkommen zu einem Taschenrechner!");
  16.         System.out.println("Was möchtest du tun?");
  17.        
  18.        
  19.        
  20.         //Beginn der Haupt-Schleife
  21.         while(true){
  22.             //Labern
  23.             System.out.println("Tippe:");
  24.             System.out.println("NormaleRechnung   für eine Normale Rechnung (+ - * /)");
  25.             System.out.println("Quersumme         um eine Quersumme zu berechnen");
  26.             System.out.println("");
  27.             System.out.print("Ihr Befehl:      ");
  28.            
  29.                        
  30.            
  31.             if(scan.hasNext()) {
  32.                    
  33.                 s1 = scan.next();
  34.             }
  35.            
  36.             if(s1 != null) {
  37.            
  38.                        
  39.            
  40.             //Normale Rechnung
  41.            
  42.             if(s1.equals("NormaleRechnung")){
  43.                 System.out.println("Ok eine Normale Rechnung also!");
  44.                 System.out.print("Deine Erste Zahl:     ");
  45.                 Zahl1 =scan.nextDouble();
  46.                
  47.                 System.out.print("Dein Rechenzeichen:   ");
  48.                
  49.                 //+
  50.                 while(true){
  51.                     s2 = scan.next();
  52.                 if(s2.equals("+")){
  53.                     System.out.print("Deine Zweite Zahl:    ");
  54.                     Zahl2 =scan.nextDouble();
  55.                     Ergebniss1 = Zahl1 + Zahl2;
  56.                     System.out.println(Zahl1 + " + " + Zahl2 + " = " + Ergebniss1);
  57.                     System.out.println("");
  58.                     System.out.println("Möchtest du noch eine Rechnung durchführen?");
  59.                     System.out.println("Tippe: Ja oder Nein");
  60.                    
  61.                     break;
  62.                    
  63.                    
  64.                 //-
  65.                 } else if(s2.equals("-")){
  66.                     System.out.print("Deine Zweite Zahl:    ");
  67.                     Zahl2 =scan.nextDouble();
  68.                     Ergebniss1 = Zahl1 - Zahl2;
  69.                     System.out.println(Zahl1 + " - " + Zahl2 + " = " + Ergebniss1);
  70.                     System.out.println("");
  71.                     System.out.println("Möchtest du noch eine Rechnung durchführen?");
  72.                     System.out.println("Tippe: Ja oder Nein");
  73.                    
  74.                     break;
  75.                 //*
  76.                 } else if(s2.equals("*")){
  77.                     System.out.print("Deine Zweite Zahl:    ");
  78.                     Zahl2 =scan.nextDouble();
  79.                     Ergebniss1 = Zahl1 * Zahl2;
  80.                     System.out.println(Zahl1 + " * " + Zahl2 + " = " + Ergebniss1);
  81.                     System.out.println("");
  82.                     System.out.println("Möchtest du noch eine Rechnung durchführen?");
  83.                     System.out.println("Tippe: Ja oder Nein");
  84.                    
  85.                     break;
  86.                 // /   
  87.                 } else if(s2.equals("/")){
  88.                     System.out.print("Deine Zweite Zahl:    ");
  89.                     Zahl2 =scan.nextDouble();
  90.                     Ergebniss1 = Zahl1 / Zahl2;
  91.                     System.out.println(Zahl1 + " / " + Zahl2 + " = " + Ergebniss1);
  92.                     System.out.println("");
  93.                     System.out.println("Möchtest du noch eine Rechnung durchführen?");
  94.                     System.out.println("Tippe: Ja oder Nein");
  95.                    
  96.                     break;
  97.                
  98.                 // else halt   
  99.                 } else {
  100.                     System.out.println(s2 + (" ' " + s2 + " ' ist kein Akzeptabless Rechenzeichen!"));
  101.                     System.out.print(s2 + ("Nochmal Bitte:     "));
  102.                    
  103.                     continue;
  104.                    
  105.                 }
  106.            
  107.                
  108.                
  109.             }
  110.            
  111.                 //Antwort Ja Nein
  112.                
  113.                 Antwort= Answer();
  114.                
  115.                 if(Antwort==1){
  116.                     continue;
  117.                 } else if(Antwort==2){
  118.                     break;
  119.                 } else {
  120.                     System.out.println("ES GAB EINEN FEHLER!!!");
  121.                     break;
  122.                 }
  123.            
  124.            
  125.            
  126.             }else if(s1.equals("Quersumme")){
  127.                 System.out.println(("Von welcher Zahl hättest du denn gerne die Quersumme (Keine Komma Zahlen):     "));
  128.                 Zahl3 = scan.nextInt();
  129.                 Zahl4 = Zahl3;
  130.                 //while schleife für Quersumme
  131.                 Ergebniss2 = 0;
  132.                 while(true){
  133.                    
  134.                     if(Zahl3<=0){
  135.                         break;
  136.                     }
  137.                    
  138.                     Ergebniss2+=Zahl3%10;
  139.                     Zahl3/=10;
  140.                 }
  141.                
  142.                 System.out.println("Die Quersumme von " + Zahl4 + " ist: "+ Ergebniss2);
  143.                 System.out.println("");
  144.                 System.out.println("Möchtest du noch eine Rechnung durchführen?");
  145.                 System.out.println("Tippe: Ja oder Nein");
  146.                
  147.                 //Antwort Ja Nein
  148.                 Antwort= Answer();
  149.                
  150.                 if(Antwort==1){
  151.                     continue;
  152.                 } else if(Antwort==2){
  153.                     break;
  154.                 } else {
  155.                     System.out.println("ES GAB EINEN FEHLER!!!");
  156.                     break;
  157.                 }
  158.                
  159.             } else {
  160.                 System.out.println(s1 + " ist keine Akzeptable Eingabe!");
  161.                 System.out.println(s1 + " Noch einmal Bitte!");
  162.                 System.out.println("");
  163.                
  164.                 continue;
  165.                
  166.             }
  167.            
  168.            
  169.            
  170.            
  171.            
  172.         }
  173.             break;
  174.         }
  175.     }
  176.    
  177.     private static double Answer(){
  178.         String Antwort;
  179.         double Ans;
  180.         Scanner scan2 = new Scanner(System.in);
  181.        
  182.        
  183.         while(true){
  184.             scan2 = new Scanner(System.in);
  185.             Antwort = scan2.next();
  186.            
  187.             if(Antwort.equals("Ja")){
  188.                 System.out.println("Ok eine Weitere Rechnung!");
  189.                 Ans = 1;
  190.                 break;
  191.                
  192.                
  193.             } else if(Antwort.equals("Nein")){
  194.                 System.out.println("Ok Aufwiedersehen!");
  195.                 System.out.println("");
  196.                 System.out.println("");
  197.                 System.out.println("");
  198.                 Ans = 2;
  199.                 break;
  200.                
  201.                
  202.             } else {
  203.                 System.out.println(" ' " + Antwort + " ' ist keine Akzeptable Antwort!");
  204.                 System.out.println("Bitte Nocheinmal Eingeben:     ");
  205.                 continue;
  206.                
  207.             }
  208.            
  209.         }
  210.        
  211.         return Ans;
  212.        
  213.     }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement