Browse Source
Merge branch 'H.F.F/Taschenrechner' into 'main'
Merge branch 'H.F.F/Taschenrechner' into 'main'
H.f.f/taschenrechner See merge request fdai7487/gruppenprojekt-programmiermethoden-und-werkzeuge!1remotes/origin/fdai7487-main-patch-56841
fdai7446
2 years ago
2 changed files with 277 additions and 0 deletions
@ -0,0 +1,177 @@ |
|||
package programmiermethoden_und_Werkzeuge; |
|||
|
|||
import java.util.Scanner; |
|||
|
|||
public class Taschenrechner { |
|||
static int addition(int a, int b) { |
|||
|
|||
return a + b; |
|||
} |
|||
|
|||
static int multiplikation(int a, int b) { |
|||
|
|||
return a * b; |
|||
} |
|||
|
|||
static int division(int a, int b) { |
|||
|
|||
return a / b; |
|||
} |
|||
|
|||
static 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; |
|||
} |
|||
|
|||
static boolean kleinerAls(int a, int b) { |
|||
|
|||
return a < b; |
|||
} |
|||
|
|||
static boolean groeßerAls(int a, int b) { |
|||
return a > b; |
|||
} |
|||
|
|||
static boolean gleich(int a, int b) { |
|||
return a == b; |
|||
} |
|||
|
|||
static int randomIntegerNummer(int a, int b) { |
|||
//Zufällige Nummer von a bis b |
|||
int temp = 0; |
|||
|
|||
temp = (int) (Math.random() * (b + 1) ) + a; |
|||
|
|||
return temp; |
|||
} |
|||
|
|||
static double pi() { |
|||
return Math.PI; |
|||
} |
|||
|
|||
static double e() { |
|||
return Math.E; |
|||
} |
|||
|
|||
static double kreisUmfang(int r) { |
|||
return 2 * r * Math.PI; |
|||
} |
|||
|
|||
static int eingabe() { |
|||
Scanner scan = new Scanner(System.in); |
|||
int intScan = 0; |
|||
try{ |
|||
intScan= scan.nextInt(); |
|||
}catch(Exception e){ |
|||
System.out.println("Fehler bei der Eingabe!"); |
|||
} |
|||
|
|||
// scan.close(); |
|||
|
|||
return intScan; |
|||
} |
|||
|
|||
static void startTaschenrechner() { |
|||
//Funktion zum Starten des Taschenrechnerprogramms |
|||
System.out.println("1.Addition, 2.Division, 3.Multiplikation, 4.Potenzieren, 5.kleinerAls, 6.groeßerAls, 7.Gleichgroß, 8.Zufällige Zahl, 9.PI, 10.Euler, 11.Kreisumfang"); |
|||
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("Die erste Zahl ist kleiner:" + kleinerAls(eingabe(), eingabe())); |
|||
|
|||
break; |
|||
} |
|||
case 6:{ |
|||
System.out.println("GroeßerAls\n"); |
|||
|
|||
System.out.println("Die erste Zahl ist groeßer:" + groeßerAls(eingabe(), eingabe())); |
|||
|
|||
break; |
|||
} |
|||
case 7:{ |
|||
System.out.println("Gleich\n"); |
|||
|
|||
System.out.println("Gleichgroß:" + gleich(eingabe(), eingabe())); |
|||
|
|||
break; |
|||
} |
|||
case 8:{ |
|||
System.out.println("RandomNummer\n"); |
|||
|
|||
System.out.println("Zufaellige Zahl:" + randomIntegerNummer(eingabe(), eingabe())); |
|||
|
|||
break; |
|||
} |
|||
case 9:{ |
|||
System.out.println("Pi\n"); |
|||
|
|||
System.out.println("Pi:" + pi()); |
|||
|
|||
break; |
|||
} |
|||
case 10:{ |
|||
System.out.println("Eulerische Konstante\n"); |
|||
|
|||
System.out.println("E:"); |
|||
|
|||
break; |
|||
} |
|||
case 11:{ |
|||
System.out.println("Kreisumfang\n"); |
|||
|
|||
System.out.println("Kreisumfang:"); |
|||
|
|||
break; |
|||
} |
|||
default: |
|||
throw new IllegalArgumentException("Unexpected value: " + s); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,100 @@ |
|||
package programmiermethoden_und_Werkzeuge; |
|||
|
|||
import static org.junit.Assert.*; |
|||
|
|||
import org.junit.Test; |
|||
|
|||
public class TaschenrechnerTest { |
|||
|
|||
@Test |
|||
public void testAddition() { |
|||
int a = 3; |
|||
int b = 4; |
|||
int ab = a + b; |
|||
int result = Taschenrechner.addition(a,b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testMultiplikation() { |
|||
int a = 6; |
|||
int b = 6; |
|||
int ab = a * b; |
|||
int result = Taschenrechner.multiplikation(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testDivision() { |
|||
int a = 14; |
|||
int b = 7; |
|||
int ab = a / b; |
|||
int result = Taschenrechner.division(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testPotenzieren() { |
|||
int a = 2; |
|||
int b = 3; |
|||
int ab = (int)Math.pow(a, b); |
|||
int result = Taschenrechner.potenzieren(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testKleinerAls() { |
|||
int a = 9; |
|||
int b = 6; |
|||
boolean ab = a<b; |
|||
boolean result = Taschenrechner.kleinerAls(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testGroeßerAls() { |
|||
int a = 6; |
|||
int b = 9; |
|||
boolean ab = a>b; |
|||
boolean result = Taschenrechner.groeßerAls(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testGleich() { |
|||
int a = 5; |
|||
int b = 5; |
|||
boolean ab = a==b; |
|||
boolean result = Taschenrechner.gleich(a, b); |
|||
|
|||
assertEquals(ab, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testRandomIntegerNummer() { |
|||
int a = 2; |
|||
int b = 10; |
|||
int r = (int) (Math.random() * (a + 1)) + b; |
|||
boolean result = r > a && r >= b; |
|||
|
|||
assertEquals(true, result); |
|||
} |
|||
|
|||
@SuppressWarnings("deprecation") |
|||
@Test |
|||
public void testKreisUmfang() { |
|||
int r = 3; |
|||
double u = 2* r *Math.PI; |
|||
double result = Taschenrechner.kreisUmfang(r); |
|||
|
|||
assertEquals(u, result); |
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue