diff --git a/.gitignore b/.gitignore
index f39916b..90e0c56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,3 +43,4 @@
/Assignments/Experiments/mavenproject1/target/
/Assignments/lab16_arrays2_CalebFontenot/target/
/Assignments/lab17_CalebFontenot/target/
+/Assignments/MP5_CalebFontenot/target/
diff --git a/Assignments/MP5_CalebFontenot/MP5_CalebFontenot.html b/Assignments/MP5_CalebFontenot/MP5_CalebFontenot.html
new file mode 100644
index 0000000..1449d18
--- /dev/null
+++ b/Assignments/MP5_CalebFontenot/MP5_CalebFontenot.html
@@ -0,0 +1,113 @@
+
+
+
+MP5_CalebFontenot.java
+
+
+
+
+/home/caleb/ASDV-Java/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java |
+
+
+nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
+nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/$
+
+package com.calebfontenot.mp5_calebfontenot;
+
+import java.util.Scanner;
+
+
+
+@author
+
+public class MP5_CalebFontenot {
+
+ static final boolean debug = false;
+
+ public static void printArray(boolean[] array) {
+
+ final String ANSI_RED = "\u001B[31m";
+ final String ANSI_GREEN = "\u001B[32m";
+ final String ANSI_WHITE = "\u001B[37m";
+
+
+ for (int i = 0; i <= array.length - 1; i++) {
+ if (array[i]) {
+ System.out.print(ANSI_GREEN + array[i] + " ");
+ } else {
+ System.out.print(ANSI_RED + array[i] + " ");
+ }
+ if (i != 0) {
+ if ((i + 1) % 10 == 0) {
+ System.out.println(ANSI_WHITE);
+ }
+ }
+ }
+ }
+
+ public static void solveAndPrint(boolean[] array, int studentCount) {
+ for (int student = 1; student <= studentCount; student++) {
+ if (debug) {
+ System.out.println("Student " + student + " is interacting with the lockers!");
+ }
+ for (int i = 0; i <= array.length - 1; i++) {
+ if ((i + 1) % student == 0) {
+ array[i] = !array[i];
+ }
+ }
+ if (debug) {
+ printArray(array);
+ }
+ }
+ for (int i = 0; i < array.length; i++) {
+ if (array[i]) {
+ System.out.println("Locker " + (i + 1) + " is open.");
+ }
+ }
+ }
+
+ public static int menu() {
+
+ Scanner input = new Scanner(System.in);
+ int userInput;
+ do {
+ System.out.print("Enter 0 to quit, and 1 to enter the number of students: ");
+ userInput = input.nextInt();
+ if (userInput == 1) {
+ System.out.print("Enter the number of students: ");
+ userInput = input.nextInt();
+ break;
+ }
+
+ } while (userInput != 0);
+ return userInput;
+ }
+
+ public static void main(String[] args) {
+ final int N = menu();
+ boolean[] lockers = new boolean[N];
+
+ solveAndPrint(lockers, N);
+
+ }
+}
+
+
+
diff --git a/Assignments/MP5_CalebFontenot/pom.xml b/Assignments/MP5_CalebFontenot/pom.xml
index 2c6bb17..0f9119c 100644
--- a/Assignments/MP5_CalebFontenot/pom.xml
+++ b/Assignments/MP5_CalebFontenot/pom.xml
@@ -7,8 +7,8 @@
jar
UTF-8
- 18
- 18
+ 19
+ 19
com.calebfontenot.mp5_calebfontenot.MP5_CalebFontenot
\ No newline at end of file
diff --git a/Assignments/MP5_CalebFontenot/run.sh b/Assignments/MP5_CalebFontenot/run.sh
new file mode 100755
index 0000000..5242c68
--- /dev/null
+++ b/Assignments/MP5_CalebFontenot/run.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+mvn exec:java -Dexec.mainClass="com.calebfontenot.mp5_calebfontenot.MP5_CalebFontenot"
diff --git a/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java b/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java
index 6faa4bd..5e39e3f 100644
--- a/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java
+++ b/Assignments/MP5_CalebFontenot/src/main/java/com/calebfontenot/mp5_calebfontenot/MP5_CalebFontenot.java
@@ -2,24 +2,82 @@
* 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.mp5_calebfontenot;
+import java.util.Scanner;
+
/**
*
* @author caleb
*/
public class MP5_CalebFontenot {
+ // Toggles execution of the printArray method.
+ static final boolean debug = true;
- public static void solveAndPrint(boolean[] ar) {
-
+ public static void printArray(boolean[] array) {
+ // Color codes
+ final String ANSI_RED = "\u001B[31m";
+ final String ANSI_GREEN = "\u001B[32m";
+ final String ANSI_WHITE = "\u001B[37m";
+
+ // Print the array
+ for (int i = 0; i <= array.length - 1; i++) {
+ if (array[i]) {
+ System.out.print(ANSI_GREEN + array[i] + " ");
+ } else {
+ System.out.print(ANSI_RED + array[i] + " ");
+ }
+ if (i != 0) {
+ if ((i + 1) % 10 == 0) {
+ System.out.println(ANSI_WHITE);
+ }
+ }
+ }
}
-
- public static int[] menu() {
-
+
+ public static void solveAndPrint(boolean[] array, int studentCount) {
+ for (int student = 1; student <= studentCount; student++) {
+ if (debug) {
+ System.out.println("Student " + student + " is interacting with the lockers!");
+ }
+ for (int i = 0; i <= array.length - 1; i++) {
+ if ((i + 1) % student == 0) {
+ array[i] = !array[i];
+ }
+ }
+ if (debug) {
+ printArray(array);
+ }
+ }
+ for (int i = 0; i < array.length; i++) {
+ if (array[i]) {
+ System.out.println("Locker " + (i + 1) + " is open.");
+ }
+ }
}
-
+
+ public static int menu() {
+ // Create scanner
+ Scanner input = new Scanner(System.in);
+ int userInput;
+ do {
+ System.out.print("Enter 0 to quit, and 1 to enter the number of students: ");
+ userInput = input.nextInt();
+ if (userInput == 1) {
+ System.out.print("Enter the number of students: ");
+ userInput = input.nextInt();
+ break;
+ }
+
+ } while (userInput != 0);
+ return userInput;
+ }
+
public static void main(String[] args) {
-
+ final int N = menu();
+ boolean[] lockers = new boolean[N];
+ // Execute solve and print
+ solveAndPrint(lockers, N);
+
}
}
diff --git a/ZIPs/MP5_CalebFontenot.zip b/ZIPs/MP5_CalebFontenot.zip
new file mode 100644
index 0000000..b6a294b
Binary files /dev/null and b/ZIPs/MP5_CalebFontenot.zip differ