started with the TicTacToe_MinMax Project. Finished the rendering of the game.

TODO: Make a playable version and add MinMax
This commit is contained in:
2020-06-14 23:13:33 +02:00
parent c1ebe11e2f
commit 99d9170365
145 changed files with 8952 additions and 0 deletions

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

15
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ATM-Machine/ATM-Machine.iml" filepath="$PROJECT_DIR$/ATM-Machine/ATM-Machine.iml" />
<module fileurl="file://$PROJECT_DIR$/BruitForce/BruitForce.iml" filepath="$PROJECT_DIR$/BruitForce/BruitForce.iml" />
<module fileurl="file://$PROJECT_DIR$/CodingChallanges/CodingChallanges.iml" filepath="$PROJECT_DIR$/CodingChallanges/CodingChallanges.iml" />
<module fileurl="file://$PROJECT_DIR$/DemoProjects/DemoProjects.iml" filepath="$PROJECT_DIR$/DemoProjects/DemoProjects.iml" />
<module fileurl="file://$PROJECT_DIR$/ImageToText/ImageToText.iml" filepath="$PROJECT_DIR$/ImageToText/ImageToText.iml" />
<module fileurl="file://$PROJECT_DIR$/LanguageAnalysis/LanguageAnalysis.iml" filepath="$PROJECT_DIR$/LanguageAnalysis/LanguageAnalysis.iml" />
<module fileurl="file://$PROJECT_DIR$/TOOLS/TOOLS.iml" filepath="$PROJECT_DIR$/TOOLS/TOOLS.iml" />
<module fileurl="file://$PROJECT_DIR$/TicTacToe_MinMax/TicTacToe_MinMax.iml" filepath="$PROJECT_DIR$/TicTacToe_MinMax/TicTacToe_MinMax.iml" />
</modules>
</component>
</project>

124
.idea/uiDesigner.xml generated Normal file
View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,28 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
public class Accounts {
private String path;
private File file;
private ArrayList<File> files;
public Accounts() {
String path = System.getProperty("user.home")+"/.accounts";
File file = new File(path);
//Creates filesystem if not present
file.mkdir();
//Reads all files from the folder
files = new ArrayList<>(Arrays.asList(file.listFiles()));
}
public boolean isValidAcc(String name, String code){
return true;
}
public static void main(String[] args) {
Accounts acc = new Accounts();
}
}

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Operator

View File

@@ -0,0 +1,4 @@
package src;
public class NumberPicker {
}

View File

@@ -0,0 +1,122 @@
import java.util.Scanner;
public class Operator {
private int balance;
private int options;
private int pin;
private boolean isActive;
public Operator() {
balance = 100;
options = -1;
pin = 1234;
isActive = true;
}
private void printMenu() {
System.out.println("Which action do you want to take?");
System.out.println(" 1. Check balance");
System.out.println(" 2. Add money to account");
System.out.println(" 3. Withdraw money from account");
System.out.println(" 4. Change Pin");
System.out.println(" 5. Cancel action");
}
public void manage() {
System.out.println("Welcome to the ATM");
while (isActive) {
printMenu();
Scanner numScanner = new Scanner(System.in);
int option = numScanner.nextInt();
switch (option) {
case 1:
System.out.println();
System.out.printf("Your account balance is %d€\n", balance);
System.out.println();
break;
case 2:
System.out.println();
System.out.println("How much money do you want to add to your account?");
Scanner addScanner = new Scanner(System.in);
int amountAdded = addScanner.nextInt();
balance += amountAdded;
System.out.println();
System.out.printf("%d€ added to your account\n", amountAdded);
System.out.printf("New balance: %d€\n", balance);
System.out.println();
break;
case 3:
System.out.println();
int tries = 3;
while (tries > 0) {
System.out.println("Please enter your pin");
Scanner pinScanner = new Scanner(System.in);
if (pinScanner.nextInt() == pin) {
while (true) {
System.out.println("Which amount do you want to withdraw from your account?");
Scanner amountScanner = new Scanner(System.in);
int amount = amountScanner.nextInt();
if (amount < balance) {
System.out.printf("%d€ got withdrawn from your Account\n", amount);
balance -= amount;
System.out.printf("New balance: %d", balance);
System.out.println();
break;
} else {
System.out.printf("You can only withdraw %d€\n", balance);
System.out.println();
}
}
break;
} else {
tries -= 1;
System.err.println("The entered pin is incorrect");
System.out.printf("%d tries left\n", tries);
}
}
if (tries <= 0) {
System.err.println("Action canceled");
isActive = false;
}
break;
case 4:
System.out.println();
System.out.println("Enter your pin");
Scanner pinScanner = new Scanner(System.in);
int oldPin = pinScanner.nextInt();
boolean pinNotValid = true;
while (pinNotValid) {
if (oldPin == pin) {
System.out.println("Enter a new 4-digit pin");
int newPin = pinScanner.nextInt();
if ((newPin + "").length() == 4) {
pin = newPin;
pinNotValid = false;
} else {
System.out.println("You have to enter a 4-digit pin");
}
} else {
System.err.println("Wrong pin entered");
}
}
System.out.println();
break;
case 5:
System.out.println();
System.err.println("Action canceled");
isActive = false;
}
}
}
public static void main(String[] args) {
Operator operator = new Operator();
operator.manage();
}
}

12
BruitForce/BruitForce.iml Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="TOOLS" exported="" />
</component>
</module>

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.BiteCoding.github.Simulation

View File

@@ -0,0 +1,17 @@
package com.BiteCoding.github;
public class Decoder {
private char[] possibleChars;
public Decoder() {
possibleChars = new char[]{ 'a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w', 'x',
'y','z' };
}
public String decode(int n){
return Character.toString(possibleChars[n]);
}
}

View File

@@ -0,0 +1,73 @@
package com.BiteCoding.github;
import javax.swing.*;
import util.Timer;
public class Simulation {
private Decoder decoder;
private Timer timer;
private String password;
private boolean properPassword;
public Simulation() {
decoder = new Decoder();
timer = new Timer();
properPassword = false;
}
public void start(){
String s = new String();
while (!properPassword) {
s = JOptionPane.showInputDialog("put in a password with 6 chars and only using" +
" the alphabet");
if (s.length() == 6 && s.matches(".*[a-zA-Z]+.*")){
properPassword = true;
} else {
JOptionPane.showMessageDialog(null, "not a valid entry");
}
}
password = s.toLowerCase();
timer.start();
crackIt();
}
private void crackIt(){
for (int i = 0; i < 26; i++) {
String s1 = decoder.decode(i);
for (int j = 0; j < 26; j++) {
String s2 = decoder.decode(j);
for (int k = 0; k < 26; k++) {
String s3 = decoder.decode(k);
for (int l = 0; l < 26; l++) {
String s4 = decoder.decode(l);
for (int m = 0; m < 26; m++) {
String s5 = decoder.decode(m);
for (int n = 0; n < 26; n++) {
String s6 = decoder.decode(n);
String possiblePassword = s1+s2+s3+s4+s5+s6;
if (possiblePassword.equals(password)){
timer.end();
JOptionPane.showMessageDialog(null, "Das Passwort war " + password);
JOptionPane.showMessageDialog(null, timer.timeNeeded());
System.exit(0);
}
}
}
}
}
}
}
}
public static void main(String[] args) {
Simulation simulation = new Simulation();
simulation.start();
}
}

