commit f2b14c75c224ba91b6e927f2b0dad6368422868e Author: Zakaria Date: Fri Nov 28 12:06:47 2025 -0500 study.com work diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..e0ff594 Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a0ccf77 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Environment-dependent path to Maven home directory +/mavenHomeManager.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b67940c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..d843f34 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Computer Science 202 - Assignment 1- Action Plan for Network Security.docx b/Computer Science 202 - Assignment 1- Action Plan for Network Security.docx new file mode 100644 index 0000000..ebf1a0a Binary files /dev/null and b/Computer Science 202 - Assignment 1- Action Plan for Network Security.docx differ diff --git a/Computer Science 202 - Assignment 2- Improving Code for Security .docx b/Computer Science 202 - Assignment 2- Improving Code for Security .docx new file mode 100644 index 0000000..099c13b Binary files /dev/null and b/Computer Science 202 - Assignment 2- Improving Code for Security .docx differ diff --git a/ComputerScience104/.DS_Store b/ComputerScience104/.DS_Store new file mode 100644 index 0000000..61c0c2e Binary files /dev/null and b/ComputerScience104/.DS_Store differ diff --git a/ComputerScience104/Assignment 3/.DS_Store b/ComputerScience104/Assignment 3/.DS_Store new file mode 100644 index 0000000..848827a Binary files /dev/null and b/ComputerScience104/Assignment 3/.DS_Store differ diff --git a/ComputerScience104/Assignment 3/CS104_Assignment_1 b/ComputerScience104/Assignment 3/CS104_Assignment_1 new file mode 160000 index 0000000..b7d4d6d --- /dev/null +++ b/ComputerScience104/Assignment 3/CS104_Assignment_1 @@ -0,0 +1 @@ +Subproject commit b7d4d6d1ee87e7b64afcb6e8136d1ff9443be5fa diff --git a/ComputerScience104/Assignment2/.DS_Store b/ComputerScience104/Assignment2/.DS_Store new file mode 100644 index 0000000..848827a Binary files /dev/null and b/ComputerScience104/Assignment2/.DS_Store differ diff --git a/ComputerScience104/Assignment2/CS104_Assignment_1 b/ComputerScience104/Assignment2/CS104_Assignment_1 new file mode 160000 index 0000000..4df044c --- /dev/null +++ b/ComputerScience104/Assignment2/CS104_Assignment_1 @@ -0,0 +1 @@ +Subproject commit 4df044c9c54e2a071cb3870000fdbc104c4c39a4 diff --git a/ComputerScience104/CS104_Assignment_1 b/ComputerScience104/CS104_Assignment_1 new file mode 160000 index 0000000..0af8e15 --- /dev/null +++ b/ComputerScience104/CS104_Assignment_1 @@ -0,0 +1 @@ +Subproject commit 0af8e15f447d21859c7da42aa566335191068cc0 diff --git a/ComputerScience107/Computer Science 107 - Assignment .docx b/ComputerScience107/Computer Science 107 - Assignment .docx new file mode 100644 index 0000000..aaa5a25 Binary files /dev/null and b/ComputerScience107/Computer Science 107 - Assignment .docx differ diff --git a/ComputerScience109/.DS_Store b/ComputerScience109/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/ComputerScience109/.DS_Store differ diff --git a/ComputerScience109/ComputerScience104 | Intro to Web Development - Assignment 1.docx b/ComputerScience109/ComputerScience104 | Intro to Web Development - Assignment 1.docx new file mode 100644 index 0000000..d1cc47a Binary files /dev/null and b/ComputerScience109/ComputerScience104 | Intro to Web Development - Assignment 1.docx differ diff --git a/ComputerScience109/ComputerScience109 - ASSIGMENT 1.docx b/ComputerScience109/ComputerScience109 - ASSIGMENT 1.docx new file mode 100644 index 0000000..e755f30 Binary files /dev/null and b/ComputerScience109/ComputerScience109 - ASSIGMENT 1.docx differ diff --git a/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 1.docx b/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 1.docx new file mode 100644 index 0000000..1eae508 Binary files /dev/null and b/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 1.docx differ diff --git a/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 2.docx b/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 2.docx new file mode 100644 index 0000000..e5ce804 Binary files /dev/null and b/ComputerScience109/ComputerScience109 | Introduction to Programming - Assignment 2.docx differ diff --git a/ComputerScience109/Main.java b/ComputerScience109/Main.java new file mode 100644 index 0000000..6ded1ff --- /dev/null +++ b/ComputerScience109/Main.java @@ -0,0 +1,118 @@ +/* + * in this Java program, the user can calculate the area of a rectangle, + * and the volumes of a cube, cylinder, and sphere. + * The user will be prompt to enter the length and width of a rectangle, + * and then choose a shape to calculate the volume of (cube, cylinder, or sphere). + */ + +import java.util.InputMismatchException; +import java.util.Scanner; + +class Rectangle { + public static double rectangleArea(double length, double width) { + return length * width; + } +} + +class Cube { + public static double cubeVolume(double side) { + return Math.pow(side, 3); + } +} + +class Cylinder { + public static double cylinderVolume(double radius, double height) { + return Math.PI * Math.pow(radius, 2) * height; + } +} + +class Sphere { + public static double sphereVolume(double radius) { + return (4.0 / 3.0) * Math.PI * Math.pow(radius, 3); + } +} +//Main Class + +public class Main{ + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + try { + // User prompt for the length and width + System.out.println("Rectangle Area"); + System.out.print("Please enter length: "); + double length = scanner.nextDouble(); + + System.out.print("Please enter width: "); + double width = scanner.nextDouble(); + +// making sure that the user put positive numbers otherwise we throw a //warning + + if (length <= 0 || width <= 0) { + System.out.println("WARNING!: Length and width must be positive numbers."); + } else { + double area = Rectangle.rectangleArea(length, width); + System.out.println("Rectangle Area: " + area); + } + + // Choose shape for volume calculation + + System.out.println(""); + System.out.println("Volume Calculation"); + System.out.println("Choose a shape to calculate volume:"); + System.out.println("1. Cube"); + System.out.println("2. Cylinder "); + System.out.println("3. Sphere "); + System.out.print("Enter your choice (1-3): "); + int userChoice = scanner.nextInt(); + + + + switch (userChoice) { + case 1: + System.out.print("Enter side length of cube: "); + double side = scanner.nextDouble(); + if (side <= 0) { + System.out.println("Error: Side must be a positive number."); + } else { + double cubeVolume = Cube.cubeVolume(side); + System.out.println("Cube Volume: " + cubeVolume); + } + break; + case 2: + System.out.print("Enter radius of cylinder: "); + double cylinderRadius = scanner.nextDouble(); + System.out.print("Enter height of cylinder: "); + double cylinderHeight = scanner.nextDouble(); + if (cylinderRadius <= 0 || cylinderHeight <= 0) { + System.out.println("Error: Radius and height must be positive numbers."); + } else { + double cylinderVolume = Cylinder.cylinderVolume(cylinderRadius, cylinderHeight); + System.out.println("Cylinder Volume: " + cylinderVolume); + } + break; + case 3: + System.out.print("Enter radius of sphere: "); + double sphereRadius = scanner.nextDouble(); + if (sphereRadius <= 0) { + System.out.println("Error: Radius must be a positive number."); + } else { + double sphereVolume = Sphere.sphereVolume(sphereRadius); + System.out.println("Sphere Volume: " + sphereVolume); + } + break; + default: + System.out.println("Invalid choice."); + } + + } catch (InputMismatchException e) { + System.out.println("Input error: Please enter valid numeric values."); + } finally { + scanner.close(); + } + } +} + +//Please copy and paste this code to an IDE and run + diff --git a/ComputerScience109/PerfectNumbers.class b/ComputerScience109/PerfectNumbers.class new file mode 100644 index 0000000..6b18ea7 Binary files /dev/null and b/ComputerScience109/PerfectNumbers.class differ diff --git a/ComputerScience109/PerfectNumbers.java b/ComputerScience109/PerfectNumbers.java new file mode 100644 index 0000000..0037461 --- /dev/null +++ b/ComputerScience109/PerfectNumbers.java @@ -0,0 +1,85 @@ +import java.util.Scanner; +/* + * The program below is a java script that helps find the perfect numbers using + * Nested Loops. + * A perfect numbersber is a positive integer that equals the sum of its + * proper positive divisors (excluding the number itself) + * */ + +public class PerfectNumbers { + + public static void main(String[] args) { + // Part 1: Find perfect numbers between 1 and 200 + System.out.println("Perfect Numbers between 1 and 200:"); + // findAndPrintPerfectNumber(200); + + // Add a separator line in the output. + System.out.println("\n----------------------------------------\n"); + + // Part 2: User input range (up to maximum of 1000) + Scanner scanner = new Scanner(System.in); + + int upperBound; + do { + System.out.print("Enter an upper bound between 1 and 1000 for checking perfect numbers: "); + while (!scanner.hasNextInt()) { // Validate integer input. + System.out.println("That's not a valid number. Please enter an integer."); + scanner.next(); // discard invalid input + System.out.print("Enter an upper bound between 1 and 1000: "); + } + upperBound = scanner.nextInt(); + + if (upperBound < 1 || upperBound > 9000) { + System.out.println("Please enter a number between 1 and 1000."); + } else { + break; + } + } while (true); + + // Now check for perfect numbers in the user-specified range. + System.out.println("\nPerfect Numbers between 1 and " + upperBound + ":"); + // findAndPrintPerfectNumber(upperBound); + + scanner.close(); + } + + /** + * This method finds and prints all perfect numbers up to a given limit + * (inclusive). + */ + public static void perfectNums() { + // Let's get the perfect numbers in the a range of positive integers ( 1 to 200) + // OUTER LOOP + for (int i = 1; i <= 200; i++) { + int total = 0; + // INNER LOOP + for (int j = 1; j <= i / 2; j++) { + total += j; + } + + if (total == i) { + System.out.println(i + " is a perfect number"); + } + } + } + // public static void findAndPrintPerfectNumber(int limit) { + // for (int i = 1; i <= limit; i++) { // Loop through each number + // int sumOfDivisors = 0; + // + // // Find proper divisors using nested loops. + // // Note: Instead of a nested loop, we can iterate up to half of the number, + // // but since you requested a nested loop approach, here's how it might look: + // for (int j = 1; j <= i / 2; j++) { // Only need to check up to i/2 + // if (i % j == 0) { + // sumOfDivisors += j; + // } + // } + // + // // Check if the number is perfect. + // if (sumOfDivisors == i && i != 1) { // Exclude 1 as it's not considered a + // perfect number + // System.out.println(i); + // } + // } + // } +} diff --git a/ComputerScience115/CS115.class b/ComputerScience115/CS115.class new file mode 100644 index 0000000..a582cd6 Binary files /dev/null and b/ComputerScience115/CS115.class differ diff --git a/ComputerScience115/ComputerScience115 | Programming in Java - Assignment 1.docx b/ComputerScience115/ComputerScience115 | Programming in Java - Assignment 1.docx new file mode 100644 index 0000000..fc0b740 Binary files /dev/null and b/ComputerScience115/ComputerScience115 | Programming in Java - Assignment 1.docx differ diff --git a/ComputerScience115/GradeCalculatorProject.class b/ComputerScience115/GradeCalculatorProject.class new file mode 100644 index 0000000..f442ecf Binary files /dev/null and b/ComputerScience115/GradeCalculatorProject.class differ diff --git a/ComputerScience115/GradeCalculatorProject.java b/ComputerScience115/GradeCalculatorProject.java new file mode 100644 index 0000000..66df936 --- /dev/null +++ b/ComputerScience115/GradeCalculatorProject.java @@ -0,0 +1,85 @@ + +/** + * CS115 + */ +import java.util.Scanner; + +public class GradeCalculatorProject { + + /* Print specifications – method separate from main */ + public static void main(String[] args) { + + final int MAX_GRADES = 10; // the max arrau length + final int QUIT = 999; // to quit + int[] grades = new int[MAX_GRADES]; // array of grades + int count = 0; // how many grades the user entered + int total = 0; // calculate the total of grades + + printSpecifications(); // specifications + Scanner sc = new Scanner(System.in); + + /* Main input loop – stop either on 999 or after 10 grades */ + System.out.print("Enter quiz grade (or 999 to finish): "); + while (count < MAX_GRADES) { + int grade = sc.nextInt(); + + /* Stop if user typed 999 */ + if (grade == QUIT) { + System.out.println("...Quitting…"); + break; + } + + if (grade < 0 || grade > 100) { + System.out.println("Invalid grade – must be 0‑100. Try again."); + continue; // don't count this iteration + } + + grades[count] = grade; // store the grade + total += grade; // addition while looping + count++; // increment number of grades as long as they dont exceed 10. + + System.out.print("Enter next quiz grade (or 999 to finish): "); + } + + sc.close(); + + /* Print all grades entered */ + System.out.println("\n=== All Grades Entered ==="); + for (int i = 0; i < count; i++) { + System.out.println("Grade #" + (i + 1) + " : " + grades[i]); + System.out.println(""); + } + + /* Compute average */ + double average = 0.0; + if (count > 0) { + average = (double) total / count; // we cast the total since the total is an int + } + System.out.printf("\nAverage of %d grades is: %.2f%n", count, average); + char letterGrade = determineLetterGrade(average); + System.out.println("Letter grade: " + letterGrade); + System.out.println("===== End ====="); + } + + private static void printSpecifications() { + System.out.println("\n===== Quiz Grade Calculator ====="); + System.out.println("This program will take 10 quiz grades from 0‑100,"); + System.out.println("Once all the ten inputs are entered, your grades will be printed,"); + System.out.println("and the program will compute your average score and letter grade."); + System.out.println("If you wish to QUIT the program please type 999.\n"); + System.out.println(""); + } + + private static char determineLetterGrade(double average) { + // pretty self exlainatory:qw! + if (average >= 90) + return 'A'; + if (average >= 80) + return 'B'; + if (average >= 70) + return 'C'; + if (average >= 60) + return 'D'; + return 'F'; + } +} diff --git a/ComputerScience201/.DS_Store b/ComputerScience201/.DS_Store new file mode 100644 index 0000000..66f052b Binary files /dev/null and b/ComputerScience201/.DS_Store differ diff --git a/ComputerScience201/.idea/.gitignore b/ComputerScience201/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/ComputerScience201/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/ComputerScience201/.idea/codeStyles/Project.xml b/ComputerScience201/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/ComputerScience201/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml b/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/ComputerScience201/.idea/misc.xml b/ComputerScience201/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/ComputerScience201/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ComputerScience201/.idea/modules.xml b/ComputerScience201/.idea/modules.xml new file mode 100644 index 0000000..99197ed --- /dev/null +++ b/ComputerScience201/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ComputerScience201/.idea/vcs.xml b/ComputerScience201/.idea/vcs.xml new file mode 100644 index 0000000..d843f34 --- /dev/null +++ b/ComputerScience201/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ComputerScience201/BinarySearchTreeApp.java b/ComputerScience201/BinarySearchTreeApp.java new file mode 100644 index 0000000..1e6f1cc --- /dev/null +++ b/ComputerScience201/BinarySearchTreeApp.java @@ -0,0 +1,217 @@ +import java.util.Scanner; + +// Node class representing each element in the Binary Search Tree (BST) +class Node { + int value; + Node left, right; + + // Constructor to initialize a node with a given value + public Node(int item) { + value = item; + left = right = null; + } +} + +// BinarySearchTree class that implements the BST operations +class BinarySearchTree { + Node root; + + // Method to create a balanced BST from a sorted array + public void createBalancedBST(int[] sortedValues) { + root = buildBalancedBST(sortedValues, 0, sortedValues.length - 1); + } + + // Helper method to recursively build a balanced BST + private Node buildBalancedBST(int[] arr, int start, int end) { + if (start > end) + return null; + + int mid = (start + end) / 2; // Find the middle index + Node node = new Node(arr[mid]); // Create a new node with the middle value + + // Recursively build left and right subtrees + node.left = buildBalancedBST(arr, start, mid - 1); + node.right = buildBalancedBST(arr, mid + 1, end); + + return node; + } + + // Method to insert a new value into the BST + public void insert(int value) { + root = insertNode(root, value); + } + + // Helper method to recursively insert a new value + private Node insertNode(Node root, int value) { + if (root == null) + return new Node(value); + + if (value < root.value) + root.left = insertNode(root.left, value); + else if (value > root.value) + root.right = insertNode(root.right, value); + + return root; + } + + // Method to delete a value from the BST + public void delete(int value) { + root = deleteNode(root, value); + } + + // Helper method to recursively delete a value + private Node deleteNode(Node root, int value) { + if (root == null) + return null; + + if (value < root.value) + root.left = deleteNode(root.left, value); + else if (value > root.value) + root.right = deleteNode(root.right, value); + else { + // If the node to delete has no children or one child + if (root.left == null) + return root.right; + else if (root.right == null) + return root.left; + + // If the node has two children, replace with the minimum value in the right subtree + root.value = minValue(root.right); + root.right = deleteNode(root.right, root.value); + } + + return root; + } + + private int minValue(Node root) { + int min = root.value; + while (root.left != null) { + min = root.left.value; + root = root.left; + } + return min; + } + + // Method to print the BST in InOrder traversal (Left -> Root -> Right) + public void printInOrder() { + System.out.print("InOrder: "); + inOrder(root); + System.out.println(); + } + + // Method to print the BST in PreOrder traversal (Root -> Left -> Right) + public void printPreOrder() { + System.out.print("PreOrder: "); + preOrder(root); + System.out.println(); + } + + // Method to print the BST in PostOrder traversal (Left -> Right -> Root) + public void printPostOrder() { + System.out.print("PostOrder: "); + postOrder(root); + System.out.println(); + } + + // Helper method for InOrder traversal + private void inOrder(Node root) { + if (root != null) { + inOrder(root.left); + System.out.print(root.value + " "); + inOrder(root.right); + } + } + + // Helper method for PreOrder traversal + private void preOrder(Node root) { + if (root != null) { + System.out.print(root.value + " "); + preOrder(root.left); + preOrder(root.right); + } + } + + // Helper method for PostOrder traversal + private void postOrder(Node root) { + if (root != null) { + postOrder(root.left); + postOrder(root.right); + System.out.print(root.value + " "); + } + } +} + +// Main application class to run the BST program +public class BinarySearchTreeApp { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + BinarySearchTree bst = new BinarySearchTree(); + + while (true) { + System.out.println("\n--- Binary Search Tree Menu ---"); + System.out.println("1. Create a binary search tree"); + System.out.println("2. Add a node"); + System.out.println("3. Delete a node"); + System.out.println("4. Print nodes by InOrder"); + System.out.println("5. Print nodes by PreOrder"); + System.out.println("6. Print nodes by PostOrder"); + System.out.println("7. Exit program"); + System.out.print("Enter your choice: "); + + int choice = -1; + try { + choice = Integer.parseInt(scanner.nextLine()); + } catch (Exception ignored) { + } + + switch (choice) { + case 1: + // Create a balanced BST from a sorted array + int[] data = {1, 2, 3, 4, 5, 6, 7}; + bst.createBalancedBST(data); + System.out.println("Binary search tree created."); + break; + + case 2: + // Insert a new node into the BST + System.out.print("Enter value to insert: "); + int valueToInsert = Integer.parseInt(scanner.nextLine()); + bst.insert(valueToInsert); + System.out.println("Node inserted."); + break; + + case 3: + // Delete a node from the BST + System.out.print("Enter value to delete: "); + int valueToDelete = Integer.parseInt(scanner.nextLine()); + bst.delete(valueToDelete); + System.out.println("Node deleted (if it existed)."); + break; + + case 4: + // Print the BST in InOrder traversal + bst.printInOrder(); + break; + + case 5: + // Print the BST in PreOrder traversal + bst.printPreOrder(); + break; + + case 6: + // Print the BST in PostOrder traversal + bst.printPostOrder(); + break; + + case 7: + // Exit the program + System.out.println("Exiting program."); + scanner.close(); + return; + + default: + System.out.println("Invalid choice. Please try again."); + } + } + } +} diff --git a/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 1.docx b/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 1.docx new file mode 100644 index 0000000..820819d Binary files /dev/null and b/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 1.docx differ diff --git a/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx b/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx new file mode 100644 index 0000000..9c88799 Binary files /dev/null and b/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx differ diff --git a/ComputerScience201/ComputerScience201.iml b/ComputerScience201/ComputerScience201.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ComputerScience201/ComputerScience201.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience201/TheStates.java b/ComputerScience201/TheStates.java new file mode 100644 index 0000000..0aa4977 --- /dev/null +++ b/ComputerScience201/TheStates.java @@ -0,0 +1,105 @@ +import java.util.*; + +public class TheStates { + // Let's first create a list of all states. + private static final String[] STATES = { + "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", + "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", + "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", + "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", + "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", + "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", + "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", + "Wisconsin", "Wyoming" + }; + + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int choice; + + while (true) { + System.out.println(""); + System.out.println("Menu:"); + System.out.println("1 - Display the text"); + System.out.println("2 - Search"); + System.out.println("3 - Exit program"); + System.out.print("Enter your choice: "); + choice = scanner.nextInt(); + scanner.nextLine(); // consume newline + + switch (choice) { + case 1: + System.out.println("\nText containing all states:\n"); + System.out.println(STATESLIST); + break; + + case 2: + System.out.print("\nEnter a pattern to search: "); + String pattern = scanner.nextLine(); + List results = boyerBadCharSearch(STATESLIST, pattern); + if (results.isEmpty()) { + System.out.println("Pattern not found."); + } else { + System.out.println("Pattern found at indices: " + results); + } + break; + + case 3: + System.out.println("Exiting program."); + scanner.close(); + return; + + default: + System.out.println("Invalid option. Try again."); + } + } + } + + // Create a single string containing all state names separated by a dash + private static final String STATESLIST = String.join(" - ", STATES); + + // Boyer-Moyer bad character search + public static List boyerBadCharSearch(String text, String pattern) { + + List result = new ArrayList<>(); + int[] badChar = buildBadCharTable(pattern); + int m = pattern.length(); + int n = text.length(); + int shift = 0; + + while (shift <= (n - m)) { + int j = m - 1; + + // Move from right to left of the pattern + while (j >= 0 && pattern.charAt(j) == text.charAt(shift + j)) + j--; + + if (j < 0) { + result.add(shift); + if (shift + m < text.length()) { + shift += m - badChar[text.charAt(shift + m)]; + } else { + shift += 1; + } + } else { + shift += Math.max(1, j - badChar[text.charAt(shift + j)]); + } + } + + return result; + } + + // Build bad character table + public static int[] buildBadCharTable(String pattern) { + final int SIZE = 256; + int[] table = new int[SIZE]; + Arrays.fill(table, -1); + + for (int i = 0; i < pattern.length(); i++) { + table[pattern.charAt(i)] = i; + } + + return table; + } +} diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/.gitignore b/ComputerScience201/out/production/ComputerScience201/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/Project.xml b/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..919ce1f --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/Project.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml b/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/misc.xml b/ComputerScience201/out/production/ComputerScience201/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/modules.xml b/ComputerScience201/out/production/ComputerScience201/.idea/modules.xml new file mode 100644 index 0000000..99197ed --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/.idea/vcs.xml b/ComputerScience201/out/production/ComputerScience201/.idea/vcs.xml new file mode 100644 index 0000000..d843f34 --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/.idea/vcs.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/BinarySearchTree.class b/ComputerScience201/out/production/ComputerScience201/BinarySearchTree.class new file mode 100644 index 0000000..74efe57 Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/BinarySearchTree.class differ diff --git a/ComputerScience201/out/production/ComputerScience201/BinarySearchTreeApp.class b/ComputerScience201/out/production/ComputerScience201/BinarySearchTreeApp.class new file mode 100644 index 0000000..afa0e69 Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/BinarySearchTreeApp.class differ diff --git a/ComputerScience201/out/production/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx b/ComputerScience201/out/production/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx new file mode 100644 index 0000000..6791197 Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/ComputerScience201 | Data Structures & Algorithms - Assignment 2.docx differ diff --git a/ComputerScience201/out/production/ComputerScience201/ComputerScience201.iml b/ComputerScience201/out/production/ComputerScience201/ComputerScience201.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/ComputerScience201/out/production/ComputerScience201/ComputerScience201.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience201/out/production/ComputerScience201/Node.class b/ComputerScience201/out/production/ComputerScience201/Node.class new file mode 100644 index 0000000..3ddb7f3 Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/Node.class differ diff --git a/ComputerScience201/out/production/ComputerScience201/TheStates.class b/ComputerScience201/out/production/ComputerScience201/TheStates.class new file mode 100644 index 0000000..747947e Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/TheStates.class differ diff --git a/ComputerScience201/out/production/ComputerScience201/~$mputerScience201 | Data Structures & Algorithms - Assignment 2.docx b/ComputerScience201/out/production/ComputerScience201/~$mputerScience201 | Data Structures & Algorithms - Assignment 2.docx new file mode 100644 index 0000000..cdd527f Binary files /dev/null and b/ComputerScience201/out/production/ComputerScience201/~$mputerScience201 | Data Structures & Algorithms - Assignment 2.docx differ diff --git a/ComputerScience204/Computer Science 204 - Assignment.docx b/ComputerScience204/Computer Science 204 - Assignment.docx new file mode 100644 index 0000000..2643dc0 Binary files /dev/null and b/ComputerScience204/Computer Science 204 - Assignment.docx differ diff --git a/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 1.docx b/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 1.docx new file mode 100644 index 0000000..9d122fa Binary files /dev/null and b/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 1.docx differ diff --git a/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 2.docx b/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 2.docx new file mode 100644 index 0000000..7f1d019 Binary files /dev/null and b/ComputerScience306/ComputerScience306 | Computer Architecture - Assignment 2.docx differ diff --git a/ComputerScience307/ClassDiagnram.xml b/ComputerScience307/ClassDiagnram.xml new file mode 100644 index 0000000..28839ee --- /dev/null +++ b/ComputerScience307/ClassDiagnram.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience307/Computer Science 307 - Assignment 2- Designing UML Diagrams .docx b/ComputerScience307/Computer Science 307 - Assignment 2- Designing UML Diagrams .docx new file mode 100644 index 0000000..727adc2 Binary files /dev/null and b/ComputerScience307/Computer Science 307 - Assignment 2- Designing UML Diagrams .docx differ diff --git a/ComputerScience307/Computer Science 307 - Configuration Management - Assignment 1.docx b/ComputerScience307/Computer Science 307 - Configuration Management - Assignment 1.docx new file mode 100644 index 0000000..ab28c0c Binary files /dev/null and b/ComputerScience307/Computer Science 307 - Configuration Management - Assignment 1.docx differ diff --git a/ComputerScience307/ComputerScience307 - Assignment 3 - Components & User Interface Design.docx b/ComputerScience307/ComputerScience307 - Assignment 3 - Components & User Interface Design.docx new file mode 100644 index 0000000..39b7cae Binary files /dev/null and b/ComputerScience307/ComputerScience307 - Assignment 3 - Components & User Interface Design.docx differ diff --git a/ComputerScience307/DeploymentUML.xml b/ComputerScience307/DeploymentUML.xml new file mode 100644 index 0000000..34b97ad --- /dev/null +++ b/ComputerScience307/DeploymentUML.xml @@ -0,0 +1,260 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience307/UML_Seq.xml b/ComputerScience307/UML_Seq.xml new file mode 100644 index 0000000..9376c7b --- /dev/null +++ b/ComputerScience307/UML_Seq.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience307/UML_USECASE.xml b/ComputerScience307/UML_USECASE.xml new file mode 100644 index 0000000..9d273ad --- /dev/null +++ b/ComputerScience307/UML_USECASE.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ComputerScience307/activityDiagram.xml b/ComputerScience307/activityDiagram.xml new file mode 100644 index 0000000..af0d3b6 --- /dev/null +++ b/ComputerScience307/activityDiagram.xml @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ComputerScience307/dataFlow.xml b/ComputerScience307/dataFlow.xml new file mode 100644 index 0000000..ce8109c --- /dev/null +++ b/ComputerScience307/dataFlow.xml @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ComputerScience307/stateChart.xml b/ComputerScience307/stateChart.xml new file mode 100644 index 0000000..e35907a --- /dev/null +++ b/ComputerScience307/stateChart.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 1.docx b/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 1.docx new file mode 100644 index 0000000..469ad1d Binary files /dev/null and b/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 1.docx differ diff --git a/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 2.docx b/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 2.docx new file mode 100644 index 0000000..3cf69fb Binary files /dev/null and b/ComputerScience311ai/ComputerScience301 | Artificial Intelligence - Assignment 2.docx differ diff --git a/ComputerScience311ai/PoliticalSurvey$SurveyQuestion.class b/ComputerScience311ai/PoliticalSurvey$SurveyQuestion.class new file mode 100644 index 0000000..6bafb9d Binary files /dev/null and b/ComputerScience311ai/PoliticalSurvey$SurveyQuestion.class differ diff --git a/ComputerScience311ai/PoliticalSurvey.class b/ComputerScience311ai/PoliticalSurvey.class new file mode 100644 index 0000000..68aef0d Binary files /dev/null and b/ComputerScience311ai/PoliticalSurvey.class differ diff --git a/ComputerScience311ai/PoliticalSurvey.java b/ComputerScience311ai/PoliticalSurvey.java new file mode 100644 index 0000000..6d6beeb --- /dev/null +++ b/ComputerScience311ai/PoliticalSurvey.java @@ -0,0 +1,428 @@ +import java.util.*; +import java.io.*; + +public class PoliticalSurvey { + private static final String[] POLITICAL_PARTIES = { + "Democratic", "Republican", "Libertarian", "Green" + }; + + private static final Map>> partyResponsePatterns = new HashMap<>(); + + // let's create a training data points per party + private static final int[] partyDataPoints = new int[POLITICAL_PARTIES.length]; + + // I gathered some random politiacl questions + private static final List QUESTIONS = new ArrayList<>(); + + private static final Scanner scanner = new Scanner(System.in); + + private static final double CONFIDENCE_THRESHOLD = 0.65; + + public static void main(String[] args) { + initializeQuestions(); + initializePartyResponsePatterns(); + + System.out.println("=========================================================="); + System.out.println(" POLITICAL PARTY PREDICTION SURVEY"); + System.out.println("=========================================================="); + System.out.println("This program will try to predict your political affiliation"); + System.out.println("based on your responses to several questions."); + System.out.println(); + + boolean continueSurvey = true; + + while (continueSurvey) { + List userResponses = conductSurvey(); + addTrainingData(userResponses); + + System.out.println("\nWould you like to take the survey again? (yes/no)"); + String response = scanner.nextLine().trim().toLowerCase(); + continueSurvey = response.equals("yes") || response.equals("y"); + + if (continueSurvey) { + System.out.println("\n==========================================================\n"); + } + } + + System.out.println("\nThank you for using the Political Party Prediction Survey!"); + scanner.close(); + } + + // Initialize the survey questions + private static void initializeQuestions() { + QUESTIONS.add(new SurveyQuestion( + "What should the government do to help the poor?", + new String[] { + "Make it easier to apply for assistance", + "Allow parents to use education funds for charter schools", + "Create welfare-to-work programs", + "Nothing, private charity should handle it" + })); + + QUESTIONS.add(new SurveyQuestion( + "What is your view on taxation?", + new String[] { + "Higher taxes on the wealthy to fund social programs", + "Lower taxes to stimulate economic growth", + "Minimal taxation, only for essential services", + "Tax policies focused on environmental sustainability" + })); + + QUESTIONS.add(new SurveyQuestion( + "What is your stance on healthcare?", + new String[] { + "Universal healthcare funded by the government", + "Market-based healthcare with limited government involvement", + "Free-market healthcare with no government involvement", + "Community-based healthcare systems with government support" + })); + + QUESTIONS.add(new SurveyQuestion( + "What is your view on gun control?", + new String[] { + "Stricter gun control laws are needed", + "Existing gun laws are sufficient", + "Gun ownership is a fundamental right with minimal restrictions", + "Gun control with community-based oversight" + })); + + QUESTIONS.add(new SurveyQuestion( + "How should we address climate change?", + new String[] { + "Government regulations and investment in renewable energy", + "Market-based solutions with limited regulations", + "No government intervention, let the market decide", + "Aggressive environmental policies and global cooperation" + })); + + QUESTIONS.add(new SurveyQuestion( + "What should be our approach to foreign policy?", + new String[] { + "Global cooperation and diplomatic engagement", + "Strong national defense and protecting American interests", + "Non-interventionism and free trade", + "International cooperation for peace and environmental protection" + })); + + QUESTIONS.add(new SurveyQuestion( + "What is your stance on immigration?", + new String[] { + "Path to citizenship for undocumented immigrants", + "Stronger border security and merit-based immigration", + "Open borders with minimal restrictions", + "Humanitarian-focused immigration policies" + })); + + QUESTIONS.add(new SurveyQuestion( + "Which political party do you most closely affiliate with?", + POLITICAL_PARTIES)); + } + + // Initialize response patterns with starting weights, just please keep in mind + // that these weights are not 100% accurate. + private static void initializePartyResponsePatterns() { + // Democratic Party patterns + Map> democraticPatterns = new HashMap<>(); + democraticPatterns.put(0, createResponseWeights(new double[] { 0.7, 0.1, 0.2, 0.0 })); + democraticPatterns.put(1, createResponseWeights(new double[] { 0.7, 0.1, 0.0, 0.2 })); + democraticPatterns.put(2, createResponseWeights(new double[] { 0.8, 0.1, 0.0, 0.1 })); + democraticPatterns.put(3, createResponseWeights(new double[] { 0.8, 0.1, 0.0, 0.1 })); + democraticPatterns.put(4, createResponseWeights(new double[] { 0.7, 0.1, 0.0, 0.2 })); + democraticPatterns.put(5, createResponseWeights(new double[] { 0.7, 0.2, 0.0, 0.1 })); + democraticPatterns.put(6, createResponseWeights(new double[] { 0.7, 0.1, 0.0, 0.2 })); + partyResponsePatterns.put(0, democraticPatterns); + + // Republican Party patterns + Map> republicanPatterns = new HashMap<>(); + republicanPatterns.put(0, createResponseWeights(new double[] { 0.1, 0.4, 0.4, 0.1 })); + republicanPatterns.put(1, createResponseWeights(new double[] { 0.0, 0.8, 0.2, 0.0 })); + republicanPatterns.put(2, createResponseWeights(new double[] { 0.0, 0.8, 0.2, 0.0 })); + republicanPatterns.put(3, createResponseWeights(new double[] { 0.1, 0.5, 0.4, 0.0 })); + republicanPatterns.put(4, createResponseWeights(new double[] { 0.0, 0.7, 0.3, 0.0 })); + republicanPatterns.put(5, createResponseWeights(new double[] { 0.0, 0.8, 0.2, 0.0 })); + republicanPatterns.put(6, createResponseWeights(new double[] { 0.0, 0.8, 0.1, 0.1 })); + partyResponsePatterns.put(1, republicanPatterns); + + // Libertarian Party patterns + Map> libertarianPatterns = new HashMap<>(); + libertarianPatterns.put(0, createResponseWeights(new double[] { 0.0, 0.2, 0.1, 0.7 })); + libertarianPatterns.put(1, createResponseWeights(new double[] { 0.0, 0.3, 0.7, 0.0 })); + libertarianPatterns.put(2, createResponseWeights(new double[] { 0.0, 0.2, 0.8, 0.0 })); + libertarianPatterns.put(3, createResponseWeights(new double[] { 0.0, 0.1, 0.9, 0.0 })); + libertarianPatterns.put(4, createResponseWeights(new double[] { 0.0, 0.2, 0.8, 0.0 })); + libertarianPatterns.put(5, createResponseWeights(new double[] { 0.0, 0.1, 0.9, 0.0 })); + libertarianPatterns.put(6, createResponseWeights(new double[] { 0.0, 0.1, 0.9, 0.0 })); + partyResponsePatterns.put(2, libertarianPatterns); + + // Green Party patterns + Map> greenPatterns = new HashMap<>(); + greenPatterns.put(0, createResponseWeights(new double[] { 0.4, 0.0, 0.1, 0.5 })); + greenPatterns.put(1, createResponseWeights(new double[] { 0.3, 0.0, 0.0, 0.7 })); + greenPatterns.put(2, createResponseWeights(new double[] { 0.6, 0.0, 0.0, 0.4 })); + greenPatterns.put(3, createResponseWeights(new double[] { 0.4, 0.0, 0.0, 0.6 })); + greenPatterns.put(4, createResponseWeights(new double[] { 0.3, 0.0, 0.0, 0.7 })); + greenPatterns.put(5, createResponseWeights(new double[] { 0.3, 0.0, 0.0, 0.7 })); + greenPatterns.put(6, createResponseWeights(new double[] { 0.2, 0.0, 0.0, 0.8 })); + partyResponsePatterns.put(3, greenPatterns); + + // Initialize partyDataPoints with fictional data points + // to simulate pre-existing training data + partyDataPoints[0] = 100; // Democratic + partyDataPoints[1] = 100; // Republican + partyDataPoints[2] = 50; // Libertarian + partyDataPoints[3] = 50; // Green + } + + // Helper method to create response weights map + private static Map createResponseWeights(double[] weights) { + Map responseWeights = new HashMap<>(); + for (int i = 0; i < weights.length; i++) { + responseWeights.put(String.valueOf(i), weights[i]); + } + return responseWeights; + } + + // Add this new method to save survey responses to a TXT file + private static void saveSurveyToTxt(List userResponses, String predictedParty, double confidence, + String actualParty) { + try { + // Create a filename with timestamp + String filename = "survey_response_" + ".txt"; + + try (PrintWriter writer = new PrintWriter(new FileWriter(filename))) { + writer.println("POLITICAL SURVEY RESPONSE"); + writer.println("========================="); + writer.println(); + + for (int i = 0; i < QUESTIONS.size() - 1; i++) { + SurveyQuestion question = QUESTIONS.get(i); + String answer = question.getOptions()[Integer.parseInt(userResponses.get(i))]; + + writer.println("Question " + (i + 1) + ": " + question.getQuestion()); + writer.println("Answer: " + answer); + writer.println(); + } + + writer.println("PREDICTION RESULTS"); + writer.println("-----------------"); + writer.println("Predicted Party: " + predictedParty + " Party"); + writer.println("Confidence: " + String.format("%.1f%%", confidence * 100)); + writer.println("Actual Party: " + actualParty + " Party"); + writer.println(); + + writer.println("Survey completed successfully!"); + } + + System.out.println("\nSurvey responses have been saved to: " + filename); + + } catch (IOException e) { + System.err.println("Error saving survey responses to file: " + e.getMessage()); + } + } + + private static List conductSurvey() { + List userResponses = new ArrayList<>(); + int questionNum = 0; + + int lastQuestionIndex = QUESTIONS.size() - 1; + + String predictedParty = ""; + double highestConfidence = 0.0; + + System.out.println("Please answer the following questions:"); + + while (questionNum < lastQuestionIndex) { + SurveyQuestion question = QUESTIONS.get(questionNum); + + System.out.println("\nQuestion " + (questionNum + 1) + ": " + question.getQuestion()); + + String[] options = question.getOptions(); + for (int i = 0; i < options.length; i++) { + System.out.println(((char) ('A' + i)) + ". " + options[i]); + } + + System.out.print("\nYour answer (A-" + (char) ('A' + options.length - 1) + "): "); + String userInput = scanner.nextLine().trim().toUpperCase(); + + if (userInput.length() == 1 && userInput.charAt(0) >= 'A' && userInput.charAt(0) < 'A' + options.length) { + int optionIndex = userInput.charAt(0) - 'A'; + userResponses.add(String.valueOf(optionIndex)); + + // After collecting some responses, try to predict party + if (questionNum >= 2) { + double[] partyConfidences = calculatePartyConfidences(userResponses); + + // Find the party with highest confidence + int maxConfidencePartyIndex = 0; + highestConfidence = partyConfidences[0]; + + for (int i = 1; i < partyConfidences.length; i++) { + if (partyConfidences[i] > highestConfidence) { + maxConfidencePartyIndex = i; + highestConfidence = partyConfidences[i]; + } + } + + predictedParty = POLITICAL_PARTIES[maxConfidencePartyIndex]; + + if (highestConfidence >= CONFIDENCE_THRESHOLD) { + System.out.println("\nBased on your answers so far, I predict you might align with the " + + predictedParty + " Party (Confidence: " + + String.format("%.1f%%", highestConfidence * 100) + ")"); + } + } + + questionNum++; + } else { + System.out.println("Invalid input. Please enter a letter between A and " + + (char) ('A' + options.length - 1)); + } + } + + if (!predictedParty.isEmpty()) { + System.out.println("\n=========================================================="); + System.out.println("FINAL PREDICTION: Based on your responses, I predict your"); + System.out.println("political affiliation is " + predictedParty + " Party"); + System.out.println("Confidence: " + String.format("%.1f%%", highestConfidence * 100)); + System.out.println("==========================================================\n"); + } + + SurveyQuestion lastQuestion = QUESTIONS.get(lastQuestionIndex); + System.out.println("Final Question: " + lastQuestion.getQuestion()); + + String[] partyOptions = lastQuestion.getOptions(); + for (int i = 0; i < partyOptions.length; i++) { + System.out.println(((char) ('A' + i)) + ". " + partyOptions[i]); + } + + boolean validInput = false; + while (!validInput) { + System.out.print("\nYour answer (A-" + (char) ('A' + partyOptions.length - 1) + "): "); + String userInput = scanner.nextLine().trim().toUpperCase(); + + if (userInput.length() == 1 && userInput.charAt(0) >= 'A' && userInput.charAt(0) < 'A' + partyOptions.length) { + int optionIndex = userInput.charAt(0) - 'A'; + userResponses.add(String.valueOf(optionIndex)); + validInput = true; + + // We ompare prediction with actual affiliation + String actualParty = partyOptions[optionIndex]; + System.out.println("\nYour actual affiliation: " + actualParty + " Party"); + + if (!predictedParty.isEmpty()) { + if (actualParty.equals(predictedParty)) { + System.out.println("Prediction was CORRECT!"); + } else { + System.out.println("Prediction was incorrect. This data will help improve future predictions."); + } + } + + saveSurveyToTxt(userResponses, predictedParty, highestConfidence, actualParty); + } else { + System.out.println("Invalid input. Please enter a letter between A and " + + (char) ('A' + partyOptions.length - 1)); + } + } + + return userResponses; + } + + // here we calculate confidence scores for each party based on user responses + private static double[] calculatePartyConfidences(List userResponses) { + double[] partyScores = new double[POLITICAL_PARTIES.length]; + + for (int partyIndex = 0; partyIndex < POLITICAL_PARTIES.length; partyIndex++) { + Map> partyPattern = partyResponsePatterns.get(partyIndex); + double totalScore = 0.0; + + for (int questionIndex = 0; questionIndex < userResponses.size(); questionIndex++) { + String response = userResponses.get(questionIndex); + Map questionPatterns = partyPattern.get(questionIndex); + + if (questionPatterns != null && questionPatterns.containsKey(response)) { + double weight = questionPatterns.get(response); + totalScore += weight; + } + } + + partyScores[partyIndex] = totalScore / userResponses.size(); + } + + double sum = 0.0; + for (double score : partyScores) { + sum += score; + } + + if (sum > 0) { + for (int i = 0; i < partyScores.length; i++) { + partyScores[i] /= sum; + } + } + + return partyScores; + } + + // Add new training data based on user responses + private static void addTrainingData(List userResponses) { + if (userResponses.size() != QUESTIONS.size()) { + return; + } + + int actualPartyIndex = Integer.parseInt(userResponses.get(userResponses.size() - 1)); + partyDataPoints[actualPartyIndex]++; + + Map> partyPattern = partyResponsePatterns.get(actualPartyIndex); + + for (int questionIndex = 0; questionIndex < userResponses.size() - 1; questionIndex++) { + String response = userResponses.get(questionIndex); + + Map questionPattern = partyPattern.computeIfAbsent(questionIndex, k -> new HashMap<>()); + + for (int optionIndex = 0; optionIndex < QUESTIONS.get(questionIndex).getOptions().length; optionIndex++) { + String option = String.valueOf(optionIndex); + double currentWeight = questionPattern.getOrDefault(option, 0.0); + + if (option.equals(response)) { + double newWeight = (currentWeight * (partyDataPoints[actualPartyIndex] - 1) + 1.0) / + partyDataPoints[actualPartyIndex]; + questionPattern.put(option, newWeight); + } else { + if (currentWeight > 0) { + double newWeight = (currentWeight * (partyDataPoints[actualPartyIndex] - 1)) / + partyDataPoints[actualPartyIndex]; + questionPattern.put(option, newWeight); + } + } + } + + double sum = 0.0; + for (double weight : questionPattern.values()) { + sum += weight; + } + + if (sum > 0) { + for (String option : questionPattern.keySet()) { + questionPattern.put(option, questionPattern.get(option) / sum); + } + } + } + } + + private static class SurveyQuestion { + private String question; + private String[] options; + + public SurveyQuestion(String question, String[] options) { + this.question = question; + this.options = options; + } + + public String getQuestion() { + return question; + } + + public String[] getOptions() { + return options; + } + } +} diff --git a/ComputerScience311ai/survey_response_.txt b/ComputerScience311ai/survey_response_.txt new file mode 100644 index 0000000..228484a --- /dev/null +++ b/ComputerScience311ai/survey_response_.txt @@ -0,0 +1,31 @@ +POLITICAL SURVEY RESPONSE +========================= + +Question 1: What should the government do to help the poor? +Answer: Nothing, private charity should handle it + +Question 2: What is your view on taxation? +Answer: Tax policies focused on environmental sustainability + +Question 3: What is your stance on healthcare? +Answer: Community-based healthcare systems with government support + +Question 4: What is your view on gun control? +Answer: Gun control with community-based oversight + +Question 5: How should we address climate change? +Answer: Aggressive environmental policies and global cooperation + +Question 6: What should be our approach to foreign policy? +Answer: International cooperation for peace and environmental protection + +Question 7: What is your stance on immigration? +Answer: Humanitarian-focused immigration policies + +PREDICTION RESULTS +----------------- +Predicted Party: Green Party +Confidence: 71.0% +Actual Party: Green Party + +Survey completed successfully! diff --git a/Cube.class b/Cube.class new file mode 100644 index 0000000..7c8091c Binary files /dev/null and b/Cube.class differ diff --git a/Cylinder.class b/Cylinder.class new file mode 100644 index 0000000..4c688bc Binary files /dev/null and b/Cylinder.class differ diff --git a/English104/English 104 - Assignment 1- Expository Essay .docx b/English104/English 104 - Assignment 1- Expository Essay .docx new file mode 100644 index 0000000..8b20027 Binary files /dev/null and b/English104/English 104 - Assignment 1- Expository Essay .docx differ diff --git a/English104/English 104 - Assignment 1- Narrative Essay .docx b/English104/English 104 - Assignment 1- Narrative Essay .docx new file mode 100644 index 0000000..8f7c0d0 Binary files /dev/null and b/English104/English 104 - Assignment 1- Narrative Essay .docx differ diff --git a/English104/English 104 - Assignment 2 - Narrative Essay .docx b/English104/English 104 - Assignment 2 - Narrative Essay .docx new file mode 100644 index 0000000..a196685 Binary files /dev/null and b/English104/English 104 - Assignment 2 - Narrative Essay .docx differ diff --git a/English104/English 104 - Assignment 23 - Argumentative Essay .docx b/English104/English 104 - Assignment 23 - Argumentative Essay .docx new file mode 100644 index 0000000..d8694dd Binary files /dev/null and b/English104/English 104 - Assignment 23 - Argumentative Essay .docx differ diff --git a/English104/English 104 - Assignment 3 - Argumentative Essay .docx b/English104/English 104 - Assignment 3 - Argumentative Essay .docx new file mode 100644 index 0000000..906135a Binary files /dev/null and b/English104/English 104 - Assignment 3 - Argumentative Essay .docx differ diff --git a/Main.class b/Main.class new file mode 100644 index 0000000..3723eb0 Binary files /dev/null and b/Main.class differ diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..86ec641 --- /dev/null +++ b/Main.java @@ -0,0 +1,113 @@ +/* + * in this Java program, the user can calculate the area of a rectangle, + * and the volumes of a cube, cylinder, and sphere. + * The user will be prompt to enter the length and width of a rectangle, + * and then choose a shape to calculate the volume of (cube, cylinder, or sphere). + */ + +import java.util.InputMismatchException; +import java.util.Scanner; + +class Rectangle { + public static double rectangleArea(double length, double width) { + return length * width; + } +} + +class Cube { + public static double cubeVolume(double side) { + return Math.pow(side, 3); + } +} + +class Cylinder { + public static double cylinderVolume(double radius, double height) { + return Math.PI * Math.pow(radius, 2) * height; + } +} + +class Sphere { + public static double sphereVolume(double radius) { + return (4.0 / 3.0) * Math.PI * Math.pow(radius, 3); + } +} +// Main Class + +public class Main { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + try { + // User prompt for the length and width + System.out.println("Rectangle Area"); + System.out.print("Please enter length: "); + double length = scanner.nextDouble(); + + System.out.print("Please enter width: "); + double width = scanner.nextDouble(); + + // making sure that the user put positive numbers otherwise we throw a //warning + + if (length <= 0 || width <= 0) { + System.out.println("WARNING! Length and width must be positive numbers."); + } else { + double area = Rectangle.rectangleArea(length, width); + System.out.println("Rectangle Area: " + area); + } + + // Choose shape for volume calculation + + System.out.println(""); + System.out.println("Volume Calculation"); + System.out.println("Choose a shape to calculate volume:"); + System.out.println("1. Cube"); + System.out.println("2. Cylinder "); + System.out.println("3. Sphere "); + System.out.print("Enter your choice (1-3): "); + int userChoice = scanner.nextInt(); + // Let's give the User the choice of which volume shape they want to calculate. + switch (userChoice) { + case 1: // Cube + System.out.print("Enter side length of cube: "); + double side = scanner.nextDouble(); + if (side <= 0) { + System.out.println("WARNING! Side must be a positive number."); + } else { + double cubeVolume = Cube.cubeVolume(side); + System.out.println("Cube Volume: " + cubeVolume); + } + break; + case 2: // Cylinder + System.out.print("Enter radius of cylinder: "); + double cylinderRadius = scanner.nextDouble(); + System.out.print("Enter height of cylinder: "); + double cylinderHeight = scanner.nextDouble(); + if (cylinderRadius <= 0 || cylinderHeight <= 0) { + System.out.println("WARNING! Radius and height must be positive numbers."); + } else { + double cylinderVolume = Cylinder.cylinderVolume(cylinderRadius, cylinderHeight); + System.out.println("Cylinder Volume: " + cylinderVolume); + } + break; + case 3: // Sphere + System.out.print("Enter radius of sphere: "); + double sphereRadius = scanner.nextDouble(); + if (sphereRadius <= 0) { + System.out.println("WARNING! Radius must be a positive number."); + } else { + double sphereVolume = Sphere.sphereVolume(sphereRadius); + System.out.println("Sphere Volume: " + sphereVolume); + } + break; + default: + System.out.println("Invalid choice."); + } + + } catch (InputMismatchException e) { + System.out.println("WARNING! Please enter valid numeric values."); + } finally { + scanner.close(); + } + } +} diff --git a/PoliticalScience102/Political Science 102 - Assignment .docx b/PoliticalScience102/Political Science 102 - Assignment .docx new file mode 100644 index 0000000..db1a8cd Binary files /dev/null and b/PoliticalScience102/Political Science 102 - Assignment .docx differ diff --git a/Rectangle.class b/Rectangle.class new file mode 100644 index 0000000..6844284 Binary files /dev/null and b/Rectangle.class differ diff --git a/Sphere.class b/Sphere.class new file mode 100644 index 0000000..5037ce6 Binary files /dev/null and b/Sphere.class differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..0b320d6 --- /dev/null +++ b/index.html @@ -0,0 +1,42 @@ + + + + + + + Document + + + +

Drag and Drop Example

+

Drag the image between the boxes

+
+ +
+
+ + + \ No newline at end of file diff --git a/study.com.iml b/study.com.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/study.com.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file