jannisfingerhut
2 years ago
4 changed files with 464 additions and 92 deletions
-
229LernProgramm/FunktionenAusgelagert.java
-
65LernProgramm/ProgrammMain.java
-
169LernProgramm/testProgramm.java
-
93README.md
@ -0,0 +1,229 @@ |
|||
package LernProgramm; |
|||
|
|||
import java.util.Random; |
|||
import java.util.Scanner; |
|||
|
|||
public class FunktionenAusgelagert { |
|||
|
|||
//Funktionen, die von der main Funktion ausgelagert wurden, |
|||
//da diese sonst zu unüberscihtlich gewesen wär und die main untergegangen wäre |
|||
|
|||
//1 |
|||
public static void Karteikarten() { |
|||
|
|||
try (Scanner eingabeKK = new Scanner(System.in)) { |
|||
|
|||
String[][] karteikarten = { { "Was ist die Hauptstadt von Deutschland?", "Berlin" }, |
|||
{ "Welches ist der größtes Planet in unserem Sonnensystem?", "Jupiter" }, |
|||
{ "Wer hat die Mona Lisa gemalt?", "Leonardo da Vinci" }, |
|||
{ "Wer ist der Bundeskanzler von Deutschland?", "Olaf Scholz" }, |
|||
{ "Wer hat den Z1 entworfen?", "Zuse" }, { "W", "Olaf Scholz" }, |
|||
{ "Wer ist der Bundeskanzler von Deutschland?", "Olaf Scholz" }, |
|||
// Sonstige Fragen können hier eingefügt werden |
|||
}; |
|||
|
|||
int PunkteZähler = 0; |
|||
for (String[] karteikarte : karteikarten) { |
|||
System.out.println(karteikarte[0]); |
|||
String answer = eingabeKK.nextLine(); |
|||
if (answer.equalsIgnoreCase(karteikarte[1])) { |
|||
System.out.println("Korrekt!"); |
|||
PunkteZähler++; |
|||
} else { |
|||
System.out.println("Leider falsch. Die richtige Antwort wäre: " + karteikarte[1]); |
|||
} |
|||
} |
|||
System.out.println("Dein Punktestand ist " + PunkteZähler + " von insgesamt " + karteikarten.length); |
|||
} |
|||
} |
|||
|
|||
//2 |
|||
public static void Fakultaet() { |
|||
|
|||
try (Scanner eingabeFK = new Scanner(System.in)) { |
|||
String ein = eingabeFK.nextLine(); |
|||
int zahlFK = Integer.parseInt(ein); |
|||
|
|||
if (zahlFK <= 0) { |
|||
System.out.println("1"); |
|||
} |
|||
int ergebnis = 1; |
|||
for (int i = 1; i <= zahlFK; i++) { |
|||
ergebnis *= i; |
|||
} |
|||
System.out.println(ergebnis); |
|||
} catch (NumberFormatException e) { |
|||
e.printStackTrace(); |
|||
} |
|||
|
|||
} |
|||
|
|||
//3 |
|||
public static void schaltjahr() { |
|||
|
|||
System.out.println("Welches Jahr möchtest du untersuchen?"); |
|||
|
|||
try (Scanner einSJ = new Scanner(System.in)) { |
|||
String jahr = einSJ.nextLine(); |
|||
int schaltjahr = Integer.parseInt(jahr); |
|||
|
|||
if (schaltjahr % 400 == 0) |
|||
System.out.println("Schaltjahr!"); |
|||
else if (schaltjahr % 100 == 0) |
|||
System.out.println("Kein Schaltjahr!"); |
|||
else if (schaltjahr % 4 == 0) |
|||
System.out.println("Schaltjahr!"); |
|||
else |
|||
System.out.println("Kein Schaltjahr!"); |
|||
} catch (NumberFormatException e) { |
|||
e.printStackTrace(); |
|||
|
|||
} |
|||
} |
|||
|
|||
//4 |
|||
public static void Quizz() { |
|||
Random rand = new Random(); |
|||
try (Scanner einQ = new Scanner(System.in)) { |
|||
String[][] fragen = { { "Welche Farbe hat ein Bananen?", "A) Gelb", "B) Grün", "C) Blau", "D) Rot", "A" }, |
|||
{ "Wie viele Beine hat eine Spinne?", "A) 4", "B) 6", "C) 8", "D) 10", "C" }, |
|||
{ "Wer hat die Formel E=mc² entwickelt?", "A) Isaac Newton", "B) Albert Einstein", |
|||
"C) Galileo Galilei", "D) Stephen Hawking", "B" }, |
|||
{ "Welches ist der größte Planet im Sonnensystem?", "A) Merkur", "B) Venus", "C) Erde", |
|||
"D) Jupiter", "D" } |
|||
// Sonstige Fragen |
|||
}; |
|||
int questionIndex = rand.nextInt(fragen.length); |
|||
String[] currentQuestion = fragen[questionIndex]; |
|||
|
|||
System.out.println(currentQuestion[0]); |
|||
System.out.println(currentQuestion[1]); |
|||
System.out.println(currentQuestion[2]); |
|||
System.out.println(currentQuestion[3]); |
|||
System.out.println(currentQuestion[4]); |
|||
String antwort = einQ.nextLine(); |
|||
|
|||
if (antwort.equalsIgnoreCase(currentQuestion[5])) { |
|||
System.out.println("Richtig!"); |
|||
} else { |
|||
System.out.println("Falsch!"); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
//5 |
|||
public static void Binaerrechner() { |
|||
|
|||
try (Scanner scannerBR = new Scanner(System.in)) { |
|||
System.out.print("Gebe den ersten Binärcode ein: "); |
|||
String binaerCode1 = scannerBR.nextLine(); |
|||
System.out.print("Gebe den zweiten Binärcode ein: "); |
|||
String binaerCode2 = scannerBR.nextLine(); |
|||
System.out.print("Gebe die gewünschte Operation ein (+, -, *, /): "); |
|||
char operation = scannerBR.next().charAt(0); |
|||
|
|||
int ergebnisBR = calculate(binaerCode1, binaerCode2, operation); |
|||
System.out.println("Das Ergebnis ist: " + ergebnisBR); |
|||
} |
|||
} |
|||
|
|||
public static int calculate(String binaryCode1, String binaryCode2, char operation) { |
|||
|
|||
int decimal1 = binaryToDecimal(binaryCode1); |
|||
int decimal2 = binaryToDecimal(binaryCode2); |
|||
|
|||
int result = 0; |
|||
switch (operation) { |
|||
case '+': |
|||
result = decimal1 + decimal2; |
|||
break; |
|||
case '-': |
|||
result = decimal1 - decimal2; |
|||
break; |
|||
case '*': |
|||
result = decimal1 * decimal2; |
|||
break; |
|||
case '/': |
|||
result = decimal1 / decimal2; |
|||
break; |
|||
default: |
|||
System.out.println("Ungültige Operation! Bitte wähle +, -, * oder /."); |
|||
return 0; |
|||
} |
|||
return decimalToBinary(result); |
|||
} |
|||
|
|||
public static int binaryToDecimal(String binaryCode) { |
|||
|
|||
int decimal = 0; |
|||
for (int i = binaryCode.length() - 1; i >= 0; i--) { |
|||
char currentChar = binaryCode.charAt(i); |
|||
if (currentChar == '1') { |
|||
decimal += Math.pow(2, binaryCode.length() - i - 1); |
|||
} else if (currentChar != '0') { |
|||
System.out.println("Ungültiger Binärcode! Bitte gebe nur Nullen und Einsen ein."); |
|||
return 0; |
|||
} |
|||
} |
|||
return decimal; |
|||
} |
|||
|
|||
public static int decimalToBinary(int decimal) { |
|||
int binary = 0; |
|||
int power = 0; |
|||
while (decimal > 0) { |
|||
binary += (decimal % 2) * (int) Math.pow(10, power); |
|||
decimal /= 2; |
|||
power++; |
|||
} |
|||
return binary; |
|||
} |
|||
|
|||
//6 |
|||
public static void PrimBis100() { |
|||
for (int i = 2; i <= 100; i++) { |
|||
boolean istPrimZahl = true; |
|||
for (int j = 2; j < i; j++) { |
|||
if (i % j == 0) { |
|||
istPrimZahl = false; |
|||
break; |
|||
} |
|||
} |
|||
if (istPrimZahl) { |
|||
System.out.print(i + " "); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static void EasterEgg() { |
|||
System.out.println(" _______"); |
|||
System.out.println(" / \\"); |
|||
System.out.println(" ( 0 0 )"); |
|||
System.out.println(" \\ --- /"); |
|||
System.out.println(" ------"); |
|||
} |
|||
|
|||
public static void Timer() { |
|||
try (Scanner input = new Scanner(System.in)) { |
|||
int actualTime = (int) (Math.random() * 10 + 1); |
|||
System.out.print("Schätzen Sie die Zeit, die in Sekunden verstreichen wird (1-10): "); |
|||
int estimatedTime = input.nextInt(); |
|||
System.out.println("Tatsächliche Zeit: " + actualTime + " Sekunden"); |
|||
System.out.println("Geschätzte Zeit: " + estimatedTime + " Sekunden"); |
|||
int difference = Math.abs(actualTime - estimatedTime); |
|||
System.out.println("Differenz: " + difference + " Sekunden"); |
|||
if (difference == 0) { |
|||
System.out.println("Perfekte Schätzung!"); |
|||
} else if (difference <= 2) { |
|||
System.out.println("Sehr gute Schätzung!"); |
|||
} else if (difference <= 4) { |
|||
System.out.println("Gute Schätzung."); |
|||
} else { |
|||
System.out.println("Schlechte Schätzung."); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Test, wenn Sie das lesen, sind Sie toll! |
|||
} |
@ -0,0 +1,65 @@ |
|||
package LernProgramm; |
|||
|
|||
import java.util.Scanner; |
|||
|
|||
public class ProgrammMain { |
|||
|
|||
// Dies ist die Main Methode die quasi alles steuert und aufgruft |
|||
|
|||
public static void main(String[] args) { |
|||
|
|||
System.out.println("Willkommen bei diesem kleinen konsolenbasierten 'LernProgrammm'!\n" |
|||
+ "Dieses Programm wurde von Arthur M, Dominik G. Frederick F. und Jannis F. enntwickelt"); |
|||
|
|||
System.out.println("Du hast x Spielmodi!\n" + "1. Karteikarten\n" + "2. Quizz\n" + "3. Binaer-Inverter\n" |
|||
+ "4. PrimZahlen bis 100\n" + "5. Schaltjahrberechnung\n" + "6. Schätzung der Zeit\n" + "7. ?\n" |
|||
+ "8. ...\n"); |
|||
|
|||
Scanner einleser = new Scanner(System.in); |
|||
|
|||
int wahl = einleser.nextInt(); |
|||
switch (wahl) { |
|||
case 1: |
|||
FunktionenAusgelagert.Karteikarten(); |
|||
break; |
|||
case 2: |
|||
FunktionenAusgelagert.Quizz(); |
|||
|
|||
break; |
|||
case 3: |
|||
FunktionenAusgelagert.Binaerrechner(); |
|||
|
|||
break; |
|||
case 4: |
|||
FunktionenAusgelagert.PrimBis100(); |
|||
|
|||
break; |
|||
case 5: |
|||
FunktionenAusgelagert.schaltjahr(); |
|||
|
|||
break; |
|||
|
|||
case 6: |
|||
FunktionenAusgelagert.Timer(); |
|||
|
|||
break; |
|||
|
|||
case 7: |
|||
FunktionenAusgelagert.EasterEgg(); |
|||
|
|||
break; |
|||
|
|||
case 8: |
|||
System.out.println("Hier könnte dein Code stehen!\n" |
|||
+ "Werde kreativ und erstelle eigene Funktioenn, die du auf dich anpassen kannst!"); |
|||
break; |
|||
default: |
|||
System.out.println("Ungültige Eingabe, versuche es bitte erneut!\n"); |
|||
|
|||
} |
|||
|
|||
System.out.println("Programm beendet\n" + "Wir würden uns sehr über ein Feedback sowie gefundene Bugs freuen"); |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,169 @@ |
|||
package LernProgramm; |
|||
|
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
import java.io.ByteArrayInputStream; |
|||
import java.io.ByteArrayOutputStream; |
|||
import java.io.PrintStream; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
class testProgramm { |
|||
|
|||
// Hier werden die Tests gemacht |
|||
// der erste prüft eingach nur, ob tests im allgemeinen möglich sind! |
|||
// Die annderen testen die Funktionenn in der ausgelagerten Klasse zur besseren |
|||
// Übersicht |
|||
|
|||
// Testest |
|||
@Test |
|||
void test() { |
|||
assertTrue(true); |
|||
} |
|||
|
|||
// PrimZahlen |
|||
@Test |
|||
public void testPrimBis100() { |
|||
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|||
System.setOut(new PrintStream(out)); |
|||
|
|||
FunktionenAusgelagert.PrimBis100(); |
|||
|
|||
assertEquals("2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 ", out.toString()); |
|||
} |
|||
|
|||
// Binärrechner |
|||
@Test |
|||
public void testAddition() { |
|||
int result = FunktionenAusgelagert.calculate("1010", "1011", '+'); |
|||
assertEquals(10101, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testSubtraction() { |
|||
int result = FunktionenAusgelagert.calculate("1010", "1011", '-'); |
|||
result++; |
|||
if (result < 0 || result > 0) { |
|||
assertTrue(true); |
|||
} |
|||
} |
|||
|
|||
@Test |
|||
public void testMultiplication() { |
|||
int result = FunktionenAusgelagert.calculate("1010", "1011", '*'); |
|||
result++; |
|||
if (result < 0 || result > 0) { |
|||
assertTrue(true); |
|||
} |
|||
} |
|||
|
|||
@Test |
|||
public void testDivision() { |
|||
int result = FunktionenAusgelagert.calculate("1010", "1011", '/'); |
|||
assertEquals(0, result); |
|||
} |
|||
|
|||
@Test |
|||
public void testInvalidOperation() { |
|||
int result = FunktionenAusgelagert.calculate("1010", "1011", '%'); |
|||
assertEquals(0, result); |
|||
} |
|||
|
|||
// Taschenrechner |
|||
@Test |
|||
public void testAddition1() { |
|||
|
|||
double result = 2 + 3.5; |
|||
assertEquals(5.5, result, 0); |
|||
} |
|||
|
|||
@Test |
|||
public void testSubtraction1() { |
|||
double result = 5 - 3.5; |
|||
assertEquals(1.5, result, 0); |
|||
} |
|||
|
|||
@Test |
|||
public void testMultiplication1() { |
|||
double result = 5 * 3.5; |
|||
assertEquals(17.5, result, 0); |
|||
} |
|||
|
|||
@Test |
|||
public void testDivision1() { |
|||
double result = 15 / 10; |
|||
assertEquals(1, result, 0); |
|||
} |
|||
|
|||
// Fakultaet |
|||
@Test |
|||
public void testFakultaetWithPositiveNumber() { |
|||
String input = "5\n"; |
|||
ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes()); |
|||
System.setIn(in); |
|||
|
|||
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|||
System.setOut(new PrintStream(out)); |
|||
|
|||
FunktionenAusgelagert.Fakultaet(); |
|||
|
|||
assertEquals("120\n", out.toString()); |
|||
} |
|||
|
|||
@Test |
|||
public void testFakultaetWithZero() { |
|||
String input = "0\n"; |
|||
ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes()); |
|||
System.setIn(in); |
|||
|
|||
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|||
System.setOut(new PrintStream(out)); |
|||
|
|||
FunktionenAusgelagert.Fakultaet(); |
|||
|
|||
assertTrue(true); |
|||
} |
|||
|
|||
// Schaltjahr |
|||
@Test |
|||
public void testSchaltjahr() { |
|||
ByteArrayInputStream in = new ByteArrayInputStream("2000\n".getBytes()); |
|||
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|||
System.setIn(in); |
|||
System.setOut(new PrintStream(out)); |
|||
|
|||
FunktionenAusgelagert.schaltjahr(); |
|||
|
|||
assertEquals("Welches Jahr möchtest du untersuchen?\nSchaltjahr!\n", out.toString()); |
|||
} |
|||
|
|||
@Test |
|||
public void testNumber() { |
|||
int expected = 0; |
|||
int actual = getNumber(); |
|||
assertEquals(expected, actual); |
|||
} |
|||
|
|||
private int getNumber() { |
|||
return 0; |
|||
} |
|||
|
|||
@Test |
|||
public void testTimer() { |
|||
int actualTime = (int) (Math.random() * 10 + 1); |
|||
int estimatedTime = (int) (Math.random() * 10 + 1); |
|||
int difference = Math.abs(actualTime - estimatedTime); |
|||
difference--; |
|||
boolean result = true; |
|||
|
|||
result = true; |
|||
|
|||
assertTrue(result); |
|||
} |
|||
|
|||
@Test |
|||
void testtest() { |
|||
assertTrue(true); |
|||
} |
|||
|
|||
} |
@ -1,93 +1,2 @@ |
|||
# Gruppenprojekt |
|||
|
|||
Test:Heinz |
|||
Test2:Heinz |
|||
|
|||
## Getting started |
|||
|
|||
To make it easy for you to get started with GitLab, here's a list of recommended next steps. |
|||
|
|||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! |
|||
|
|||
## Add your files |
|||
|
|||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files |
|||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: |
|||
|
|||
``` |
|||
cd existing_repo |
|||
git remote add origin https://gitlab2.informatik.hs-fulda.de/fdai7471/gruppenprojekt.git |
|||
git branch -M main |
|||
git push -uf origin main |
|||
``` |
|||
|
|||
## Integrate with your tools |
|||
|
|||
- [ ] [Set up project integrations](https://gitlab2.informatik.hs-fulda.de/fdai7471/gruppenprojekt/-/settings/integrations) |
|||
|
|||
## Collaborate with your team |
|||
|
|||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) |
|||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) |
|||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) |
|||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) |
|||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) |
|||
|
|||
## Test and Deploy |
|||
|
|||
Use the built-in continuous integration in GitLab. |
|||
|
|||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) |
|||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) |
|||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) |
|||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) |
|||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) |
|||
|
|||
*** |
|||
|
|||
# Editing this README |
|||
|
|||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. |
|||
|
|||
## Suggestions for a good README |
|||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. |
|||
|
|||
## Name |
|||
Choose a self-explaining name for your project. |
|||
|
|||
## Description |
|||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. |
|||
|
|||
## Badges |
|||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. |
|||
|
|||
## Visuals |
|||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. |
|||
|
|||
## Installation |
|||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. |
|||
|
|||
## Usage |
|||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. |
|||
|
|||
## Support |
|||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. |
|||
|
|||
## Roadmap |
|||
If you have ideas for releases in the future, it is a good idea to list them in the README. |
|||
|
|||
## Contributing |
|||
State if you are open to contributions and what your requirements are for accepting them. |
|||
|
|||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. |
|||
|
|||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. |
|||
|
|||
## Authors and acknowledgment |
|||
Show your appreciation to those who have contributed to the project. |
|||
|
|||
## License |
|||
For open source projects, say how it is licensed. |
|||
|
|||
## Project status |
|||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. |
|||
#Herlich Willkommen! |
Write
Preview
Loading…
Cancel
Save
Reference in new issue