Reset author name to chosen name

This commit is contained in:
2025-10-19 22:02:41 -05:00
parent 168b35c94a
commit 578c33de70
316 changed files with 17381 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
/*
* 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.chloefontenot.mp5_chloefontenot;
import java.util.Scanner;
/**
*
* @author chloe
*/
public class MP5_ChloeFontenot {
// Toggles execution of the printArray method.
static final boolean debug = true;
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 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);
}
}