View File

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="var" path="MAVEN_REPOSITORY/junit/junit/4.12/junit-4.12.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

15
CodingChallanges/.project Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CodingChallanges</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inherit-compiler-output="true" inheritJdk="true">
<output-test url="file://$USER_HOME$/Documents/real-java/out/test/CodingChallanges"/>
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$"/>
</component>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,51 @@
package arrays;
import java.util.Arrays;
public class PoppingBlocks {
//Edabit-Challange
//https://edabit.com/challenge/p38KD5Far2g72fv3d
public static char[] finalResult(char[] letters) {
int firstIndex = -1;
int lastIndex = -1;
char[] newLetters = new char[0];
for (int i = 0; i < letters.length - 1; i++) {
if (letters[i] == letters[i + 1]) {
firstIndex = i;
break;
}
}
if (firstIndex != -1) {
for (int j = firstIndex; j < letters.length; j++) {
if (letters[j] != letters[firstIndex]) {
lastIndex = j - 1;
break;
}
if (j == letters.length - 1) {
lastIndex = j;
break;
}
}
newLetters = new char[letters.length - (lastIndex - firstIndex) - 1];
int j = 0;
for (int i = 0; i < letters.length; i++) {
if (i < firstIndex || i > lastIndex) {
newLetters[j] = letters[i];
j++;
}
}
}
if (firstIndex == -1) {
return letters;
}
return finalResult(newLetters);
}
public static void main(String[] args) {
System.out.println(finalResult(new char[]{'B', 'B', 'C', 'C', 'A', 'A', 'A'}));
}
}

View File

@@ -0,0 +1,19 @@
package geometry;
public class PentagonalNumber {
//Edabit-Challange
//https://edabit.com/challenge/H6eTNH6NW36MHqkjb
public static int pentagonal(int num) {
int outerRings = 0;
for(int i = num-1; i > 0; i--){
outerRings += i * 5;
}
return outerRings + 1;
}
public static void main(String[] args) {
System.out.println(pentagonal(10));
}
}

View File

@@ -0,0 +1,26 @@
package geometry;
import java.util.Arrays;
public class makeGrid {
//Edabit-Challange
//https://edabit.com/challenge/7Tb7qMDQHtz3xpydd
public static int[][] squarePatch( int n ){
int[][] array = new int[n][n];
int i = 0;
while (i < n){
for (int j = 0; j < n; j++){
array[i][j] = n;
}
i++;
}
return array;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(squarePatch(4)));
}
}

View File

@@ -0,0 +1,48 @@
package numbers;
public class CarryingTheDigits {
//Edabit-Challange:
//https://edabit.com/challenge/5snfPLPbvjAsZ5kjo
public static int carryDigits(int n1, int n2){
String firstNum = String.valueOf(n1);
String secondNum = String.valueOf(n2);
String first = new String();
String second = new String();
if (firstNum.length() > secondNum.length()){
String filler = new String();
for (int i = 0; i < firstNum.length()-secondNum.length();i++){
filler += "0";
}
first = firstNum;
second = filler + secondNum;
} else {
String filler = new String();
for (int i = 0; i < secondNum.length()-firstNum.length();i++){
filler += "0";
}
first = filler + firstNum;
second = secondNum;
}
System.out.println(first+ ", "+ second);
int tempCarry = 0;
int carry = 0;
for (int i = first.length()-1; i >= 0; i--){
int num = Integer.parseInt(Character.toString(first.charAt(i))) + Integer.parseInt(Character.toString(second.charAt(i))) + tempCarry;
if (num > 9){
tempCarry = num - 9;
if (tempCarry <= 0) {
tempCarry = 0;
}
carry++;
}
}
return carry;
}
public static void main(String[] args) {
System.out.println( carryDigits(671, 329));
}
}

View File

@@ -0,0 +1,21 @@
package numbers;
public class FindPrimorial {
//Edabit-Link
//https://edabit.com/challenge/Tyzp6S67dtXPAAQan
static int[] primes = {2, 3, 5, 7, 11, 13, 17, 19};
public static int primorial(int n) {
if (n > 0) {
int primorial = primes[n-1] * primorial(n - 1);
return primorial;
} else {
return 1;
}
}
public static void main(String[] args) {
System.out.println(primorial(1));
}
}

View File

@@ -0,0 +1,27 @@
package numbers;
public class HowManyPrimes_NOT_SOLVED {
//Edabit link
//https://edabit.com/challenge/z8vvSdWjAPu5ufBuR
public static int findPrimes(int boundary){
int primes = 0;
for (int i = 0; i < boundary; i++){
if (i % 2 != 0 && i!= 0){
for (int j = 1; j < 10; j = j+2){
if (i/j == 1){
}
}
}
}
return primes;
}
public static void main(String[] args) {
int boundary = 100;
System.out.printf("There are %d primes within the range of 0-%d",findPrimes(boundary),boundary);
}
}

View File

@@ -0,0 +1,27 @@
package numbers;
public class MaxFirstNum {
public static int maxPossible(int n1, int n2) {
String firstNum = n1 + "";
String secondNum = n2 + "";
String maxNum = null;
for (int i = 0; i < firstNum.length(); i++){
int num1 = Integer.parseInt(Character.toString(firstNum.charAt(i)));
boolean found = false;
for (int j = 0; j < secondNum.length(); j++){
if (num1 < Integer.parseInt(Character.toString(secondNum.charAt(i)))){
firstNum.replace(Character.toString(firstNum.charAt(i)), Character.toString(secondNum.charAt(j)));
secondNum.replace(Character.toString(secondNum.charAt(j)),"");
}
}
}
return Integer.parseInt(firstNum);
}
public static void main(String[] args) {
System.out.println(maxPossible(9132, 5564));
}
}

View File

@@ -0,0 +1,29 @@
package numbers;
public class SimplifyFractions {
//Edabit-Challange
//https://edabit.com/challenge/bmwpoeCybNWnBxn7M
public static String simplify(String str) {
String[] numbers = str.split("/");
int firstNum = Integer.parseInt(numbers[0]);
int secondNum = Integer.parseInt(numbers[1]);
int lowNum = Math.min(firstNum, secondNum);
for (int i = lowNum; i > 0; i--){
if (firstNum % i == 0 && secondNum % i == 0){
firstNum = firstNum/i;
secondNum = secondNum/i;
}
}
if (firstNum % secondNum == 0){
return firstNum/secondNum+"";
} else{
return firstNum+"/"+secondNum;
}
}
public static void main(String[] args) {
System.out.println(simplify("100/400"));
}
}

View File

@@ -0,0 +1,38 @@
package numbers;
// Link: https://edabit.com/challenge/RvxGLMzoPoBgXhcaC
public class ValidateCreditCard {
public static boolean validateCard(long num) {
if ((num+"").length()<14 || (num+"".length()<20)){
return false;
}
int checkDigit = Integer.parseInt((num+"").substring((num+"").length()-1));
int[] numInArray = new int [(num+"").length()-1];
for (int i = 1; i < numInArray.length+1; i++){
numInArray[i-1] = Integer.parseInt((num+"").substring((num+"").length()-i-1, (num+"").length()-i));
if (i % 2 == 1){
numInArray[i-1] *= 2;
if (numInArray[i-1]>9){
numInArray[i-1] = (numInArray[i-1]/10) + (numInArray[i-1]-10);
}
}
}
int sum = 0;
for (int i = 0; i < numInArray.length; i++){
sum += numInArray[i];
}
return 10 - (sum-((sum/10)*10)) == checkDigit;
}
public static void main(String[] args) {
System.out.println(validateCard(1234567890123456L));
}
}

View File

@@ -0,0 +1,26 @@
package strings;
import java.util.Arrays;
public class CharacterMapping {
//Edabit-Challange
//https://edabit.com/challenge/zcobRojF5p8DWkfiC
public static int[] characterMapping(String str) {
int[] mappedArr = new int[str.length()];
String chars = new String();
for (int i = 0; i < str.length(); i++){
if (chars.indexOf(str.charAt(i)) == -1){
chars += str.charAt(i);
}
mappedArr[i] = chars.indexOf(str.charAt(i));
}
return mappedArr;
}
public static void main(String[] args) {
System.out.println(Arrays.toString(characterMapping("hmmmmm")));
}
}

View File

@@ -0,0 +1,54 @@
package strings;
import java.util.LinkedList;
public class DistanceToNearestVowel {
//Edabit-Challange
//https://edabit.com/challenge/Ls6pbLkC9wfYuaDgm
public static int[] distanceToNearestVowel(String str) {
LinkedList<Character> vowels= new LinkedList<Character>();
char[] vowelsArr = new char[]{'a', 'e', 'i', 'o', 'u'};
for (int i = 0; i < vowelsArr.length; i++) {
vowels.add(vowelsArr[i]);
}
LinkedList<Integer> values = new LinkedList<>();
for (int i = 0; i < str.length();i++){
if (vowels.contains(str.charAt(i))){
values.addLast(1);
} else{
values.addLast(0);
}
}
LinkedList<Integer> indexesVowels = new LinkedList<>();
for (int i = 0 ; i < values.size(); i++){
if (values.get(i) == 1){
indexesVowels.addLast(i);
}
}
int[] distances = new int[values.size()];
for (int i = 0; i < distances.length; i++){
distances[i] = 1000;
}
for (int i = 0; i < values.size(); i++){
if (values.get(i) == 1){
distances[i] = 0;
}
}
for (int i = 0; i < indexesVowels.size(); i++){
for (int j = 0; j < distances.length; j++){
if (distances[j] != 0){
if (distances[j] > Math.abs(j - indexesVowels.get(i))){
distances[j] = Math.abs(j - indexesVowels.get(i));
}
}
}
}
return distances;
}
public static void main(String[] args) {
distanceToNearestVowel("shopper");
}
}

View File

@@ -0,0 +1,33 @@
package strings;
import java.util.Arrays;
import java.util.Stack;
public class FilterStringArray {
//Edabit-Link
//https://edabit.com/challenge/vNszi3mbJA5BhgGFX
public static String[] filterArray(String[] str) {
Stack<String> stack = new Stack<>();
int stackSize = 0;
for (int i = 0; i < str.length; i++) {
try {
int possibleNum = Integer.parseInt(str[i]);
if (stack.search(possibleNum) < 0) {
stack.push(str[i]);
stackSize++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
String[] strArray = new String[stackSize];
return stack.toArray(strArray);
}
public static void main(String[] args) {
System.out.println(Arrays.toString(filterArray(new String[]{"1", "2", "aasf", "1", "123", "123"})));
}
}

View File

@@ -0,0 +1,64 @@
package strings;
//Link: https://edabit.com/challenge/FToTLuiB7bmFngkjr
public class FiscalCode {
static String[] months = {"A", "B", "C", "D", "E", "H", "L", "M", "P", "R", "S", "T"};
static String vowels = "AEIOU";
public static String fiscalCode(String name, String surName, String gender, String dob) {
String returnString = "";
returnString += generateLetters(surName, 's');
returnString += generateLetters(name, 'n');
returnString += generateNumbers(dob, gender);
return returnString;
}
private static String generateLetters(String string, char mode) {
String returnString = "";
string = string.toUpperCase();
for (int i = 0; i < string.length(); i++) {
if (vowels.indexOf(string.charAt(i)) == -1) {
returnString += string.charAt(i);
}
}
if (returnString.length() == 3) {
return returnString;
} else if (returnString.length() > 3) {
if (mode != 'n' && mode != 's') {
System.err.println("Not a valid value");
System.exit(0);
}
return mode == 'n' ? "" + returnString.charAt(0) + returnString.charAt(2) + returnString.charAt(3) : returnString.substring(0, 3);
} else {
int index = 0;
while (returnString.length() < 3 && string.length() > index) {
if (vowels.indexOf(string.charAt(index)) > -1) {
returnString += string.charAt(index);
}
index++;
}
return returnString.length() == 3 ? returnString : returnString + "X";
}
}
private static String generateNumbers(String dob, String gender) {
String returnString = "";
String date = dob.substring(dob.length() - 2);
int month = Integer.parseInt(dob.substring(dob.indexOf("/") + 1, dob.lastIndexOf("/")))-1;
if (gender.equals("M")) {
return date + months[month] + (dob.substring(0, dob.indexOf("/")).length() == 2 ? dob.substring(0, dob.indexOf("/")) :
0 + dob.substring(0, dob.indexOf("/")));
} else {
int day = Integer.parseInt(dob.substring(0, dob.indexOf("/")))+40;
return date + months[month] + day;
}
}
public static void main(String[] args) {
System.out.println(fiscalCode("Mickey", "Mouse", "M", "6/1/1928"));
}
}

View File

@@ -0,0 +1,40 @@
package strings;
import java.util.LinkedList;
public class LongestAlternatingSubstring {
//Edabit-Challange
//https://edabit.com/challenge/De5e8kdsCFmKvc6w8
public static String longestSubstring(String digits) {
char[] digitsArr = digits.toCharArray();
LinkedList<Integer> indexes = new LinkedList<>();
indexes.addLast(0);
for (int i = 0; i < digitsArr.length - 1; i++) {
if ((digitsArr[i] % 2 == 0 && digitsArr[i + 1] % 2 == 0) || (digitsArr[i] % 2 != 0 && digitsArr[i + 1] % 2 != 0)) {
indexes.addLast(i+1 );
}
}
indexes.addLast(digits.length());
LinkedList<String> substrings = new LinkedList<String>();
LinkedList<Integer> indexDump = (LinkedList<Integer>) indexes.clone();
for (int i = 0; i < indexes.size()-1; i++) {
if (indexDump.get(i+1)-indexDump.get(i)>1) {
String sub = digits.substring(indexDump.get(i), indexDump.get(i + 1));
substrings.addLast(sub);
}
}
String longest = new String();
for (int i = 0;i < substrings.size();i++){
if (substrings.get(i).length() > longest.length()){
longest = substrings.get(i);
}
}
return "lll";
}
public static void main(String[] args) {
longestSubstring("594127169973391692147228678476");
}
}

View File

@@ -0,0 +1,23 @@
package strings;
public class SmoothSentences {
//Edabit-Challange
//https://edabit.com/challenge/FtoNXq7DTCAiZ3z9T
public static boolean isSmooth(String sentence) {
String[] words = sentence.toLowerCase().split("\\s+");
for (int i = 0; i < words.length-1; i++){
char lastChar = words[i].charAt(words[i].length()-1);
char firstChar = words[i+1].charAt(0);
if (lastChar != firstChar){
return false;
}
}
return true;
}
public static void main(String[] args) {
System.out.println(isSmooth("Marigold daffodils streaming happily."));
}
}

View File

@@ -0,0 +1,43 @@
package strings;
public class WordChain {
String link = "https://edabit.com/challenge/hbHJdMv4HubYs5TRv";
public static boolean isWordChain(String[] words){
String firstWord, secondWord;
for (int i = 0; i < words.length-1; i++){
int differences = 0;
firstWord = words[i];
secondWord = words[i+1];
if (firstWord.length() == secondWord.length()){
for (int j = 0; j < firstWord.length(); j++){
if (firstWord.charAt(j) != secondWord.charAt(j)){
differences++;
}
}
} else if(firstWord.length() > secondWord.length()){
differences = firstWord.length()-secondWord.length();
for (int j = 0; j < secondWord.length(); j++){
if (firstWord.charAt(j) != secondWord.charAt(j)){
differences++;
}
}
} else {
differences = secondWord.length()-firstWord.length();
for (int j = 0; j < firstWord.length(); j++){
if (firstWord.charAt(j) != secondWord.charAt(j)){
differences++;
}
}
}
if (differences > 1){
break;
}
differences = 0;
}
return false;
}
}

View File

@@ -0,0 +1,35 @@
package tests;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import strings.FiscalCode;
/**
* @author edwardclark
**/
public class FiscalCodeTest {
@Test
public void test1() throws Exception {
assertEquals("CHEBND61T01", FiscalCode.fiscalCode("Brendan", "Eich", "M", "1/12/1961"));
}
@Test
public void test2() throws Exception {
assertEquals("YUXHLN50T41", FiscalCode.fiscalCode("Helen", "Yu", "F", "1/12/1950"));
}
@Test
public void test3() throws Exception {
assertEquals("CPNLAX99A17", FiscalCode.fiscalCode("Al", "Capone", "M", "17/1/1899"));
}
@Test
public void test4() throws Exception {
assertEquals("MSOMKY28A16", FiscalCode.fiscalCode("Mickey", "Mouse", "M", "16/1/1928"));
}
@Test
public void test5() throws Exception {
assertEquals("CRUMRA67S47", FiscalCode.fiscalCode("Marie", "Curie", "F", "7/11/1867"));
}
}

View File

@@ -0,0 +1,34 @@
package tests;
import org.junit.Assert;
import org.junit.Test;
import translation_encryption.PigLatinTranslation;
import static org.junit.Assert.assertEquals;
public class PigLatinTranslationTest {
@Test
public void test1() {
Assert.assertEquals("Atscay areway reatgay etspay.", PigLatinTranslation.pigLatin("Cats are great pets."));
}
@Test
public void test2() {
assertEquals("Omtay otgay away mallsay iecepay ofway iepay.", PigLatinTranslation.pigLatin("Tom got a small piece of pie."));
}
@Test
public void test3() {
assertEquals("Ehay oldtay usway away eryvay excitingway aletay.", PigLatinTranslation.pigLatin("He told us a very exciting tale."));
}
@Test
public void test4() {
assertEquals("Away iamondday isway otnay enoughway.", PigLatinTranslation.pigLatin("A diamond is not enough."));
}
@Test
public void test5() {
assertEquals("Urryhay!", PigLatinTranslation.pigLatin("Hurry!"));
}
}

View File

@@ -0,0 +1,53 @@
package tests;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import numbers.ValidateCreditCard;
public class ValidateCreditCardTest {
@Test
public void test1() {
assertEquals(false, ValidateCreditCard.validateCard(79927398714L));
}
@Test
public void test2() {
System.out.println("Passes Luhn test, but too short.");
assertEquals(false, ValidateCreditCard.validateCard(79927398713L));
}
@Test
public void test3() {
assertEquals(true, ValidateCreditCard.validateCard(709092739800713L));
}
@Test
public void test4() {
assertEquals(false, ValidateCreditCard.validateCard(1234567890123456L));
}
@Test
public void test5() {
assertEquals(true, ValidateCreditCard.validateCard(12345678901237L));
}
@Test
public void test6() {
assertEquals(true, ValidateCreditCard.validateCard(5496683867445267L));
}
@Test
public void test7() {
assertEquals(false, ValidateCreditCard.validateCard(4508793361140566L));
}
@Test
public void test8() {
assertEquals(true, ValidateCreditCard.validateCard(376785877526048L));
}
@Test
public void test9() {
assertEquals(false, ValidateCreditCard.validateCard(36717601781975L));
}
}

View File

@@ -0,0 +1,51 @@
package tests;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import strings.WordChain;
public class WordChainTest {
@Test
public void test1() {
assertEquals(true, WordChain.isWordChain(new String[]{"row", "crow", "crown", "brown", "brawn"}));
}
@Test
public void test2() {
assertEquals(true, WordChain.isWordChain(new String[]{"flew", "flaw", "flan", "flat", "fat", "rat", "rot", "tot"}));
}
@Test
public void test3() {
assertEquals(false, WordChain.isWordChain(new String[]{"meek", "meet", "meat", "teal"}));
}
@Test
public void test4() {
assertEquals(false, WordChain.isWordChain(new String[]{"run", "runny", "bunny"}));
}
@Test
public void test5() {
assertEquals(true, WordChain.isWordChain(new String[]{"fun", "fund", "find", "bind", "wind", "wild", "wile", "wiles"}));
}
@Test
public void test6() {
assertEquals(true, WordChain.isWordChain(new String[]{"nut", "but", "bot", "boot", "loot", "look", "book", "brook"}));
}
@Test
public void test7() {
assertEquals(true, WordChain.isWordChain(new String[]{"some", "tome", "tame", "lame", "flame", "flamer", "blamer", "blamers"}));
}
@Test
public void test8() {
assertEquals(false, WordChain.isWordChain(new String[]{"a", "at", "hat", "that", "what", "flat"}));
}
@Test
public void test9() {
assertEquals(false, WordChain.isWordChain(new String[]{"link", "blink", "wink", "sink"}));
}
}

View File

@@ -0,0 +1,69 @@
package translation_encryption;
public class EdabitEncription {
//Edabit Link
//https://edabit.com/challenge/jfCsugyp9BSLYEtwb
public EdabitEncription(){ }
public String encrypt(String clearText){
String editedString = new String();
editedString = clearText.replaceAll("\\s","");
int length = editedString.length();
double sqrtOfLength = Math.sqrt(length);
int columns = (int) sqrtOfLength;
int rows = columns + 1;
char[][] wordtable = new char[columns][rows];
fillWordtable(wordtable, editedString);
String word = new String();
String encrypted = new String();
for (int i = 0; i < wordtable[0].length; i++){
for (int j = 0; j < wordtable.length; j++){
word += wordtable[j][i];
}
encrypted += word + " ";
word = "";
}
return encrypted;
}
private void fillWordtable(char[][] wordtable, String text) {
int position = 0;
for (int i = 0; i < wordtable.length; i++){
for (int j = 0; j < wordtable[0].length; j++){
if (position < text.length()) {
wordtable[i][j] = text.charAt(position);
position++;
}
else {
break;
}
}
}
}
public String decrypt(String cryptedText){
String decrypted = new String();
decrypted = "LOL";
return decrypted;
}
public static void main(String[] args) {
EdabitEncription encryption = new EdabitEncription();
String clearText = "Info ist ein wenig langweilig";
String encrypted = encryption.encrypt(clearText);
System.out.println(encrypted);
String decrypted = encryption.decrypt(encrypted);
if (decrypted.equals(clearText)){
System.out.println("The Encryption was successful!");
} else {
System.out.println("You made a mistake.");
}
}
}

View File

@@ -0,0 +1,57 @@
package translation_encryption;
public class KaracasEncryption {
//Edabit-Challange
//https://edabit.com/challenge/SmL32HnRnmsCqGC5g
public KaracasEncryption(){
}
public String replaceVowles(String reversedText){
String tempText = new String();
for (int i = 0; i < reversedText.length(); i++){
char c = reversedText.charAt(i);
switch (c){
case 'a':
tempText += 0;
break;
case 'e':
tempText+= 1;
break;
case 'o':
tempText += 2;
break;
case 'u':
tempText += 3;
break;
default:
tempText += reversedText.charAt(i);
break;
}
}
tempText += "aca";
return tempText;
}
public String reverseString(String clearText){
String tempText = new String();
for (int i = clearText.length()-1; i >= 0; i--){
tempText += clearText.charAt(i);
}
return tempText;
}
public String encrypt(String clearText){
String reversed = reverseString(clearText);
String fullencrypted = replaceVowles(reversed);
return fullencrypted;
}
public static void main(String[] args) {
KaracasEncryption karacas = new KaracasEncryption();
karacas.encrypt("alpaca");
}
}

View File

@@ -0,0 +1,50 @@
package translation_encryption;
import java.util.Arrays;
public class PigLatinTranslation {
//Edabit-Challange
//https://edabit.com/challenge/2aajqTB69y7ZSSo9v
public static String pigLatin(String str) {
String[] words = str.split("\\s|(?=[!\\.?])");
String returnString = "";
for (int i = 0; i < words.length-1; i++) {
String s = "";
if ("AEIOUaeiou".indexOf(words[i].charAt(0)) == -1) {
if (i == 0) {
if (words[i].length() > 1) {
s = words[i].toUpperCase().charAt(1) + words[i].substring(2) + words[i].toLowerCase().charAt(0);
} else {
s = words[i].toUpperCase();
}
} else {
if (words[i].length() > 2) {
s = words[i].substring(1) + words[i].toLowerCase().charAt(0);
} else if (words[i].length() == 2) {
s = words[i].toLowerCase().charAt(1) + String.valueOf(words[i].toLowerCase().charAt(0));
} else {
s = words[i].toLowerCase();
}
}
s += "ay";
} else {
s += words[i] + "way";
}
if (i < words.length-2) {
returnString += s + " ";
} else{
returnString += s + words[i+1];
}
}
return returnString;
}
public static void main(String[] args) {
System.out.println(pigLatin("Tom got a small piece of pie."));
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,24 @@
package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
public class SwingPaintDemo1 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
System.out.println("Created GUI on EDT? " +
SwingUtilities.isEventDispatchThread());
JFrame f = new JFrame("Swing Paint Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(250, 250);
f.setVisible(true);
}
}

View File

@@ -0,0 +1,49 @@
package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
public class SwingPaintDemo2 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
System.out.println("Created GUI on EDT? "+
SwingUtilities.isEventDispatchThread());
JFrame f = new JFrame("Swing Paint Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new MyPanel1());
f.pack();
f.setVisible(true);
}
}
class MyPanel1 extends JPanel {
public MyPanel1() {
setBorder(BorderFactory.createLineBorder(Color.blue));
}
public Dimension getPreferredSize() {
return new Dimension(900,900);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Draw Text
g.drawString("This is my custom Panel!", getSize().width/2,getSize().height/2);
System.out.println("called");
}
}

View File

@@ -0,0 +1,85 @@
package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseMotionAdapter;
public class SwingPaintDemo3 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
System.out.println("Created GUI on EDT? "+
SwingUtilities.isEventDispatchThread());
JFrame f = new JFrame("Swing Paint Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new MyPanel2());
f.pack();
f.setVisible(true);
}
}
class MyPanel2 extends JPanel {
private int squareX = 50;
private int squareY = 50;
private int squareW = 20;
private int squareH = 20;
public MyPanel2() {
setBorder(BorderFactory.createLineBorder(Color.black));
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
moveSquare(e.getX(),e.getY());
}
});
addMouseMotionListener(new MouseAdapter() {
public void mouseDragged(MouseEvent e) {
moveSquare(e.getX(),e.getY());
}
});
}
private void moveSquare(int x, int y) {
int OFFSET = 1;
if ((squareX!=x) || (squareY!=y)) {
repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
squareX=x;
squareY=y;
repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET);
}
}
public Dimension getPreferredSize() {
return new Dimension(250,200);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("This is my custom Panel!",10,20);
g.setColor(Color.RED);
g.fillRect(squareX,squareY,squareW,squareH);
g.setColor(Color.BLACK);
g.drawRect(squareX,squareY,squareW,squareH);
}
}

