Compare commits
No commits in common. "5fb49043fab930335bde04227f448df0ea788e0e" and "1575f53c9b170ccace899560a0ed94e84d896636" have entirely different histories.
5fb49043fa
...
1575f53c9b
6 changed files with 0 additions and 361 deletions
85
.gitignore
vendored
85
.gitignore
vendored
|
@ -1,85 +0,0 @@
|
||||||
# Created by https://www.toptal.com/developers/gitignore/api/java,c
|
|
||||||
# Edit at https://www.toptal.com/developers/gitignore?templates=java,c
|
|
||||||
|
|
||||||
### C ###
|
|
||||||
# Prerequisites
|
|
||||||
*.d
|
|
||||||
|
|
||||||
# Object files
|
|
||||||
*.o
|
|
||||||
*.ko
|
|
||||||
*.obj
|
|
||||||
*.elf
|
|
||||||
|
|
||||||
# Linker output
|
|
||||||
*.ilk
|
|
||||||
*.map
|
|
||||||
*.exp
|
|
||||||
|
|
||||||
# Precompiled Headers
|
|
||||||
*.gch
|
|
||||||
*.pch
|
|
||||||
|
|
||||||
# Libraries
|
|
||||||
*.lib
|
|
||||||
*.a
|
|
||||||
*.la
|
|
||||||
*.lo
|
|
||||||
|
|
||||||
# Shared objects (inc. Windows DLLs)
|
|
||||||
*.dll
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.dylib
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
*.exe
|
|
||||||
*.out
|
|
||||||
*.app
|
|
||||||
*.i*86
|
|
||||||
*.x86_64
|
|
||||||
*.hex
|
|
||||||
|
|
||||||
# Debug files
|
|
||||||
*.dSYM/
|
|
||||||
*.su
|
|
||||||
*.idb
|
|
||||||
*.pdb
|
|
||||||
|
|
||||||
# Kernel Module Compile Results
|
|
||||||
*.mod*
|
|
||||||
*.cmd
|
|
||||||
.tmp_versions/
|
|
||||||
modules.order
|
|
||||||
Module.symvers
|
|
||||||
Mkfile.old
|
|
||||||
dkms.conf
|
|
||||||
|
|
||||||
### Java ###
|
|
||||||
# Compiled class file
|
|
||||||
*.class
|
|
||||||
|
|
||||||
# Log file
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# BlueJ files
|
|
||||||
*.ctxt
|
|
||||||
|
|
||||||
# Mobile Tools for Java (J2ME)
|
|
||||||
.mtj.tmp/
|
|
||||||
|
|
||||||
# Package Files #
|
|
||||||
*.jar
|
|
||||||
*.war
|
|
||||||
*.nar
|
|
||||||
*.ear
|
|
||||||
*.zip
|
|
||||||
*.tar.gz
|
|
||||||
*.rar
|
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
|
||||||
hs_err_pid*
|
|
||||||
replay_pid*
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/java,c
|
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Konto {
|
|
||||||
static double kontostand;
|
|
||||||
static Scanner scanner;
|
|
||||||
|
|
||||||
private static boolean isInt(String input) {
|
|
||||||
try {
|
|
||||||
Integer.parseInt(input);
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showBalance() {
|
|
||||||
System.out.printf("Kontostand: %f", kontostand);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void deposit() {
|
|
||||||
System.out.printf("Bitte geben Sie an, wie viel Geld sie einzahlen möchten: ");
|
|
||||||
String userInput;
|
|
||||||
while (true) {
|
|
||||||
userInput = scanner.nextLine();
|
|
||||||
if (isInt(userInput)) {
|
|
||||||
Double.parseDouble(userInput);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("Bitte geben Sie eine ganze Zahl ein.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
double cleanUserInput = Double.parseDouble(userInput);
|
|
||||||
kontostand += cleanUserInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void withdraw() {
|
|
||||||
System.out.printf("Bitte geben Sie ein, wie viel Sie abheben möchten: ");
|
|
||||||
String userInput;
|
|
||||||
while (true) {
|
|
||||||
userInput = scanner.nextLine();
|
|
||||||
if (isInt(userInput)) {
|
|
||||||
Double.parseDouble(userInput);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("Bitte geben Sie eine ganze Zahl ein.");
|
|
||||||
}
|
|
||||||
double cleanUserInput = Double.parseDouble(userInput);
|
|
||||||
if (cleanUserInput > kontostand) {
|
|
||||||
System.out.println("Der eingegebene Betrag ist größer als der Kontostand.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
kontostand -= cleanUserInput;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void menu() {
|
|
||||||
System.out.println("1. Kontostandanzeige");
|
|
||||||
System.out.println("2. Einzahlung");
|
|
||||||
System.out.println("3. Auszahlung");
|
|
||||||
System.out.println("4. Verlassen");
|
|
||||||
System.out.printf("Eingabe: ");
|
|
||||||
String userInput;
|
|
||||||
while (true) {
|
|
||||||
userInput = scanner.nextLine();
|
|
||||||
if (isInt(userInput)) {
|
|
||||||
Integer.parseInt(userInput);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
System.out.println("Bitte geben Sie eine ganze Zahl ein.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int cleanUserInput = Integer.parseInt(userInput);
|
|
||||||
while (true) {
|
|
||||||
switch (cleanUserInput) {
|
|
||||||
case 1:
|
|
||||||
showBalance();
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
deposit();
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
withdraw();
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
System.out.println("Verlassen...");
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
kontostand = 0;
|
|
||||||
scanner = new Scanner(System.in);
|
|
||||||
menu();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
Main-Class: vorbereitungen.MonteCarlo.MonteCarlo
|
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
package vorbereitungen.MonteCarlo;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class MonteCarlo {
|
|
||||||
public static void main(String args[]) {
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
System.out.println("Enter how many attempts you want to run:");
|
|
||||||
String attempts = scanner.nextLine();
|
|
||||||
|
|
||||||
try {
|
|
||||||
int num_attempts = Integer.parseInt(attempts);
|
|
||||||
} catch(NumberFormatException nfe) {
|
|
||||||
System.out.println("Invalid input.");
|
|
||||||
scanner.close();
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int num_attempts = Integer.parseInt(attempts);
|
|
||||||
|
|
||||||
System.out.println("Enter how large the initial bankroll should be:");
|
|
||||||
String bankroll = scanner.nextLine();
|
|
||||||
|
|
||||||
try {
|
|
||||||
int num_bankroll = Integer.parseInt(bankroll);
|
|
||||||
} catch(NumberFormatException nfe) {
|
|
||||||
System.out.println("Invalid input.");
|
|
||||||
scanner.close();
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int num_bankroll = Integer.parseInt(bankroll);
|
|
||||||
|
|
||||||
System.out.println("Enter the Betsize you want to use for this simulation:");
|
|
||||||
String betsize = scanner.nextLine();
|
|
||||||
|
|
||||||
try {
|
|
||||||
int num_betsize = Integer.parseInt(betsize);
|
|
||||||
} catch(NumberFormatException nfe) {
|
|
||||||
System.out.println("Invalid input.");
|
|
||||||
scanner.close();
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int num_betsize = Integer.parseInt(betsize);
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
Simulation simulation = new Simulation(num_attempts, num_bankroll, num_betsize);
|
|
||||||
simulation.run();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package vorbereitungen.MonteCarlo;
|
|
||||||
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
|
|
||||||
public class Simulation{
|
|
||||||
int max_attempts;
|
|
||||||
int current_attempts;
|
|
||||||
double starting_bankroll;
|
|
||||||
double current_bankroll;
|
|
||||||
double simulated_betsize;
|
|
||||||
|
|
||||||
public Simulation(int max_atts, int bankroll, double betsize) {
|
|
||||||
this.max_attempts = max_atts;
|
|
||||||
this.current_attempts = 1;
|
|
||||||
this.starting_bankroll = bankroll;
|
|
||||||
this.current_bankroll = bankroll;
|
|
||||||
this.simulated_betsize = betsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int roll() {
|
|
||||||
return ThreadLocalRandom.current().nextInt(1, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double calculate(int player_roll, int dealer_roll) {
|
|
||||||
int diff = dealer_roll - player_roll;
|
|
||||||
if (diff >= 1) {return 0;}
|
|
||||||
else if (diff == 0) {return 1;}
|
|
||||||
else if (diff == -6) {return 2;}
|
|
||||||
else {return 1.5;}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handle() {
|
|
||||||
if (this.simulated_betsize > this.current_bankroll) {
|
|
||||||
System.out.println("|===Out of money===|");
|
|
||||||
System.out.printf("|Attempts: %d |\n", this.current_attempts);
|
|
||||||
System.out.println("===================|");
|
|
||||||
System.exit(2137);
|
|
||||||
}
|
|
||||||
this.current_bankroll -= this.simulated_betsize;
|
|
||||||
int player_roll = roll();
|
|
||||||
int house_roll = roll();
|
|
||||||
double mult = calculate(player_roll, house_roll);
|
|
||||||
this.current_bankroll += this.simulated_betsize*mult;
|
|
||||||
this.current_attempts++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void print_progress() {
|
|
||||||
double bankroll_percentage = (this.current_bankroll/this.starting_bankroll)*100;
|
|
||||||
double attempt_percentage = (this.current_attempts/this.max_attempts)*100;
|
|
||||||
System.out.printf("\033[2J"); // Clear screen
|
|
||||||
System.out.println("|===========|");
|
|
||||||
System.out.printf("|Current Attempt: %d/%d|\n", this.current_attempts, this.max_attempts);
|
|
||||||
System.out.printf("|Current Bankroll: %f|\n", this.current_bankroll);
|
|
||||||
System.out.printf("|%f%% left of starting bankroll\n|", bankroll_percentage);
|
|
||||||
System.out.printf("|%f%% done|", attempt_percentage);
|
|
||||||
System.out.println("|===========|");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
for (int i = 0; i < max_attempts; i++) {
|
|
||||||
handle();
|
|
||||||
if (this.current_attempts % 7500 == 0 || this.current_attempts == 1) {
|
|
||||||
print_progress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class SieveOfErathostenes {
|
|
||||||
private static void isValid(String input) {
|
|
||||||
if (input == null) {System.exit(-1);}
|
|
||||||
try {
|
|
||||||
Integer.parseInt(input);
|
|
||||||
} catch (NumberFormatException nfe) {
|
|
||||||
System.out.println("Die eingegebene Zahl ist keine ganze Zahl");
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
int cleanInput = Integer.parseInt(input);
|
|
||||||
if (cleanInput < 2 || cleanInput > 1000) {
|
|
||||||
System.out.println("Die eingegebene Zahl muss mindestens 2 sein und höchstens 1000 sein.");
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printArray(boolean[] arr) {
|
|
||||||
for (int i = 0; i < arr.length; i++) {
|
|
||||||
if (arr[i]) {
|
|
||||||
System.out.printf("%d ", i + 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.printf("%n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
//System.out.println("Sanity Check");
|
|
||||||
Scanner input_scanner = new Scanner(System.in);
|
|
||||||
System.out.println("Bitte gib eine Zahl ein. ");
|
|
||||||
String user_input = input_scanner.nextLine();
|
|
||||||
input_scanner.close();
|
|
||||||
isValid(user_input);
|
|
||||||
int clean_input = Integer.parseInt(user_input);
|
|
||||||
|
|
||||||
boolean[] primes = new boolean[clean_input];
|
|
||||||
Arrays.fill(primes, true);
|
|
||||||
|
|
||||||
for (int i = 1; i < clean_input; i++) {
|
|
||||||
if (i == 1) {continue;}
|
|
||||||
if (primes[i]) {
|
|
||||||
for (int j = 2; j < clean_input; j++) {
|
|
||||||
int tmp = j*i;
|
|
||||||
if (tmp > clean_input) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
primes[tmp - 2] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
primes[clean_input - 1] = false;
|
|
||||||
printArray(primes);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue