forked from Labore/PR2-L
add demo for UI-logic separation
parent
7c781659cf
commit
4ba4cec390
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"java.project.sourcePaths": ["src"],
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
]
|
||||
}
|
||||
|
|
@ -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).
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue