aboutsummaryrefslogtreecommitdiff
path: root/Java
diff options
context:
space:
mode:
authorSyndamia <kami02882@gmail.com>2019-07-29 11:46:36 +0300
committerSyndamia <kami02882@gmail.com>2019-07-29 11:46:36 +0300
commitbc09da5a7b65b08b5d5dcd1e90173ad3b6081c23 (patch)
treec66cebc02aac30ff859c06ca462f3dd58b6809b0 /Java
parent65edf7296baf48aad1b4e0c09b57f1a7f48791a8 (diff)
downloadSelf-learning-bc09da5a7b65b08b5d5dcd1e90173ad3b6081c23.tar
Self-learning-bc09da5a7b65b08b5d5dcd1e90173ad3b6081c23.tar.gz
Self-learning-bc09da5a7b65b08b5d5dcd1e90173ad3b6081c23.zip
Did some more work in Python and started officially learning Java
Diffstat (limited to 'Java')
-rw-r--r--Java/Beginer training/.idea/.gitignore2
-rw-r--r--Java/Beginer training/.idea/.name1
-rw-r--r--Java/Beginer training/.idea/misc.xml6
-rw-r--r--Java/Beginer training/.idea/modules.xml8
-rw-r--r--Java/Beginer training/.idea/uiDesigner.xml124
-rw-r--r--Java/Beginer training/.idea/vcs.xml6
-rw-r--r--Java/Beginer training/Beginer training.iml11
-rw-r--r--Java/Beginer training/out/production/Beginer training/Game_test.classbin0 -> 2422 bytes
-rw-r--r--Java/Beginer training/out/production/Beginer training/META-INF/Beginer training.kotlin_modulebin0 -> 16 bytes
-rw-r--r--Java/Beginer training/out/production/Beginer training/Player.classbin0 -> 396 bytes
-rw-r--r--Java/Beginer training/out/production/Beginer training/Training.classbin0 -> 893 bytes
-rw-r--r--Java/Beginer training/out/production/Beginer training/VampireNumber explanation.txt39
-rw-r--r--Java/Beginer training/out/production/Beginer training/VampireNumber.classbin0 -> 1968 bytes
-rw-r--r--Java/Beginer training/src/Game_test.java72
-rw-r--r--Java/Beginer training/src/Training.java18
-rw-r--r--Java/Beginer training/src/VampireNumber explanation.txt39
-rw-r--r--Java/Beginer training/src/VampireNumber.java45
17 files changed, 371 insertions, 0 deletions
diff --git a/Java/Beginer training/.idea/.gitignore b/Java/Beginer training/.idea/.gitignore
new file mode 100644
index 0000000..5c98b42
--- /dev/null
+++ b/Java/Beginer training/.idea/.gitignore
@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml \ No newline at end of file
diff --git a/Java/Beginer training/.idea/.name b/Java/Beginer training/.idea/.name
new file mode 100644
index 0000000..eb51918
--- /dev/null
+++ b/Java/Beginer training/.idea/.name
@@ -0,0 +1 @@
+Beginner training \ No newline at end of file
diff --git a/Java/Beginer training/.idea/misc.xml b/Java/Beginer training/.idea/misc.xml
new file mode 100644
index 0000000..e0844bc
--- /dev/null
+++ b/Java/Beginer training/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+</project> \ No newline at end of file
diff --git a/Java/Beginer training/.idea/modules.xml b/Java/Beginer training/.idea/modules.xml
new file mode 100644
index 0000000..70966ea
--- /dev/null
+++ b/Java/Beginer training/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/Beginer training.iml" filepath="$PROJECT_DIR$/Beginer training.iml" />
+ </modules>
+ </component>
+</project> \ No newline at end of file
diff --git a/Java/Beginer training/.idea/uiDesigner.xml b/Java/Beginer training/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/Java/Beginer training/.idea/uiDesigner.xml
@@ -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> \ No newline at end of file
diff --git a/Java/Beginer training/.idea/vcs.xml b/Java/Beginer training/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Java/Beginer training/.idea/vcs.xml
@@ -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> \ No newline at end of file
diff --git a/Java/Beginer training/Beginer training.iml b/Java/Beginer training/Beginer training.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/Java/Beginer training/Beginer training.iml
@@ -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> \ No newline at end of file
diff --git a/Java/Beginer training/out/production/Beginer training/Game_test.class b/Java/Beginer training/out/production/Beginer training/Game_test.class
new file mode 100644
index 0000000..38331d5
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/Game_test.class
Binary files differ
diff --git a/Java/Beginer training/out/production/Beginer training/META-INF/Beginer training.kotlin_module b/Java/Beginer training/out/production/Beginer training/META-INF/Beginer training.kotlin_module
new file mode 100644
index 0000000..2983af7
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/META-INF/Beginer training.kotlin_module
Binary files differ
diff --git a/Java/Beginer training/out/production/Beginer training/Player.class b/Java/Beginer training/out/production/Beginer training/Player.class
new file mode 100644
index 0000000..398e5e5
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/Player.class
Binary files differ
diff --git a/Java/Beginer training/out/production/Beginer training/Training.class b/Java/Beginer training/out/production/Beginer training/Training.class
new file mode 100644
index 0000000..659ebce
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/Training.class
Binary files differ
diff --git a/Java/Beginer training/out/production/Beginer training/VampireNumber explanation.txt b/Java/Beginer training/out/production/Beginer training/VampireNumber explanation.txt
new file mode 100644
index 0000000..10ac553
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/VampireNumber explanation.txt
@@ -0,0 +1,39 @@
+VampireNumber Java task, code explanation with the number 1827:
+
+1827 (Number that we are checking)
+0123 (Indexes of digits, in code they are named: first, second, third & fourth)
+
+The first and second number that are multiplied are illustrated combined as one (the first half of the calculated numbers is the first multiple, and the second half - the second)
+For example, the number 1278 is actually 12 and 78 and they are multiplied to check for the result
+This is done like that to better illustrate how the numbers change
+
+Cycle: Swap 1 with 3 (indexes):
+1827 1728
+1782 1287
+1278 1872
+
+2178 2871
+2817 2718
+2781 2187 NOTE: 2187 is the answer, so the code would stop here, but this example is continued to the end
+
+7281 7182
+7128 7821
+7812 7218
+
+8712 8217
+8271 8172
+8127 8721
+
+1827 (Here the cycles end)
+
+Cycle: it rotates the last 3 digits, for example if we have 123,the 3 gets in the front and the others move back, i.e. 312
+
+ 1 2 3 => 3 1 2
+ ^-----'
+
+Swap 1 with 3: as the name suggests, it makes a second version of the number by swapping the 1st (index) and 2nd (index) digit
+
+ 0 1 2 3 => 0 3 2 1
+ ^---^
+
+ -the swap is there because with the cycle we miss out on half of the possible numbers \ No newline at end of file
diff --git a/Java/Beginer training/out/production/Beginer training/VampireNumber.class b/Java/Beginer training/out/production/Beginer training/VampireNumber.class
new file mode 100644
index 0000000..ef49838
--- /dev/null
+++ b/Java/Beginer training/out/production/Beginer training/VampireNumber.class
Binary files differ
diff --git a/Java/Beginer training/src/Game_test.java b/Java/Beginer training/src/Game_test.java
new file mode 100644
index 0000000..e0400dd
--- /dev/null
+++ b/Java/Beginer training/src/Game_test.java
@@ -0,0 +1,72 @@
+import java.util.Arrays;
+import java.io.*;
+import java.text.*;
+
+public class Game_test {
+ public static final char[][] ORIGINAL_MAP = {
+ {' ', '-', '-', '-', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '[', ' ', '|', ' '},
+ {' ', '-', '<', '-', ' '}
+ };
+
+ public static void main(String args[]) {
+ Console cons = System.console();
+
+ while (true){
+ ReWriteMap();
+ System.out.println("Type direction and press enter:");
+ String direction = cons.readLine();
+
+ switch (direction.charAt(0)) {
+ case 'w': Player.yPos++; break;
+ case 's': Player.yPos--; break;
+ case 'a': Player.xPos--; break;
+ case 'd': Player.xPos++; break;
+ }
+
+ try { Thread.sleep(1000); }
+ catch (Exception ex) { }
+ }
+ }
+
+ public static void ReWriteMap(){
+ var map = Arrays.copyOf(ORIGINAL_MAP, ORIGINAL_MAP.length);
+
+ for (int i = 0; i < map.length; i++){
+ for (int j = 0; j < map[0].length; j++){
+ if (i == Player.yPos && j == Player.xPos) map[i][j] = Player.body;
+
+ System.out.print(map[i][j]);
+ }
+ System.out.println();
+ }
+ }
+}
+
+class Player {
+ public static char body = '*';
+
+ public static int yPos = 0, xPos = 1; //y is up/down ; x is left/right
+}
diff --git a/Java/Beginer training/src/Training.java b/Java/Beginer training/src/Training.java
new file mode 100644
index 0000000..95886d0
--- /dev/null
+++ b/Java/Beginer training/src/Training.java
@@ -0,0 +1,18 @@
+import java.io.*;
+
+public class Training {
+ public static void main(String args[]){
+ PrintFibonacci(7);
+ }
+
+ public static void PrintFibonacci (int length) {
+ int a = 1, b = 0;
+ for (int i = 0; i < length; i++){
+ System.out.printf("%d ", a);
+
+ int temp = a;
+ a += b;
+ b = temp;
+ }
+ }
+}
diff --git a/Java/Beginer training/src/VampireNumber explanation.txt b/Java/Beginer training/src/VampireNumber explanation.txt
new file mode 100644
index 0000000..10ac553
--- /dev/null
+++ b/Java/Beginer training/src/VampireNumber explanation.txt
@@ -0,0 +1,39 @@
+VampireNumber Java task, code explanation with the number 1827:
+
+1827 (Number that we are checking)
+0123 (Indexes of digits, in code they are named: first, second, third & fourth)
+
+The first and second number that are multiplied are illustrated combined as one (the first half of the calculated numbers is the first multiple, and the second half - the second)
+For example, the number 1278 is actually 12 and 78 and they are multiplied to check for the result
+This is done like that to better illustrate how the numbers change
+
+Cycle: Swap 1 with 3 (indexes):
+1827 1728
+1782 1287
+1278 1872
+
+2178 2871
+2817 2718
+2781 2187 NOTE: 2187 is the answer, so the code would stop here, but this example is continued to the end
+
+7281 7182
+7128 7821
+7812 7218
+
+8712 8217
+8271 8172
+8127 8721
+
+1827 (Here the cycles end)
+
+Cycle: it rotates the last 3 digits, for example if we have 123,the 3 gets in the front and the others move back, i.e. 312
+
+ 1 2 3 => 3 1 2
+ ^-----'
+
+Swap 1 with 3: as the name suggests, it makes a second version of the number by swapping the 1st (index) and 2nd (index) digit
+
+ 0 1 2 3 => 0 3 2 1
+ ^---^
+
+ -the swap is there because with the cycle we miss out on half of the possible numbers \ No newline at end of file
diff --git a/Java/Beginer training/src/VampireNumber.java b/Java/Beginer training/src/VampireNumber.java
new file mode 100644
index 0000000..63d7085
--- /dev/null
+++ b/Java/Beginer training/src/VampireNumber.java
@@ -0,0 +1,45 @@
+public class VampireNumber {
+ public static void main(String args[]){
+ //NOTE: Works ONLY with 4 digit numbers, for bigger use BigVampireNumber
+ System.out.println(FindVampireNumber(6880));
+ }
+
+ public static String FindVampireNumber(int result){
+ String num = result + "";
+ int first = num.charAt(0) - 48, second = num.charAt(1) - 48, third = num.charAt(2) - 48, fourth = num.charAt(3) - 48;
+
+ for (int i = 0; i < 4; i++){
+ for (int j = 0; j < 3; j++){
+ int first_half = Combine(first, second), second_half = Combine(third, fourth);
+ int swapped_first_half = Combine(first, fourth), swapped_second_half = Combine(third, second);
+
+ if (first_half * second_half == result) {
+ return result + " = " + first_half + " * " + second_half;
+ }
+ else if (swapped_first_half *swapped_second_half == result){
+ return result + " = " + swapped_first_half + " * " + swapped_second_half;
+ }
+
+ switch (j) {
+ case 0:
+ case 1:
+ int temp = fourth;
+ fourth = second; second = temp;
+ temp = third;
+ third = fourth; fourth = temp;
+
+ break;
+ case 2:
+ temp = second;
+ second = first; first = temp;
+ break;
+ }
+ }
+ }
+ return result + " isn't a vampire number";
+ }
+
+ private static int Combine(int first, int second) {
+ return (first * 10) + second;
+ }
+}