View File

@@ -0,0 +1,136 @@
package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
public class SwingPaintDemo4 {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
System.out.println("Created GUI on EDT? "+
SwingUtilities.isEventDispatchThread());
JFrame f = new JFrame("Swing Paint Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new MyPanel3());
f.setSize(250,250);
f.setVisible(true);
}
}
class MyPanel3 extends JPanel {
RedSquare redSquare = new RedSquare();
RedSquare redSquare2 = new RedSquare();
public MyPanel3() {
setBorder(BorderFactory.createLineBorder(Color.black));
addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e){
moveSquare(e.getX(),e.getY());
}
});
addMouseMotionListener(new MouseAdapter(){
public void mouseDragged(MouseEvent e){
moveSquare(e.getX(),e.getY());
}
});
}
private void moveSquare(int x, int y){
// Current square state, stored as final variables
// to avoid repeat invocations of the same methods.
final int CURR_X = redSquare.getX();
final int CURR_Y = redSquare.getY();
final int CURR_W = redSquare.getWidth();
final int CURR_H = redSquare.getHeight();
final int OFFSET = 1;
if ((CURR_X!=x) || (CURR_Y!=y)) {
// The square is moving, repaint background
// over the old square location.
repaint(CURR_X,CURR_Y,CURR_W+OFFSET,CURR_H+OFFSET);
// Update coordinates.
redSquare.setX(x);
redSquare.setY(y);
// Repaint the square at the new location.
repaint(redSquare.getX(), redSquare.getY(),
redSquare.getWidth()+OFFSET,
redSquare.getHeight()+OFFSET);
}
}
public Dimension getPreferredSize() {
return new Dimension(250,200);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("This is my custom Panel!",10,20);
System.out.println(getSize());
redSquare.paintSquare(g);
redSquare2.paintSquare(g);
}
}
class RedSquare{
private int xPos = 50;
private int yPos = 50;
private int width = 20;
private int height = 20;
public void setX(int xPos){
this.xPos = xPos;
}
public int getX(){
return xPos;
}
public void setY(int yPos){
this.yPos = yPos;
}
public int getY(){
return yPos;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public void paintSquare(Graphics g){
g.setColor(Color.RED);
g.fillRect(xPos,yPos,width,height);
g.setColor(Color.BLACK);
g.drawRect(xPos,yPos,width,height);
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

11
ImageToText/src.iml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,69 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.*;
public class Keyboard {
public static void main(String args[]) throws InterruptedException {
KeyListener listener = new KeyListener() {
@Override
public void keyPressed(KeyEvent event) {
System.out.println(event.getKeyChar());
}
@Override
public void keyReleased(KeyEvent event) {
System.out.println(event.getKeyChar());
}
@Override
public void keyTyped(KeyEvent event) {
System.out.println(event.getKeyChar());
}
private void printEventInfo(String str, KeyEvent e) {
System.out.println(str);
int code = e.getKeyCode();
System.out.println(" Code: " + KeyEvent.getKeyText(code));
System.out.println(" Char: " + e.getKeyChar());
int mods = e.getModifiersEx();
System.out.println(" Mods: "
+ KeyEvent.getModifiersExText(mods));
System.out.println(" Location: "
+ keyboardLocation(e.getKeyLocation()));
System.out.println(" Action? " + e.isActionKey());
}
private String keyboardLocation(int keybrd) {
switch (keybrd) {
case KeyEvent.KEY_LOCATION_RIGHT:
return "Right";
case KeyEvent.KEY_LOCATION_LEFT:
return "Left";
case KeyEvent.KEY_LOCATION_NUMPAD:
return "NumPad";
case KeyEvent.KEY_LOCATION_STANDARD:
return "Standard";
case KeyEvent.KEY_LOCATION_UNKNOWN:
default:
return "Unknown";
}
}
};
JFrame jFrame = new JFrame();
jFrame.setSize(1000,1000);
jFrame.setVisible(true);
jFrame.addKeyListener(listener);
while(true){
Thread.sleep(1);
}
}
}

73
ImageToText/src/Test.java Normal file
View File

@@ -0,0 +1,73 @@
package src;
import org.w3c.dom.css.RGBColor;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Test extends Frame implements ActionListener {
private Label lblCount; // Declare a Label component
private TextField tfCount; // Declare a TextField component
private Button btnCount; // Declare a Button component
private int count = 0; // Counter's value
private Color c;
// Constructor to setup GUI components and event handlers
public Test () {
setLayout(new FlowLayout());
// "super" Frame, which is a Container, sets its layout to FlowLayout to arrange
// the components from left-to-right, and flow to next row from top-to-bottom.
lblCount = new Label("Counter"); // construct the Label component
add(lblCount); // "super" Frame container adds Label component
tfCount = new TextField(count + "", 5); // construct the TextField component with initial text
tfCount.setEditable(false); // set to read-only
add(tfCount); // "super" Frame container adds TextField component
btnCount = new Button("Count"); // construct the Button component
add(btnCount); // "super" Frame container adds Button component
btnCount.addActionListener(this);
// "btnCount" is the source object that fires an ActionEvent when clicked.
// The source add "this" instance as an ActionEvent listener, which provides
// an ActionEvent handler called actionPerformed().
// Clicking "btnCount" invokes actionPerformed().
setTitle("AWT Counter"); // "super" Frame sets its title
setSize(250, 100); // "super" Frame sets its initial window size
// For inspecting the Container/Components objects
// System.out.println(this);
// System.out.println(lblCount);
// System.out.println(tfCount);
// System.out.println(btnCount);
setVisible(true); // "super" Frame shows
c = new Color(150,100,25);
// System.out.println(this);
// System.out.println(lblCount);
// System.out.println(tfCount);
// System.out.println(btnCount);
}
// The entry main() method
public static void main(String[] args) {
// Invoke the constructor to setup the GUI, by allocating an instance
Test app = new Test();
// or simply "new AWTCounter();" for an anonymous instance
}
@Override
public void actionPerformed(ActionEvent e) {
++count; // Increase the counter value
// Display the counter value on the TextField tfCount
tfCount.setText(count + ""); // Convert int to String
System.out.println(c.getRGB());
c = c.brighter();
}
}

View File

@@ -0,0 +1,3 @@
public class Text{
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,99 @@
package src;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.awt.Canvas;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Image extends Canvas {
private JFrame frame;
private BufferedImage img;
private Color c;
private File f;
private ArrayList<File> files;
private static int n;
private KeyListener keys;
public Image() {
f = new File("/home/bitecoding/Bilder");
files = new ArrayList<File>(Arrays.asList(f.listFiles()));
c = null;
n = 0;
try {
img = ImageIO.read(files.get(0));
} catch (IOException ioException) {
ioException.printStackTrace();
}
keys = new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == ' '){
n++;
}
}
@Override
public void keyReleased(KeyEvent e) {
}
};
frame = new JFrame();
frame.setSize(img.getWidth(), img.getHeight());
frame.addKeyListener(keys);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
try {
img = ImageIO.read(files.get(n%2));
} catch (IOException ioException) {
ioException.printStackTrace();
}
for (int x = 0; x < img.getWidth(); x++) {
for (int y = 0; y < img.getHeight(); y++) {
c = new Color(img.getRGB(x, y), true);
g2d.setColor(c);
g2d.drawLine(x, y, x, y);
}
}
}
public static void main(String[] args) throws IOException, InterruptedException {
Image image = new Image();
image.frame.add(image);
int temp = 0;
while (true){
Thread.sleep(1);
if (temp != n){
image.repaint();
temp = n;
System.out.println(n);
}
}
}
}

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Marshal

153
LanguageAnalysis/src/Marshal.java Executable file
View File

@@ -0,0 +1,153 @@
package src;
import java.io.*;
import java.text.DecimalFormat;
import java.util.Arrays;
public class Marshal {
File file;
RandomAccessFile ramAccessFile;
DecimalFormat df;
int chars;
int[] absoluteValues;
double[][] relativeValues;
private char[][] charArray = { { '#', 'e' }, { '#', 'n' }, { '#', 'i' }, { '#', 's' }, { '#', 'r' }, { '#', 'a' },
{ '#', 't' }, { '#', 'd' }, { '#', 'h' }, { '#', 'u' }, { '#', 'l' }, { '#', 'c' }, { '#', 'g' },
{ '#', 'm' }, { '#', 'o' }, { '#', 'b' }, { '#', 'w' }, { '#', 'f' }, { '#', 'k' }, { '#', 'z' },
{ '#', 'p' }, { '#', 'v' }, { '#', 'ß' }, { '#', 'j' }, { '#', 'y' }, { '#', 'x' }, { '#', 'q' } };
public Marshal(String path) throws IOException {
file = new File(path);
ramAccessFile = new RandomAccessFile(file, "rw");
df = new DecimalFormat("#.00");
chars = 0;
absoluteValues = new int[27];
relativeValues = new double[2][27];
}
private void read() throws IOException {
String line = "";
while ((line = ramAccessFile.readLine()) != null) {
line = line.toLowerCase();
for (int i = 0; i < line.length(); i++) {
if ((line.charAt(i)+"").matches("[a-z]")){
try {
absoluteValues[line.charAt(i) - ('a')] += 1;
chars++;
}
catch (Exception e){
System.out.println(line.charAt(i));
}
} else if (line.charAt(i) == 'ß'){
try {
absoluteValues[21] += 1;
} catch (Exception e){
System.out.println(line.charAt(i));
}
}
}
}
ramAccessFile.seek(0);
}
private void relValues(int[] absoluteValues){
System.out.println(Arrays.toString(absoluteValues));
for (int i = 0; i < absoluteValues.length; i++){
relativeValues[0][i] = 'a'+i;
relativeValues[1][i] = Double.valueOf(df.format((absoluteValues[i]/(double)chars) * 100));
}
}
private void sortMax(double[][] relativeValues){
double[][] tempArray = relativeValues.clone();
System.out.println(Arrays.toString(tempArray[1]));
for (int j = 0; j < tempArray[1].length; j++) {
int index = -1;
double biggestValue = -1;
for (int i = 0; i < tempArray[1].length; i++) {
if (tempArray[1][i] > biggestValue) {
index = i;
biggestValue = tempArray[1][i];
}
}
charArray[j][0] = (char)tempArray[0][index];
tempArray[1][index] = 0;
}
}
private void decrypt() throws IOException {
String tempLine = "";
File resultFile = new File(System.getProperty("user.home")+System.getProperty("file.separator")+"results.txt");
if (resultFile.exists()){
resultFile.delete();
}
resultFile.createNewFile();
RandomAccessFile rnd = new RandomAccessFile(resultFile, "rw");
rnd.seek(0);
while ((tempLine = ramAccessFile.readLine()) != null) {
tempLine = tempLine.toLowerCase();
for (int i = 0; i < tempLine.length(); i++){
if ((tempLine.charAt(i)+"").matches("[a-z]")){
System.out.print(charArray[getIndexPosFromArray(tempLine.charAt(i),charArray)][1]);
rnd.write(charArray[getIndexPosFromArray(tempLine.charAt(i),charArray)][1]);
} else {
System.out.print(tempLine.charAt(i));
rnd.write(tempLine.charAt(i));
}
}
}
ramAccessFile.close();
rnd.close();
}
private int getIndexPosFromArray(char c, char[][] cArray){
for (int i = 0; i < cArray.length; i++){
if (cArray[i][0] == c){
return i;
}
}
return -1;
}
public void analyse(){
try {
read();
relValues(absoluteValues);
sortMax(relativeValues);
for (int i = 0; i < charArray.length; i++){
System.out.print(charArray[i][0] + " | ");
}
System.out.println();
for (int i = 0; i < charArray.length; i++){
System.out.print(charArray[i][1] + " | ");
}
System.out.println();
decrypt();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
if (args.length == 1) {
Marshal marshal = new Marshal(args[0]);
marshal.analyse();
} else if(args.length == 0){
System.err.println("File location is missing");
} else {
System.err.println("Only use this tool with one file at a time");
}
}
}

View File

@@ -0,0 +1,11 @@
package src;
import static java.lang.System.getProperty;
public class test {
public static void main(String[] args) {
System.out.println(getProperty("user.home"));
}
}

9
TOOLS/.classpath Normal file
View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="createBackground"/>
<classpathentry kind="src" path="fileReader"/>
<classpathentry kind="src" path="fileWriter"/>
<classpathentry kind="lib" path="C:/Program Files/Java/jdk1.8.0_65/jre/lib/ext/basisSwing130203UTF8.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
TOOLS/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bin/

17
TOOLS/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TOOLS</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

14
TOOLS/TOOLS.iml Normal file
View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/createBackground" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/fileReader" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/fileWriter" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/time" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,42 @@
package reader;
import java.io.*;
public class NumberReader {
private String path;
int i;
public NumberReader(String PATH) {
this.path = PATH;
}
public int read() {
File file = new File(path);
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
char[] chars = st.toCharArray();
st = "";
for (int i = 0; i < chars.length; i++) {
String j = "" + chars[i];
try {
st += Integer.parseInt(j);
} catch (Exception e) {
}
}
i = Integer.parseInt(st);
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
return i;
}
}

View File

@@ -0,0 +1,47 @@
package reader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class ReaderRakete {
private String path;
private int[] fluege;
private int entrys;
public ReaderRakete(String PATH) {
this.path = PATH;
fluege = new int [3];
}
public int read() {
File file = new File(path);
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
if(st != "") {
fluege[entrys] = Integer.parseInt(st);
System.out.println(fluege[entrys]);
entrys++;
}
}
}
catch (IOException e) {
e.printStackTrace();
}
return entrys;
}
public static void main(String[] args) throws Exception {
ReaderRakete r = new ReaderRakete("F:/JavaCode/RaketeGame/src/RaketeGame/res/highscores.txt");
r.read();
}
}

