Dan преди 7 години
ревизия
d91cf39c67

+ 57
- 0
.gitignore Целия файл

@@ -0,0 +1,57 @@
1
+er-specific stuff:
2
+.idea/**/workspace.xml
3
+.idea/**/tasks.xml
4
+.idea/dictionaries
5
+
6
+# Sensitive or high-churn files:
7
+.idea/**/dataSources/
8
+.idea/**/dataSources.ids
9
+.idea/**/dataSources.xml
10
+.idea/**/dataSources.local.xml
11
+.idea/**/sqlDataSources.xml
12
+.idea/**/dynamic.xml
13
+.idea/**/uiDesigner.xml
14
+
15
+# Gradle:
16
+.idea/**/gradle.xml
17
+.idea/**/libraries
18
+
19
+# CMake
20
+cmake-build-debug/
21
+
22
+# Mongo Explorer plugin:
23
+.idea/**/mongoSettings.xml
24
+
25
+## File-based project format:
26
+*.iws
27
+
28
+## Plugin-specific files:
29
+
30
+# IntelliJ
31
+/out/
32
+
33
+# mpeltonen/sbt-idea plugin
34
+.idea_modules/
35
+
36
+# JIRA plugin
37
+atlassian-ide-plugin.xml
38
+
39
+# Cursive Clojure plugin
40
+.idea/replstate.xml
41
+
42
+# Crashlytics plugin (for Android Studio and IntelliJ)
43
+com_crashlytics_export_strings.xml
44
+crashlytics.properties
45
+crashlytics-build.properties
46
+fabric.properties
47
+
48
+### Intellij Patch ###
49
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
50
+
51
+# *.iml
52
+# modules.xml
53
+# .idea/misc.xml
54
+# *.ipr
55
+
56
+# Sonarlint plugin
57
+.idea/sonarlint

+ 1
- 0
README.md Целия файл

@@ -0,0 +1 @@
1
+# Tech Connect Fundamentals Lab 1

+ 35
- 0
pom.xml Целия файл

@@ -0,0 +1,35 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>zipcoder.io</groupId>
8
+    <artifactId>ChapterOneMicro</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+
11
+    <dependencies>
12
+        <dependency>
13
+            <groupId>junit</groupId>
14
+            <artifactId>junit</artifactId>
15
+            <version>4.12</version>
16
+            <scope>test</scope>
17
+        </dependency>
18
+    </dependencies>
19
+
20
+    <build>
21
+        <plugins>
22
+            <plugin>
23
+                <groupId>org.apache.maven.plugins</groupId>
24
+                <artifactId>maven-compiler-plugin</artifactId>
25
+                <version>3.6.0</version>
26
+                <configuration>
27
+                    <source>1.8</source>
28
+                    <target>1.8</target>
29
+                </configuration>
30
+            </plugin>
31
+        </plugins>
32
+    </build>
33
+
34
+
35
+</project>

+ 13
- 0
src/main/java/HelloWorld/HelloWorld.java Целия файл

@@ -0,0 +1,13 @@
1
+package HelloWorld;
2
+
3
+/**
4
+ * Created by dan on 6/14/17.
5
+ */
6
+public class HelloWorld {
7
+
8
+    //Should return hello world as a string
9
+    public String helloWorld(){
10
+        return "Hello World";
11
+    }
12
+
13
+}

+ 71
- 0
src/main/java/Math/Math.java Целия файл

@@ -0,0 +1,71 @@
1
+package Math;
2
+
3
+/**
4
+ * Created by dan on 6/14/17.
5
+ */
6
+public class Math {
7
+
8
+    //Get the remainder from division
9
+    public int remainder(int one, int two){
10
+        return one % two;
11
+    }
12
+
13
+    //Return true using greater than symbol
14
+    public boolean greaterThanTrue(int one, int two){
15
+        return one > two;
16
+    }
17
+
18
+    //Return false using greater than symbol
19
+    public boolean greaterThanFalse(int one, int two){
20
+        return one > two;
21
+    }
22
+
23
+    //Return true using less than symbol
24
+    public boolean lessThanTrue(int one, int two){
25
+        return one < two;
26
+    }
27
+
28
+    //Return false using less than symbol
29
+    public boolean lessThanFalse(int one, int two){
30
+        return one < two;
31
+    }
32
+
33
+    //Return true using greater or equal symbol
34
+    public boolean greaterOrEqualTrue(int one, int two){
35
+        return one >= two;
36
+    }
37
+
38
+    //Return false using greater or equal symbol
39
+    public boolean greaterOrEqualFalse(int one, int two){
40
+        return one >= two;
41
+    }
42
+
43
+    //Return true using less than or equal symbol
44
+    public boolean lessOrEqualTrue(int one, int two){
45
+        return one <= two;
46
+    }
47
+
48
+    //Return false using less than or equal symbol
49
+    public boolean lessOrEqualFalse(int one, int two){
50
+        return one <= two;
51
+    }
52
+
53
+    //Return true if the number in parameter is equal to 3 and less than 90
54
+    public boolean logicalAnd(Integer number){
55
+        if (number == 3 && number < 90){
56
+            return true;
57
+        }
58
+        else
59
+            return false;
60
+    }
61
+
62
+    //Return true if the number passed in is equal to 4 or greater than 100
63
+    public boolean logicalOr(Integer number){
64
+        if (number == 4 || number > 100){
65
+            return true;
66
+        }
67
+        else
68
+            return false;
69
+    }
70
+
71
+}

+ 134
- 0
src/main/java/PrimativeTypes/PrimativeTypes.java Целия файл

@@ -0,0 +1,134 @@
1
+package PrimativeTypes;
2
+
3
+/**
4
+ * Created by dan on 6/14/17.
5
+ */
6
+public class PrimativeTypes {
7
+
8
+    //Add two ints and return the answer
9
+    public int add(int x, int y){
10
+        return x + y;
11
+    }
12
+
13
+    //Add two long's and return the answer
14
+    public long add(long x, long y){
15
+        return x + y;
16
+    }
17
+
18
+    //Add two short's and return the answer Must Type Cast
19
+    public short add(short x, short y){
20
+        return (short) (x + y);
21
+    }
22
+    //Add two bytes and return the answer, Must Type Cast
23
+    public byte add(byte x, byte y){
24
+        return (byte) (x + y);
25
+    }
26
+
27
+    //Add two floats and return the answer
28
+    public float add(float x, float y){
29
+        return x + y;
30
+    }
31
+
32
+    //Add two doubles and return the answer
33
+    public double add(double x, double y){
34
+        return x + y;
35
+    }
36
+
37
+    //Subtract two ints and return the answer
38
+    public int subtract(int x, int y){
39
+        return x - y;
40
+    }
41
+
42
+    //Subtract two long's and return the answer
43
+    public long subtract(long x, long y){
44
+        return x - y;
45
+    }
46
+
47
+    //Subtract two short's and return the answer Must Type Cast
48
+    public short subtract(short x, short y){
49
+        return (short) (x - y);
50
+    }
51
+    //Subtract two bytes and return the answer, Must Type Cast
52
+    public byte subtract(byte x, byte y){
53
+        return (byte) (x - y);
54
+    }
55
+
56
+    //Subtract two floats and return the answer
57
+    public float subtract(float x, float y){
58
+        return x - y;
59
+    }
60
+
61
+    //Subtract two doubles and return the answer
62
+    public double subtract(double x, double y){
63
+        return x - y;
64
+    }
65
+
66
+    //Divide two ints and return the answer
67
+    public int divide(int x, int y){
68
+        return x / y;
69
+    }
70
+
71
+    //Divide two long's and return the answer
72
+    public long divide(long x, long y){
73
+        return x / y;
74
+    }
75
+
76
+    //Divide two short's and return the answer Must Type Cast
77
+    public short divide(short x, short y){
78
+        return (short) (x / y);
79
+    }
80
+    //Divide two bytes and return the answer, Must Type Cast
81
+    public byte divide(byte x, byte y){
82
+        return (byte) (x / y);
83
+    }
84
+
85
+    //Divide two floats and return the answer
86
+    public float divide(float x, float y){
87
+        return x / y;
88
+    }
89
+
90
+    //Divide two doubles and return the answer
91
+    public double divide(double x, double y){
92
+        return x / y;
93
+    }
94
+
95
+    //Multiply two ints and return the answer
96
+    public int multiply(int x, int y){
97
+        return x * y;
98
+    }
99
+
100
+    //Multiply two long's and return the answer
101
+    public long multiply(long x, long y){
102
+        return x * y;
103
+    }
104
+
105
+    //Multiply two short's and return the answer Must Type Cast
106
+    public short multiply(short x, short y){
107
+        return (short) (x * y);
108
+    }
109
+    //Multiply two bytes and return the answer, Must Type Cast
110
+    public byte multiply(byte x, byte y){
111
+        return (byte) (x * y);
112
+    }
113
+
114
+    //Multiply two floats and return the answer
115
+    public float multiply(float x, float y){
116
+        return x * y;
117
+    }
118
+
119
+    //Multiply two doubles and return the answer
120
+    public double multiply(double x, double y){
121
+        return x * y;
122
+    }
123
+
124
+    //Return true
125
+    public boolean returnTrue(){
126
+        return true;
127
+    }
128
+
129
+    //Return false
130
+    public boolean returnFalse(){
131
+        return false;
132
+    }
133
+
134
+}

+ 80
- 0
src/main/java/Strings/Strings.java Целия файл

@@ -0,0 +1,80 @@
1
+package Strings;
2
+
3
+/**
4
+ * Created by dan on 6/14/17.
5
+ */
6
+public class Strings {
7
+
8
+    //Concatenate two strings together that are passed in the parameters
9
+    public String concatenation(String one, String two){
10
+        return one + two;
11
+    }
12
+
13
+    //Concatenate a string and a integer together that are passed in the parameters
14
+    public String concatenation(int one, String two){
15
+        return one + two;
16
+    }
17
+
18
+    //Get the substring of the first three letters of a string
19
+    public String subStringBegin(String input){
20
+        return input.substring(0,3);
21
+    }
22
+
23
+    //Get the substring of a string "Hello" so it returns the last three letters only
24
+    public String subStringEnd(String input){
25
+        return input.substring(input.length() - 3, input.length());
26
+    }
27
+
28
+    //Compare the two strings using compareTo() and if they are return true, else false
29
+    public boolean compareTwoStrings(String one, String two){
30
+        int comparison = one.compareTo(two);
31
+        if (comparison == 0){
32
+            return true;
33
+        }
34
+        else
35
+            return false;
36
+    }
37
+
38
+    //Compare the two strings using equals() and if they are return true, else false
39
+    public boolean compareTwoStringsEqual(String one, String two){
40
+        return one.equals(two);
41
+    }
42
+
43
+    //Write a method that returns the middle character in the given string hint: use the .length and .charAt methods
44
+    public char getTheMiddleChar(String string){
45
+        Integer middle = string.length()/2;
46
+        return string.charAt(middle);
47
+    }
48
+
49
+    //Use the indexOf method to find the first space in a string and .substring() to return the first word
50
+    public String getTheFirstWord(String string){
51
+        Integer space = 0;
52
+        for (int i = 0; i < string.length(); i++){
53
+            if (string.charAt(i) == ' '){
54
+                space = i;
55
+            }
56
+        }
57
+        return string.substring(0, space);
58
+    }
59
+
60
+    //Use the same behavior to find the second word
61
+    public String getTheSecondWord(String string){
62
+        Integer space = 0;
63
+        for (int i = 0; i < string.length(); i++){
64
+            if (string.charAt(i) == ' '){
65
+                space = i;
66
+            }
67
+        }
68
+        return string.substring(space + 1, string.length());
69
+    }
70
+
71
+    //Create a method that uses the above methods to return a string consisting of the second and first word in reversed order
72
+    public String reverseTheTwo(String string){
73
+        StringBuilder sb = new StringBuilder();
74
+        sb.append(getTheSecondWord(string));
75
+        sb.append(" ");
76
+        sb.append(getTheFirstWord(string));
77
+        return sb.toString();
78
+    }
79
+
80
+}

+ 25
- 0
src/test/java/HelloWorld/HelloWorldTest.java Целия файл

@@ -0,0 +1,25 @@
1
+package HelloWorld;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import static org.junit.Assert.*;
6
+/**
7
+ * Created by dan on 6/14/17.
8
+ */
9
+public class HelloWorldTest {
10
+
11
+    HelloWorld helloWorld;
12
+
13
+    @Before public void initialize(){
14
+        helloWorld = new HelloWorld();
15
+    }
16
+
17
+    @Test
18
+    public void TestHelloWorld(){
19
+        String expected = "Hello World";
20
+        String actual = this.helloWorld.helloWorld();
21
+
22
+        assertEquals(expected,actual);
23
+    }
24
+
25
+}

+ 67
- 0
src/test/java/Math/MathTest.java Целия файл

@@ -0,0 +1,67 @@
1
+package Math;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import static org.junit.Assert.*;
6
+/**
7
+ * Created by dan on 6/14/17.
8
+ */
9
+public class MathTest {
10
+
11
+
12
+    Math math;
13
+
14
+    @Before public void initialize(){
15
+        math = new Math();
16
+    }
17
+
18
+    @Test
19
+    public void testRemainder(){
20
+        Integer one = 7, two = 3;
21
+        Integer expected = 1;
22
+        Integer actual = this.math.remainder(one, two);
23
+
24
+        assertTrue(expected == actual);
25
+    }
26
+
27
+    @Test
28
+    public void testGreaterThan(){
29
+        assertTrue(this.math.greaterThanTrue(456,23));
30
+        assertFalse(this.math.greaterThanFalse(1,3));
31
+    }
32
+
33
+    @Test
34
+    public void testLessThan(){
35
+        assertTrue(this.math.lessThanTrue(1 ,3));
36
+        assertFalse(this.math.lessThanFalse(4,1));
37
+    }
38
+
39
+    @Test
40
+    public void testLessOrEqual(){
41
+        assertTrue(this.math.lessOrEqualTrue(3 , 3));
42
+        assertTrue(this.math.lessOrEqualTrue(3, 6));
43
+        assertFalse(this.math.lessOrEqualFalse(3, 1));
44
+    }
45
+
46
+    @Test
47
+    public void testGreaterOrEqual(){
48
+        assertTrue(this.math.greaterOrEqualTrue(4, 4));
49
+        assertTrue(this.math.greaterOrEqualTrue(78, 5));
50
+        assertFalse(this.math.greaterOrEqualFalse(4, 56));
51
+    }
52
+
53
+    @Test
54
+    public void testLogicalAnd(){
55
+        assertTrue(this.math.logicalAnd(3));
56
+        assertFalse(this.math.logicalAnd(4));
57
+    }
58
+
59
+    @Test
60
+    public void testLogicalOr(){
61
+        assertTrue(this.math.logicalOr(4));
62
+        assertTrue(this.math.logicalOr(14564));
63
+        assertFalse(this.math.logicalOr(54));
64
+    }
65
+
66
+
67
+}

+ 135
- 0
src/test/java/PrimativeTypes/PrimativeTypesTest.java Целия файл

@@ -0,0 +1,135 @@
1
+package PrimativeTypes;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import static org.junit.Assert.*;
6
+/**
7
+ * Created by dan on 6/14/17.
8
+ */
9
+public class PrimativeTypesTest {
10
+
11
+    PrimativeTypes primativeTypes;
12
+
13
+    @Before public void initialize(){
14
+        primativeTypes = new PrimativeTypes();
15
+    }
16
+
17
+    @Test
18
+    public void testAdditions(){
19
+        int expectedInt = 27;
20
+        int actualInt = this.primativeTypes.add(20,7);
21
+
22
+        long expectedLong = 456874531;
23
+        long actualLong = this.primativeTypes.add(228437266, 228437265);
24
+
25
+        short expectedShort = 32767;
26
+        short actualShort = (short) this.primativeTypes.add(16384, 16383);
27
+
28
+        byte expectedByte = 127;
29
+        byte actualByte = (byte) this.primativeTypes.add(63, 64);
30
+
31
+        float expectedFloat = (float) 1545.585;
32
+        float actualFloat = (float) this.primativeTypes.add(750.585,795.000);
33
+
34
+        double expectedDouble = 456.25;
35
+        double actualDouble = this.primativeTypes.add(225.25,231);
36
+
37
+        assertEquals(expectedInt,actualInt);
38
+        assertEquals(expectedLong,actualLong);
39
+        assertEquals(expectedShort,actualShort);
40
+        assertEquals(expectedByte,actualByte);
41
+        assertEquals(expectedFloat,actualFloat, 0);
42
+        assertEquals(expectedDouble,actualDouble, 0);
43
+    }
44
+
45
+    @Test
46
+    public void testSubtractions(){
47
+        int expectedInt = 13;
48
+        int actualInt = this.primativeTypes.subtract(20,7);
49
+
50
+        long expectedLong = 1;
51
+        long actualLong = this.primativeTypes.subtract(228437266, 228437265);
52
+
53
+        short expectedShort = 1;
54
+        short actualShort = (short) this.primativeTypes.subtract(16384, 16383);
55
+
56
+        byte expectedByte = -1;
57
+        byte actualByte = (byte) this.primativeTypes.subtract(63, 64);
58
+
59
+        float expectedFloat = (float) -44.415;
60
+        float actualFloat = (float) this.primativeTypes.subtract(750.585,795.000);
61
+
62
+        double expectedDouble = -5.75;
63
+        double actualDouble = this.primativeTypes.subtract(225.25,231);
64
+
65
+        assertEquals(expectedInt,actualInt);
66
+        assertEquals(expectedLong,actualLong);
67
+        assertEquals(expectedShort,actualShort);
68
+        assertEquals(expectedByte,actualByte);
69
+        assertEquals(expectedFloat,actualFloat, 0);
70
+        assertEquals(expectedDouble,actualDouble, 0);
71
+    }
72
+
73
+    @Test
74
+    public void testDivision(){
75
+        int expectedInt = 10;
76
+        int actualInt = this.primativeTypes.divide(20,2);
77
+
78
+        long expectedLong = 20000;
79
+        long actualLong = this.primativeTypes.divide(20000000, 1000);
80
+
81
+        short expectedShort = 2;
82
+        short actualShort = (short) this.primativeTypes.divide(2, 1);
83
+
84
+        byte expectedByte = 2;
85
+        byte actualByte = (byte) this.primativeTypes.divide(64, 32);
86
+
87
+        float expectedFloat = (float) 2.50;
88
+        float actualFloat = (float) this.primativeTypes.divide(7.5,3);
89
+
90
+        double expectedDouble = 1.25;
91
+        double actualDouble = this.primativeTypes.divide(5.0,4.0);
92
+
93
+        assertEquals(expectedInt,actualInt);
94
+        assertEquals(expectedLong,actualLong);
95
+        assertEquals(expectedShort,actualShort);
96
+        assertEquals(expectedByte,actualByte);
97
+        assertEquals(expectedFloat,actualFloat, 0);
98
+        assertEquals(expectedDouble,actualDouble, 0);
99
+    }
100
+
101
+    @Test
102
+    public void testMultiplication(){
103
+        int expectedInt = 10;
104
+        int actualInt = this.primativeTypes.multiply(5,2);
105
+
106
+        long expectedLong = 20000;
107
+        long actualLong = this.primativeTypes.multiply(20, 1000);
108
+
109
+        short expectedShort = 2;
110
+        short actualShort = (short) this.primativeTypes.multiply(2, 1);
111
+
112
+        byte expectedByte = 64;
113
+        byte actualByte = (byte) this.primativeTypes.multiply(16, 4);
114
+
115
+        float expectedFloat = (float) 2.50;
116
+        float actualFloat = (float) this.primativeTypes.multiply(2.50,1);
117
+
118
+        double expectedDouble = 9.75;
119
+        double actualDouble = this.primativeTypes.multiply(3.25,3.0);
120
+
121
+        assertEquals(expectedInt,actualInt);
122
+        assertEquals(expectedLong,actualLong);
123
+        assertEquals(expectedShort,actualShort);
124
+        assertEquals(expectedByte,actualByte);
125
+        assertEquals(expectedFloat,actualFloat, 0);
126
+        assertEquals(expectedDouble,actualDouble, 0);
127
+    }
128
+
129
+    @Test
130
+    public void testBoolean(){
131
+        assertTrue(this.primativeTypes.returnTrue());
132
+        assertFalse(this.primativeTypes.returnFalse());
133
+    }
134
+
135
+}

