You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
2.2 KiB
129 lines
2.2 KiB
package programmiermethoden_und_Werkzeuge;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class Taschenrechner {
|
|
int addition(int a, int b) {
|
|
|
|
return a + b;
|
|
}
|
|
|
|
int multiplikation(int a, int b) {
|
|
|
|
return a * b;
|
|
}
|
|
|
|
int division(int a, int b) {
|
|
|
|
return a / b;
|
|
}
|
|
|
|
int potenzieren(int a, int b) {
|
|
|
|
int temp = 1;
|
|
|
|
if(b == 0) {
|
|
return 1;
|
|
}
|
|
|
|
for(int i = 0; i < b; i++) {
|
|
temp = temp * a;
|
|
}
|
|
|
|
return temp;
|
|
}
|
|
|
|
boolean kleinerAls(int a, int b) {
|
|
|
|
return a < b;
|
|
}
|
|
|
|
boolean groeßerAls(int a, int b) {
|
|
return a > b;
|
|
}
|
|
|
|
boolean gleich(int a, int b) {
|
|
return a == b;
|
|
}
|
|
|
|
int randomNummer(int a, int b) {
|
|
//Zufällige Nummer von a bis b
|
|
int temp = 0;
|
|
|
|
temp = (int) (Math.random() * (b + 1) ) + a;
|
|
|
|
return temp;
|
|
}
|
|
|
|
double pie() {
|
|
return Math.PI;
|
|
}
|
|
|
|
static int eingabe() {
|
|
Scanner scan = new Scanner(System.in);
|
|
int intScan= scan.nextInt();
|
|
|
|
scan.close();
|
|
|
|
return intScan;
|
|
}
|
|
|
|
void startTaschenrechner() {
|
|
//Funktion zum Starten des Taschenrechnerprogramms
|
|
System.out.println("1.Addition, 2.Multiplikation, 3.Division, 4.Potenzieren, 5.kleinerAls, 6.groeßerAls, 7.Gleichgroß, 8.Zufällige Zahl, 9.PI");
|
|
Scanner scan = new Scanner(System.in);
|
|
|
|
int s = scan.nextInt();
|
|
|
|
scan.close();
|
|
|
|
switch (s) {
|
|
case 1: {
|
|
System.out.println("Addition\n");
|
|
|
|
System.out.println("Ergebnis:" + addition(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
case 2: {
|
|
System.out.println("Division\n");
|
|
|
|
System.out.println("Ergebnis:" + division(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
case 3:{
|
|
System.out.println("Multiplikation\n");
|
|
|
|
System.out.println("Ergebnis:" + multiplikation(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
case 4:{
|
|
System.out.println("Potenzieren\n");
|
|
|
|
System.out.println("Ergebnis:" + potenzieren(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
case 5:{
|
|
System.out.println("KleinerAls\n");
|
|
|
|
System.out.println("Ergebnis:" + kleinerAls(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
case 6:{
|
|
System.out.println("GroeßerAls\n");
|
|
|
|
System.out.println("Ergebnis:" + groeßerAls(eingabe(), eingabe()));
|
|
|
|
break;
|
|
}
|
|
default:
|
|
throw new IllegalArgumentException("Unexpected value: " + s);
|
|
}
|
|
|
|
|
|
}
|
|
}
|