Auf Thema antworten

[code=Java]import javax.swing.JOptionPane;



public class Taschenrechner {

   

    public static void main(String[] args) {

        JOptionPane.showMessageDialog( null, "Hallo, dies ist ein Taschenrechner." );

        do

            invokeTaschenrechner();

        while( JOptionPane.showConfirmDialog( null, "Möchten Sie fortführen?", "Fortführen", JOptionPane.YES_NO_OPTION ) == 0 );

    }

   

    private static void invokeTaschenrechner() {

        String Operator = JOptionPane.showInputDialog( "Welchen Rechenoperator benötigen sie? (+ - * /)" );

       

        if( Operator.equals( "+" ) ) {

            String AFrage1 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre erste Zahl ein." );

            String AFrage2 = JOptionPane.showInputDialog( "Geben Sie jeztz ihre zweite Zahl ein." );

           

            try {

                Double AZahl1 = Double.parseDouble( AFrage1 );

                Double AZahl2 = Double.parseDouble( AFrage2 );

                JOptionPane.showMessageDialog( null, AZahl1 + AZahl2 );

            }

           

            catch( Exception e ) {

                JOptionPane.showMessageDialog( null, "Geben Sie zwei ZAHLEN ein!" );

            }

           

        }

       

        else if( Operator.equals( "-" ) ) {

            String SFrage1 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre erste Zahl ein." );

            String SFrage2 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre zweite Zahl ein." );

            try {

                double SZahl1 = Double.parseDouble( SFrage1 );

                double SZahl2 = Double.parseDouble( SFrage2 );

                JOptionPane.showMessageDialog( null, SZahl1 - SZahl2 );

            } catch( Exception e ) {

                JOptionPane.showMessageDialog( null, "Geben Sie zwei ZAHLEN ein!" );

            }

        }

       

        else if( Operator.equals( "*" ) ) {

            String MFrage1 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre erste Zahl ein." );

            String MFrage2 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre zweite Zahl ein." );

            try {

                double MZahl1 = Double.parseDouble( MFrage1 );

                double MZahl2 = Double.parseDouble( MFrage2 );

                JOptionPane.showMessageDialog( null, MZahl1 * MZahl2 );

            } catch( Exception e ) {

                JOptionPane.showMessageDialog( null, "Geben Sie zwei ZAHLEN ein!" );

            }

        }

       

        else if( Operator.equals( "/" ) ) {

            String DFrage1 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre erste Zahl ein." );

            String DFrage2 = JOptionPane.showInputDialog( "Geben Sie jetzt ihre zweite Zahl ein." );

            try {

                double DZahl1 = Double.parseDouble( DFrage1 );

                double DZahl2 = Double.parseDouble( DFrage2 );

                JOptionPane.showMessageDialog( null, DZahl1 / DZahl2 );

            } catch( Exception e ) {

                JOptionPane.showMessageDialog( null, "Geben Sie zwei ZAHLEN ein!" );

            }

        }

       

        else {

            JOptionPane.showMessageDialog( null, "Das ist keiner der gennanten Rechenoperatoren!" );

        }

    }

}[/code]


Und bitte die Tipps der anderen beachten.

Variablen mit kleinem Buchstaben beginnen!



Oben