+ 81
- 0
src/test/java/Strings/StringsTest.java Целия файл

@@ -0,0 +1,81 @@
1
+package Strings;
2
+
3
+import org.junit.Before;
4
+import org.junit.Test;
5
+import static org.junit.Assert.*;
6
+
7
+/**
8
+ * Created by dan on 6/14/17.
9
+ */
10
+public class StringsTest {
11
+
12
+    Strings strings;
13
+
14
+    @Before public void initialize(){
15
+        strings = new Strings();
16
+    }
17
+
18
+    @Test
19
+    public void concatenationStringTest(){
20
+        String one = "Hello", two = " Java";
21
+        assertTrue(this.strings.concatenation(one,two).equals("Hello Java"));
22
+    }
23
+
24
+    @Test
25
+    public void concatenationStringAndIntegerTest(){
26
+        int one = 21;
27
+        String two = " Years Old";
28
+        assertTrue(this.strings.concatenation(one, two).equals("21 Years Old"));
29
+    }
30
+
31
+    @Test
32
+    public void substringBeginTest(){
33
+        String string = "Hello";
34
+        assertTrue(this.strings.subStringBegin(string).equals("Hel"));
35
+    }
36
+
37
+    @Test
38
+    public void substringEndTest(){
39
+        String string = "Hello";
40
+        assertTrue(this.strings.subStringEnd(string).equals("llo"));
41
+    }
42
+
43
+    @Test
44
+    public void compareToTest(){
45
+        String one = "Zipcode", two = "Zipcode", three ="Wilmington";
46
+        assertTrue(this.strings.compareTwoStrings(one,two));
47
+        assertFalse(this.strings.compareTwoStrings(one,three));
48
+    }
49
+
50
+    @Test
51
+    public void equalToTest(){
52
+        String one = "Zipcode", two = "Zipcode", three = "Wilmington";
53
+        assertTrue(this.strings.compareTwoStringsEqual(one, two));
54
+        assertFalse(this.strings.compareTwoStringsEqual(three, two));
55
+    }
56
+
57
+    @Test
58
+    public void getTheMiddleChar(){
59
+        String one = "Zipcode";
60
+        assertTrue('c' == this.strings.getTheMiddleChar(one));
61
+    }
62
+
63
+    @Test
64
+    public void getTheFirstWord(){
65
+        String string = "Zipcode Wilmington";
66
+        assertTrue(this.strings.getTheFirstWord(string).equals("Zipcode"));
67
+    }
68
+
69
+    @Test
70
+    public void getTheSecondWord(){
71
+        String string = "Zipcode Wilmington";
72
+        assertTrue(this.strings.getTheSecondWord(string).equals("Wilmington"));
73
+    }
74
+
75
+    @Test
76
+    public void reverseThem(){
77
+        String string = "Zipcode Wilmington";
78
+        assertTrue(this.strings.reverseTheTwo(string).equals("Wilmington Zipcode"));
79
+    }
80
+
81
+}

BIN
target/classes/HelloWorld/HelloWorld.class Целия файл


BIN
target/classes/Math/Math.class Целия файл


BIN
target/classes/PrimativeTypes/PrimativeTypes.class Целия файл


BIN
target/classes/Strings/Strings.class Целия файл


BIN
target/classes/Variables/Variables.class Целия файл


BIN
target/test-classes/HelloWorld/HelloWorldTest.class Целия файл


BIN
target/test-classes/Math/MathTest.class Целия файл


BIN
target/test-classes/PrimativeTypes/PrimativeTypesTest.class Целия файл


BIN
target/test-classes/Strings/StringsTest.class Целия файл


BIN
target/test-classes/Variables/VariablesTest.class Целия файл