Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Rechner {
- public static void main(String[] args){
- //Wariablen Erstellen und Scanner erstellen
- double Zahl1, Zahl2, Ergebniss1, Antwort;
- int Zahl3, Ergebniss2, Zahl4;
- String s1 = null;
- String s2;
- Scanner scan = new Scanner(System.in);
- System.out.println("Willkommen zu einem Taschenrechner!");
- System.out.println("Was möchtest du tun?");
- //Beginn der Haupt-Schleife
- while(true){
- //Labern
- System.out.println("Tippe:");
- System.out.println("NormaleRechnung für eine Normale Rechnung (+ - * /)");
- System.out.println("Quersumme um eine Quersumme zu berechnen");
- System.out.println("");
- System.out.print("Ihr Befehl: ");
- if(scan.hasNext()) {
- s1 = scan.next();
- }
- if(s1 != null) {
- //Normale Rechnung
- if(s1.equals("NormaleRechnung")){
- System.out.println("Ok eine Normale Rechnung also!");
- System.out.print("Deine Erste Zahl: ");
- Zahl1 =scan.nextDouble();
- System.out.print("Dein Rechenzeichen: ");
- //+
- while(true){
- s2 = scan.next();
- if(s2.equals("+")){
- System.out.print("Deine Zweite Zahl: ");
- Zahl2 =scan.nextDouble();
- Ergebniss1 = Zahl1 + Zahl2;
- System.out.println(Zahl1 + " + " + Zahl2 + " = " + Ergebniss1);
- System.out.println("");
- System.out.println("Möchtest du noch eine Rechnung durchführen?");
- System.out.println("Tippe: Ja oder Nein");
- break;
- //-
- } else if(s2.equals("-")){
- System.out.print("Deine Zweite Zahl: ");
- Zahl2 =scan.nextDouble();
- Ergebniss1 = Zahl1 - Zahl2;
- System.out.println(Zahl1 + " - " + Zahl2 + " = " + Ergebniss1);
- System.out.println("");
- System.out.println("Möchtest du noch eine Rechnung durchführen?");
- System.out.println("Tippe: Ja oder Nein");
- break;
- //*
- } else if(s2.equals("*")){
- System.out.print("Deine Zweite Zahl: ");
- Zahl2 =scan.nextDouble();
- Ergebniss1 = Zahl1 * Zahl2;
- System.out.println(Zahl1 + " * " + Zahl2 + " = " + Ergebniss1);
- System.out.println("");
- System.out.println("Möchtest du noch eine Rechnung durchführen?");
- System.out.println("Tippe: Ja oder Nein");
- break;
- // /
- } else if(s2.equals("/")){
- System.out.print("Deine Zweite Zahl: ");
- Zahl2 =scan.nextDouble();
- Ergebniss1 = Zahl1 / Zahl2;
- System.out.println(Zahl1 + " / " + Zahl2 + " = " + Ergebniss1);
- System.out.println("");
- System.out.println("Möchtest du noch eine Rechnung durchführen?");
- System.out.println("Tippe: Ja oder Nein");
- break;
- // else halt
- } else {
- System.out.println(s2 + (" ' " + s2 + " ' ist kein Akzeptabless Rechenzeichen!"));
- System.out.print(s2 + ("Nochmal Bitte: "));
- continue;
- }
- }
- //Antwort Ja Nein
- Antwort= Answer();
- if(Antwort==1){
- continue;
- } else if(Antwort==2){
- break;
- } else {
- System.out.println("ES GAB EINEN FEHLER!!!");
- break;
- }
- }else if(s1.equals("Quersumme")){
- System.out.println(("Von welcher Zahl hättest du denn gerne die Quersumme (Keine Komma Zahlen): "));
- Zahl3 = scan.nextInt();
- Zahl4 = Zahl3;
- //while schleife für Quersumme
- Ergebniss2 = 0;
- while(true){
- if(Zahl3<=0){
- break;
- }
- Ergebniss2+=Zahl3%10;
- Zahl3/=10;
- }
- System.out.println("Die Quersumme von " + Zahl4 + " ist: "+ Ergebniss2);
- System.out.println("");
- System.out.println("Möchtest du noch eine Rechnung durchführen?");
- System.out.println("Tippe: Ja oder Nein");
- //Antwort Ja Nein
- Antwort= Answer();
- if(Antwort==1){
- continue;
- } else if(Antwort==2){
- break;
- } else {
- System.out.println("ES GAB EINEN FEHLER!!!");
- break;
- }
- } else {
- System.out.println(s1 + " ist keine Akzeptable Eingabe!");
- System.out.println(s1 + " Noch einmal Bitte!");
- System.out.println("");
- continue;
- }
- }
- break;
- }
- }
- private static double Answer(){
- String Antwort;
- double Ans;
- Scanner scan2 = new Scanner(System.in);
- while(true){
- scan2 = new Scanner(System.in);
- Antwort = scan2.next();
- if(Antwort.equals("Ja")){
- System.out.println("Ok eine Weitere Rechnung!");
- Ans = 1;
- break;
- } else if(Antwort.equals("Nein")){
- System.out.println("Ok Aufwiedersehen!");
- System.out.println("");
- System.out.println("");
- System.out.println("");
- Ans = 2;
- break;
- } else {
- System.out.println(" ' " + Antwort + " ' ist keine Akzeptable Antwort!");
- System.out.println("Bitte Nocheinmal Eingeben: ");
- continue;
- }
- }
- return Ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement