diff --git a/.gitignore b/.gitignore index 4e107a0..024a744 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ /Assignments/lab15_CalebFontenot/build/ /Assignments/lab15_CalebFontenot/dist/ /Assignments/Experiments/mavenproject1/target/ +/Assignments/lab16_arrays2_CalebFontenot/target/ diff --git a/Assignments/MP4_CalebFontenot/MP4_CalebFontenot.html. b/Assignments/MP4_CalebFontenot/MP4_CalebFontenot.html. new file mode 100644 index 0000000..9010098 --- /dev/null +++ b/Assignments/MP4_CalebFontenot/MP4_CalebFontenot.html. @@ -0,0 +1,197 @@ + + + +MP4_CalebFontenot.java + + + + +
/home/caleb/ASDV-Java/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package mp4_calebfontenot;
+
+import java.util.Scanner;
+
+/**
+ *
+ * @author caleb
+ */
+public class MP4_CalebFontenot {
+
+    static boolean debug = true;
+
+    /**
+     * If the result from Step 4 is divisible by 10, the card number is valid; otherwise, it is invalid. For example, the number 4388576018402626 is invalid, but the number 4388576018410707 is valid
+     *
+     * @param CreditCard
+     * @return
+     */
+    public static boolean isValid(String CreditCard) {
+        int sumResult = MP4_CalebFontenot.sum(MP4_CalebFontenot.doubleDigitsAndSumSingleDigits(CreditCard), MP4_CalebFontenot.addOddNumbersFromRightToLeft(CreditCard));
+        int divisionResult = sumResult % 10;
+        if (debug) {
+            System.out.println(sumResult + ", " + divisionResult);
+        }
+        if (divisionResult == 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Sum the results from Steps 1, 2 and Step 3. 37 + 38 = 75
+     *
+     * @param step1andSep2 result form step 1 and step 2
+     * @param step3 result form step 3
+     * @return
+     */
+    public static int sum(int step1andStep2, int step3) {
+        return step1andStep2 + step3;
+    }
+
+    /**
+     * Add all digits in the odd places from right to left in the card number. 6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
+     *
+     * @param -creditCard the credit card number to be processed.
+     * @return the sum of digits at odd position from right to left.
+     */
+    public static int addOddNumbersFromRightToLeft(String creditCard) {
+        if (debug) {
+            System.out.println("Now executing addOddNumbersFromRightToLeft()");
+        }
+        // Iterate through string
+        int creditCardLength = creditCard.length();
+        int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
+        //System.out.println(creditCard.length());
+
+        for (int i = (creditCardLength - 1); i >= 0; i--) {
+            currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it
+            if (currentDigit % 2 != 0) { // Is this number an odd number?
+                sum += currentDigit;
+                if (debug) {
+                    System.out.println(currentDigit);
+                    System.out.println("sum: " + sum);
+                }
+            }
+        }
+
+        return sum;
+    }
+
+    /**
+     * Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. 2 * 2 = 4 2 * 2 = 4 4 * 2 = 8 1 * 2 = 2 6 * 2 = 12 (1 + 2 = 3) 5 * 2 = 10 (1 + 0 = 1) 8 * 2 = 16 (1 + 6 = 7) 4 * 2 = 8 Step 2 Now add all single-digit numbers from Step 1. 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37
+     *
+     * @param -creditCard the credit card number to be processed.
+     * @return
+     */
+    public static int doubleDigitsAndSumSingleDigits(String creditCard) {
+        if (debug) {
+            System.out.println("Now executing doubleDigitsAndSumSingleDigits()");
+        }
+        // Iterate through string
+        int creditCardLength = creditCard.length();
+        int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
+        //System.out.println(creditCard.length());
+
+        for (int i = (creditCardLength - 1); i >= 0; i--) {
+            if (i % 2 == 0) {
+                currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it
+                if (debug) {
+                    System.out.println("current digit: " + currentDigit);
+                }
+                digitProduct = currentDigit * 2;
+                if (digitProduct > 9) { // Product is larger than 9. Typecast the integer back into a string so we can seperate the digits and add them together.
+                    String workingString = Integer.toString(digitProduct);
+                    tensDigit = Character.getNumericValue(workingString.charAt(0));
+                    onesDigit = Character.getNumericValue(workingString.charAt(1));
+                    if (debug) {
+                        System.out.println("tensDigit is " + tensDigit);
+                        System.out.println("onesDigit is " + onesDigit);
+                    }
+                    digitProduct = (tensDigit + onesDigit);
+                }
+                sum += digitProduct;
+            }
+
+        }
+        if (debug) {
+            System.out.println("The sum is: " + sum);
+        }
+        return sum;
+    }
+
+    /**
+     * Displays Q/q or C/c. If the user enters C, it read the credit number and returns it as String. If the user types Q/q returns 0
+     *
+     * @return a string with credit card number or 0.
+     */
+    public static String menu() {
+        String userInput = "";
+        Scanner input = new Scanner(System.in);
+        
+        while (!userInput.equals("0"))//user has not entered Q/q
+        {
+            System.out.println("Press Q/q to quit");
+            System.out.println("Press C/c to enter a credit card");
+            userInput = input.next();
+            if (userInput.equalsIgnoreCase("q")) {
+                userInput = "0";
+            }
+            if (userInput.equalsIgnoreCase("c")) {
+                System.out.print("Please enter a credit card number: ");
+                userInput = input.next();
+                break;
+            }
+        }
+        
+        return userInput;
+    }
+
+    /**
+     *
+     * @param args
+     */
+    public static void main(String[] args) {
+
+        //String sampleCreditCard = "4388576018410707";
+        String userInput = menu();
+        if (userInput == "0") { // Stop program execution if credit card not entered
+            System.out.println("Credit card not entered!");
+            System.exit(0);
+        } 
+        
+        boolean creditCardValidity = MP4_CalebFontenot.isValid(userInput);
+        String validityString;
+        if (creditCardValidity) {
+            validityString = "valid";
+        } else {
+            validityString = "invalid";
+        }
+
+        System.out.println("The credit card " + userInput + " is " + validityString);
+    }
+
+}
+
+
+ diff --git a/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java b/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java index 11ed45a..ea72cb1 100644 --- a/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java +++ b/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java @@ -149,7 +149,7 @@ public class MP4_CalebFontenot { */ public static void main(String[] args) { - String sampleCreditCard = "4388576018410707"; + //String sampleCreditCard = "4388576018410707"; String userInput = menu(); if (userInput == "0") { // Stop program execution if credit card not entered System.out.println("Credit card not entered!"); diff --git a/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array5.java b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array5.java new file mode 100644 index 0000000..b19b45e --- /dev/null +++ b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array5.java @@ -0,0 +1,38 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package lab15_calebfontenot; + +/** + * + * @author caleb + */ +public class Array5 { + public static void main(String[] args) + { + String[] alphaBetics = new String[5]; + final int NAME_SIZE = 20; + + //print the array that has all nulls + for (int i = 0; i < alphaBetics.length; i++) { + System.out.println(alphaBetics[i]); + } + //init the array to character numbers + for (int i = 0; i < alphaBetics.length; i++) { + alphaBetics[i] = "index " + Integer.toString(i) + " "; + } + //append to the array 20 random alphabetic characters + for (int i = 0; i < alphaBetics.length; i++) { + for (int j = 0; j < NAME_SIZE; j++) { + alphaBetics[i] += (char) (65 + Math.random() * 26); + } + } + + //print the array again + for (int i = 0; i < alphaBetics.length; i++) { + System.out.println(alphaBetics[i]); + + } + } +} diff --git a/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array6.java b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array6.java new file mode 100644 index 0000000..fc3622b --- /dev/null +++ b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array6.java @@ -0,0 +1,57 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package lab15_calebfontenot; + +/** + * + * @author caleb + */ +public class Array6 { + + public static void main(String[] args) + { + String[] alphaBetics = new String[10]; + final int NAME_SIZE = 3; + /* + //print the array that has all nulls + for (int i = 0; i < alphaBetics.length; i++) { + System.out.println(alphaBetics[i]); + } + */ + //init the array to character numbers + for (int i = 0; i < alphaBetics.length; i++) { + alphaBetics[i] = ""; + } + + //append to the array 20 random alphabetic characters + for (int i = 0; i < alphaBetics.length; i++) { + for (int j = 0; j < NAME_SIZE; j++) { + alphaBetics[i] += (char) (97 + Math.random() * 26); + } + } + //print the array + for (int i = 0; i < alphaBetics.length; i++) { + System.out.println(alphaBetics[i]); + + } + System.out.println(); + // Reverse each string in the array + String tmp = ""; + for (int i = 0; i < alphaBetics.length; i++) { + tmp = ""; + int stringLength = alphaBetics[i].length(); + for (int j = 0; j < stringLength; j++) { + char currentChar = alphaBetics[i].charAt(j); + tmp = currentChar + tmp; + } + alphaBetics[i] = tmp; + } + for (int i = 0; i < alphaBetics.length; i++) { + System.out.println(alphaBetics[i]); + + } + } +} + diff --git a/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array7.java b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array7.java new file mode 100644 index 0000000..5592b46 --- /dev/null +++ b/Assignments/lab15_CalebFontenot/src/lab15_calebfontenot/Array7.java @@ -0,0 +1,60 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package lab15_calebfontenot; + +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class Array7 { + + public static int getLargest(int[] a, int total) + { + int temp; + for (int i = 0; i < total; i++) { + for (int j = i + 1; j < total; j++) { + if (a[i] > a[j]) { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + return (total - 1); + } + + public static void main(String[] args) + { + // Create array + int numArray[] = new int[5]; + int i = 0; + + // Scanner + Scanner input = new Scanner(System.in); + + //Prompt for input + do { + System.out.print("Enter 5 numbers between the range of 10 to 20: "); + numArray[i] = input.nextInt(); + i++; + } while (i < 5); + + // Print the array + for (int j = 0; j < numArray.length; j++) { + System.out.println(numArray[j]); + } + // Find the maximum + System.out.println("The largest item in the array is: " + getLargest(numArray, numArray.length)); + int index = 0; + for (int j = 0; j < numArray.length; j++) { + if(numArray[j] == getLargest(numArray, numArray.length)) { + index = j; + } + } + System.out.println("it is the " + (index + 1) + "th item in the array"); + } +} diff --git a/Assignments/lab16_arrays2_CalebFontenot/lab17-3-1.pdf b/Assignments/lab16_arrays2_CalebFontenot/lab17-3-1.pdf new file mode 100644 index 0000000..240165a Binary files /dev/null and b/Assignments/lab16_arrays2_CalebFontenot/lab17-3-1.pdf differ diff --git a/Assignments/lab16_arrays2_CalebFontenot/pom.xml b/Assignments/lab16_arrays2_CalebFontenot/pom.xml new file mode 100644 index 0000000..a58c2b7 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + lab16_arrays2_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 1.8 + 1.8 + com.calebfontenot.lab16_arrays2_calebfontenot.Lab16_arrays2_CalebFontenot + + \ No newline at end of file diff --git a/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift1.java b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift1.java new file mode 100644 index 0000000..d40a4c3 --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayShift1.java @@ -0,0 +1,26 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package com.calebfontenot.lab16_arrays2_calebfontenot; + +/** + * + * @author caleb + */ +public class ArrayShift1 { + public static void main(String[] args) + { + int[] ar = {1, 2, 3, 4, 5}; + int temp = ar[0]; + for (int i = 1; i < ar.length; ++i) { + ar[i-1] = ar[i]; + + ar[ar.length - 1] = temp; + + for (int value: ar) { + System.out.println(value + " "); + } + } + } +} diff --git a/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/Lab16_arrays2_CalebFontenot.java b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/Lab16_arrays2_CalebFontenot.java new file mode 100644 index 0000000..a94694d --- /dev/null +++ b/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/Lab16_arrays2_CalebFontenot.java @@ -0,0 +1,17 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template + */ + +package com.calebfontenot.lab16_arrays2_calebfontenot; + +/** + * + * @author caleb + */ +public class Lab16_arrays2_CalebFontenot { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/Test Project/target/classes/.netbeans_automatic_build b/Test Project/target/classes/.netbeans_automatic_build deleted file mode 100644 index e69de29..0000000 diff --git a/Test Project/target/test-classes/.netbeans_automatic_build b/Test Project/target/test-classes/.netbeans_automatic_build deleted file mode 100644 index e69de29..0000000 diff --git a/ZIPs/MP4_CalebFontenot.zip b/ZIPs/MP4_CalebFontenot.zip new file mode 100644 index 0000000..dcfd356 Binary files /dev/null and b/ZIPs/MP4_CalebFontenot.zip differ