View File

@@ -0,0 +1,170 @@
package reader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class ReaderRotkaeppchen {
// OPTIONAL
private double wolfRot, wolfOma, jaegerWolf, rotOma;
private double gesamt, fehler, runden, male;
private String path;
private String[] strings;
public ReaderRotkaeppchen(String PATH) {
// OPTIONAL
wolfRot = 0;
wolfOma = 0;
jaegerWolf = 0;
rotOma = 0;
gesamt = 0;
runden = 0;
male = 0;
strings = new String[13];
this.path = PATH;
}
public void read() {
File file = new File(path);
BufferedReader br;
try {
br = new BufferedReader(new FileReader(file));
String st;
male++;
while ((st = br.readLine()) != null) {
// OPTIONAL
switch (st) {
case "Der Wolf hat das Rotkaeppchen gefressen!":
this.setWolfRot(this.getWolfRot()+1);
break;
case "Der Wolf hat die Oma gefressen!":
this.setWolfOma(this.getWolfOma()+1);
break;
case "Der Jaeger hat den Wolf erschossen!":
this.setJaegerWolf(this.getJaegerWolf()+1);
break;
case "Das Rotkaeppchen hat das Haus erreicht!":
this.setRotOma(this.getRotOma()+1);
break;
case " Runde beendet":
this.setRunden(this.getRunden()+1);
default:
this.setFehler(this.getFehler()+1);
break;
}
}
// OPTIONAL
this.setGesamt( this.getWolfOma() + this.getWolfRot() + this.getJaegerWolf() + this.getRotOma());
}
catch (IOException e) {
e.printStackTrace();
}
}
public int stringsLength() {
return strings.length;
}
public String[] results() {
strings[0] = "Gesamte Aktionen: " + Math.round(gesamt) + "\n";
strings[1] = "Der Wolf hat das Rotk<74>ppchen " + Math.round(wolfRot) + "-mal gefressen. ";
strings[2] = "(" + (Math.round((wolfRot / gesamt)*100)) + "%)\n";
strings[3] = "Der Wolf hat die Oma " + Math.round(wolfOma) + "-mal gefressen. ";
strings[4] = "(" + (Math.round((wolfOma / gesamt) * 100)) + "%)\n";
strings[5] = "Der J<>ger hat den Wolf " + Math.round(jaegerWolf) + "-mal erschossen. ";
strings[6] = "(" + Math.round((jaegerWolf / gesamt) * 100) + "%)\n";
strings[7] = "Das Rotk<74>ppchen hat das Haus der Oma " + Math.round(rotOma) + "-mal erreicht. ";
strings[8] = "(" + (Math.round((rotOma / gesamt) * 100)) + "%)\n";
strings[9] = "Not matched: " + Math.round(fehler) + " / Gesamt: " + Math.round(gesamt + fehler);
strings[10] = " (" + Math.round(fehler / (gesamt + fehler) * 100) + "%)\n";
strings[11] = "Runden: " + (Math.round(this.getRunden()) + "\n");
strings[12] = "Male durchgelaufen: " + male + "\n";
return strings;
}
public double getWolfRot() {
return wolfRot;
}
public void setWolfRot(double wolfRot) {
this.wolfRot = wolfRot;
}
public double getWolfOma() {
return wolfOma;
}
public void setWolfOma(double wolfOma) {
this.wolfOma = wolfOma;
}
public double getJaegerWolf() {
return jaegerWolf;
}
public void setJaegerWolf(double jaegerWolf) {
this.jaegerWolf = jaegerWolf;
}
public double getRotOma() {
return rotOma;
}
public void setRotOma(double rotOma) {
this.rotOma = rotOma;
}
public double getGesamt() {
return gesamt;
}
public void setGesamt(double gesamt) {
this.gesamt = gesamt;
}
public double getFehler() {
return fehler;
}
public void setFehler(double fehler) {
this.fehler = fehler;
}
public double getRunden() {
return runden;
}
public void setRunden(double runden) {
this.runden = runden;
}
public static void main(String[] args) throws Exception {
ReaderRotkaeppchen r = new ReaderRotkaeppchen("E:\\JavaCode\\Rotkeappchengame\\Rotkeappchengame\\statistics\\Run.txt");
r.read();
for(int i = 0; i < r.stringsLength(); i++)
System.out.print(r.results()[i]);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,58 @@
package writer;
import reader.ReaderRakete;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class Writer {
private String filePath;
public Writer(String PATH) {
this.filePath = PATH;
}
public void write(String newText, boolean append) {
File file = new File(filePath);
FileWriter fr = null;
try {
fr = new FileWriter(file, append);
fr.write(newText);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void clear() {
File file = new File(filePath);
FileWriter fr = null;
try {
// Below constructor argument decides whether to append or override
fr = new FileWriter(filePath, false);
fr.write("");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void delete() {
File file = new File(filePath);
file.delete();
}
}

View File

@@ -0,0 +1,41 @@
package util;
/**
* This is a tool to time
*
* @param starttime This Parameter captures the time at the beginning of a program
* @param endtime This Parameter captures the time at the end of a program
* @Author BiteCoding --> https://github.com/BiteCoding
*/
import java.util.Date;
public class Timer {
private long starttime;
private long endtime;
public Timer() {
starttime = 0;
endtime = 0;
}
public void start() {
starttime = new Date().getTime();
}
public void end() {
endtime = new Date().getTime();
}
private long deltaTime() {
if (starttime == 0 || endtime == 0) {
return -1;
} else {
return endtime-starttime;
}
}
public String timeNeeded(){
return "Time needed " + deltaTime() + " ms";
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,41 @@
import javax.swing.*;
public class Game {
public void place(int player, int position, int[] playfield){
if (playfield[position] == -1){
playfield[position] = player;
} else {
JOptionPane.showConfirmDialog(null,"Tile is already taken");
}
}
private boolean checkWin(int[] playfield){
for (int i = 0; i < 3; i++){
if ((playfield[i] == playfield[i+3]) && (playfield[i] == playfield[i+6])){
System.out.println("vertical");
return true;
} else if ((playfield[i*3] == playfield[i*3+1]) && (playfield[i*3] == playfield[i*3+2])){
System.out.println("horizontal");
return true;
}
}
return (playfield[2] == playfield[4]) && (playfield[2] == playfield[6]) || (playfield[0] == playfield[4]) && (playfield[0] == playfield[8]);
}
public static void main(String[] args) {
Game game = new Game();
Render render = new Render();
int[] playfield = {1,0,-1,1,1,0,-1,0,1};
SwingUtilities.invokeLater(new Runnable() {
public void run() {
render.createUI(playfield);
}
});
System.out.println(game.checkWin(playfield));
}
}

View File

@@ -0,0 +1,135 @@
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
public class Render {
public static void createUI(int[] playfield){
JFrame f = new JFrame("Swing Paint Demo");
MyPanel myPanel = new MyPanel(playfield);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(myPanel);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
class MyPanel extends JPanel {
Grid grid;
GameCharacters gameCharacters;
public MyPanel() {
setBorder(BorderFactory.createLineBorder(Color.BLACK));
grid = new Grid();
}
public MyPanel(int[] playfield){
setBorder(BorderFactory.createLineBorder(Color.BLACK));
grid = new Grid();
gameCharacters = new GameCharacters(playfield);
}
public Dimension getPreferredSize() {
return new Dimension(900,900);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
grid.paintGrid(g);
gameCharacters.paintGameCharacters(g);
}
}
class Grid{
private final int TILE_X = 300;
private final int TILE_Y = 300;
public void paintGrid(Graphics g){
g.setColor(Color.BLACK);
//horizontal
for (int i = 1; i < 3; i++) {
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(5));
g2d.drawLine(0, TILE_Y*i, TILE_X*3, TILE_Y*i);
}
//vertical
for (int i = 1; i < 3; i++){
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(5));
g2d.drawLine(TILE_X*i, 0, TILE_X*i, TILE_Y*3);
}
}
}
class GameCharacters {
CharacterX characterX = new CharacterX();
CharacterO characterO = new CharacterO();
private final int TILE_X = 300;
private final int TILE_Y = 300;
int[] playfield;
public GameCharacters(int[] playfield) {
this.playfield = playfield;
}
public void paintGameCharacters(Graphics g) {
int actions = 0;
for (int column = 0; column < 3; column++) {
for (int row = 0; row < 3; row++) {
if (playfield[actions] == 1) {
characterX.setX(TILE_X * row);
characterX.setY(TILE_Y * column);
characterX.paintX(g);
} else if (playfield[actions] == -1) {
characterO.setX(TILE_X * row);
characterO.setY(TILE_Y * column);
characterO.paintO(g);
}
actions++;
}
}
}
class CharacterX {
private int x;
private int y;
public void paintX(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(10));
g2d.drawLine(x+25, y+25, x+275, y+275);
g2d.drawLine(x+25, y +275, x+275, y+25);
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
}
class CharacterO {
private int x;
private int y;
public void paintO(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g2d.setStroke(new BasicStroke(10));
g2d.drawOval(x + 25, y + 25, 250, 250);
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Operator

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.BiteCoding.github.Simulation

Some files were not shown because too many files have changed in this diff Show More