diff --git a/.vscode/launch.json b/.vscode/launch.json index 7db1619..6dc00eb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,13 @@ // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "type": "java", + "name": "UI", + "request": "launch", + "mainClass": "UI", + "projectName": "PR2-L_e28f9f2c" + }, { "type": "java", "name": "FraktalDemoThread", diff --git a/SeparateU_Logic/.vscode/settings.json b/SeparateU_Logic/.vscode/settings.json new file mode 100644 index 0000000..0ac215c --- /dev/null +++ b/SeparateU_Logic/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "java.project.sourcePaths": ["src"], + "java.project.outputPath": "bin", + "java.project.referencedLibraries": [ + "lib/**/*.jar" + ] +} diff --git a/SeparateU_Logic/README.md b/SeparateU_Logic/README.md new file mode 100644 index 0000000..a43b9f6 --- /dev/null +++ b/SeparateU_Logic/README.md @@ -0,0 +1,18 @@ +## Getting Started + +Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. + +## Folder Structure + +The workspace contains two folders by default, where: + +- `src`: the folder to maintain sources +- `lib`: the folder to maintain dependencies + +Meanwhile, the compiled output files will be generated in the `bin` folder by default. + +> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. + +## Dependency Management + +The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). diff --git a/SeparateU_Logic/src/Logic.java b/SeparateU_Logic/src/Logic.java new file mode 100644 index 0000000..da5e02a --- /dev/null +++ b/SeparateU_Logic/src/Logic.java @@ -0,0 +1,37 @@ +public class Logic { + private int zahl1; + private int zahl2; + + public Logic(int z1, int z2) { + zahl1 = z1; + zahl2 = z2; + } + + private int add() { return zahl1 + zahl2; } + private int subtract() { return zahl1 - zahl2; } + private int multiply() { return zahl1 * zahl2; } + private int divide() { return zahl1 / zahl2; } + + /** + * This method adds, subtracts, .... + * + * @param op + * @return result of basic operation + */ + public int calculate(String op) + { + if(op.equals("+")) + return add(); + + if(op.equals("-")) + return subtract(); + + if(op.equals("*")) + return multiply(); + + if(op.equals(":")) + return divide(); + + return 0; + } +} diff --git a/SeparateU_Logic/src/UI.java b/SeparateU_Logic/src/UI.java new file mode 100644 index 0000000..a2ec935 --- /dev/null +++ b/SeparateU_Logic/src/UI.java @@ -0,0 +1,35 @@ +import java.util.Scanner; + +public class UI { + private static int zahl1; + private static int zahl2; + private static String operator; + + public static void main(String[] args) throws Exception { + eingabe(); + ausgabe(); + } + + public static void eingabe() { + Scanner sc = new Scanner(System.in); + + System.out.print("1. Zahl eingeben: " ); + zahl1 = sc.nextInt(); + + System.out.print("2. Zahl eingeben: " ); + zahl2 = sc.nextInt(); + + sc.nextLine(); + + System.out.print("Operand (+/-/*/:): " ); + operator = sc.nextLine(); + } + + public static void ausgabe() { + Logic c = new Logic(zahl1, zahl2); + + int ergebnis = c.calculate(operator); + + System.out.println("Das Ergebnis ist: " + ergebnis); + } +}