Pārlūkot izejas kodu

Would of def gotten these done if I had more time I'm just slow

Whitney Martinez 6 gadus atpakaļ
vecāks
revīzija
0a6107caee
3 mainītis faili ar 81 papildinājumiem un 15 dzēšanām
  1. 45
    5
      LoopFun.java
  2. 15
    7
      MathUtilities.java
  3. 21
    3
      StringUtilities.java

+ 45
- 5
LoopFun.java Parādīt failu

@@ -8,7 +8,13 @@ public class LoopFun
8 8
        * @return the factorial of the number
9 9
        */
10 10
       public int factorial(int number){
11
-          return -1;
11
+          int total = 0;
12
+          for(int i = 1; i < number; i++ ){
13
+              
14
+            total = i * number; 
15
+        
16
+            }
17
+            return total;
12 18
       }
13 19
 
14 20
       /**
@@ -19,8 +25,38 @@ public class LoopFun
19 25
        * @return Upper case string of the first letter of each word
20 26
        */
21 27
       public String acronym(String phrase) {
22
-          return null;
23
-      }
28
+         /* String x1="";
29
+          String [] container = phrase.split(" ");
30
+          for(int i= 0; i < container.length ; i++)
31
+            {   
32
+                
33
+                x1 = container.charAt(0,1);
34
+                
35
+                
36
+            }
37
+          String letters = x1;
38
+          return letters.toUpperCase();*/
39
+          
40
+         //String result = phrase.replaceAll("\\B |\\P{L}","").toUpperCase();
41
+         //return result;
42
+          
43
+          String [] container = phrase.split(" ");
44
+          
45
+          String a_c = "";
46
+          for(int i= 0; i < container.length ; i++)
47
+            {   
48
+                
49
+                 a_c +=Character.toString(container[i].charAt(0));
50
+                
51
+                
52
+            }
53
+          
54
+          
55
+         
56
+         return a_c;
57
+         
58
+        }
59
+      
24 60
 
25 61
       /**
26 62
        * To prevent anyone from reading our messages, we can encrypt it so it will only be readable by its
@@ -35,6 +71,10 @@ public class LoopFun
35 71
        * @return the encrypted string by shifting each character by three character
36 72
        */
37 73
       public String encrypt(String word) {
38
-          return null;
39
-      }
74
+          
75
+        //  char alph = (((alph - 'a' + 3) % 26) + 'a');
76
+        
77
+          
78
+        return null;
79
+        }
40 80
 }

+ 15
- 7
MathUtilities.java Parādīt failu

@@ -6,7 +6,7 @@ public class MathUtilities{
6 6
    * @return the sum of the two numbers
7 7
    */
8 8
   public int add(int num1, int num2){
9
-      return -1;
9
+      return num1 + num2;
10 10
   }
11 11
 
12 12
   /**
@@ -16,7 +16,7 @@ public class MathUtilities{
16 16
    * @return the sum of the two numbers
17 17
    */
18 18
   public double add(double num1, double num2){
19
-      return -1;
19
+      return num1 + num2;
20 20
   }
21 21
 
22 22
   /**
@@ -25,7 +25,7 @@ public class MathUtilities{
25 25
    * @return the half of the number in double
26 26
    */
27 27
   public double half(int number) {
28
-      return -1;
28
+      return number / 2;
29 29
   }
30 30
 
31 31
   /**
@@ -34,9 +34,16 @@ public class MathUtilities{
34 34
    * @return true if the number is odd, false if it is even
35 35
    */
36 36
   public boolean isOdd(int number){
37
-      return false;
38
-  }
39
-
37
+            
38
+      boolean odd = true;
39
+      if(number % 2 == 0){
40
+                odd = false;
41
+                
42
+            }else if(number % 2 != 0){
43
+                odd = true;
44
+            }
45
+      return odd;
46
+    }
40 47
 
41 48
   /**
42 49
    * Multiply the number by itself
@@ -44,7 +51,8 @@ public class MathUtilities{
44 51
    * @return the result of the number multiply by itself
45 52
    */
46 53
   public int square(int number) {
47
-      return -1;
54
+      //return (int)Math.sqrt(number);
55
+      return number * number;
48 56
   }
49 57
 
50 58
 }

+ 21
- 3
StringUtilities.java Parādīt failu

@@ -1,13 +1,31 @@
1 1
 public class StringUtilities {
2 2
    public Character getMiddleCharacter(String word){
3
-       return null;
3
+       int middle = word.length();
4
+       int x;
5
+       char m = 0; 
6
+       
7
+       if(middle % 2 == 0){
8
+            x = middle / 2 - 1;
9
+            m = word.charAt(x);
10
+        }else if (middle % 2 != 0){
11
+            x = middle / 2;
12
+            m = word.charAt(x);
13
+        }
14
+        return m;
4 15
    }
5 16
    
6 17
    public String removeCharacter(String value, char charToRemove){
7
-     return null;  
18
+       // String newestword = value.replaceAll(charToRemove,"");
19
+        //return newestword;
20
+        return null;
21
+        
8 22
    }
9 23
    
10 24
    public String getLastWord(String value) {
11
-       return null;
25
+       
26
+       String [] container = value.split(" "); 
27
+       String x =  container[container.length -1];
28
+       return x; 
29
+       
12 30
    }
13 31
 }