diff --git a/.gitignore b/.gitignore index 2e115e5..0b5c3ba 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,5 @@ /Semester 2/Assignments/MP4_CalebFontenot/target/ /Semester 2/Assignments/Exceptions/target/ /Semester 2/Assignments/lab6-Exceptions_CalebFontenot/target/ +/Semester 2/Assignments/fileClassTest/target/ +/Semester 2/Assignments/lab7_CalebFontenot/target/ diff --git a/Semester 2/Assignments/fileClassTest/nbactions.xml b/Semester 2/Assignments/fileClassTest/nbactions.xml new file mode 100644 index 0000000..2567a0d --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/nbactions.xml @@ -0,0 +1,55 @@ + + + + run + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.0.0:exec + + + -ea + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + ${packageClassName} + java + + + + debug + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.0.0:exec + + + -ea -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + + ${packageClassName} + java + true + + + + profile + + jar + + + process-classes + org.codehaus.mojo:exec-maven-plugin:3.0.0:exec + + + -ea + ${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs} + ${packageClassName} + java + + + + diff --git a/Semester 2/Assignments/fileClassTest/pom.xml b/Semester 2/Assignments/fileClassTest/pom.xml new file mode 100644 index 0000000..ae03436 --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.calebfontenot + fileClassTest + 1.0-SNAPSHOT + jar + + UTF-8 + 17 + 17 + com.calebfontenot.fileclasstest.FileClassTest + + + \ No newline at end of file diff --git a/Semester 2/Assignments/fileClassTest/scores.txt b/Semester 2/Assignments/fileClassTest/scores.txt new file mode 100644 index 0000000..a225378 --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/scores.txt @@ -0,0 +1,2 @@ +John T Smith 90 +Eric K Jones 85 diff --git a/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/FileClassTest.java b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/FileClassTest.java new file mode 100644 index 0000000..597f8fd --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/FileClassTest.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.calebfontenot.fileclasstest; + +/** + * + * @author caleb + */ +public class FileClassTest { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/ReadData2.java b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/ReadData2.java new file mode 100644 index 0000000..0aaa64b --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/ReadData2.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 com.calebfontenot.fileclasstest; + +/** + * + * @author caleb + */ +import java.util.Scanner; + +public class ReadData2 { + + public static void main(String[] args) throws Exception + { + // Create a File instance + java.io.File file = new java.io.File("scores.txt"); + try { + // Create a Scanner for the file + try (Scanner input = new Scanner(file)) { + // Read data from a file + while (input.hasNext()) { + String firstName = input.next(); + String mi = input.next(); + String lastName = input.next(); + int score = input.nextInt(); + System.out.println( + firstName + " " + mi + " " + lastName + " " + score); + } + } + } catch (Exception e) { + + } + // Close the file + //input.close(); + } +} diff --git a/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/TestFileClass.java b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/TestFileClass.java new file mode 100644 index 0000000..512f920 --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/TestFileClass.java @@ -0,0 +1,44 @@ +/* + * 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.fileclasstest; + +import java.util.GregorianCalendar; + +/** + * + * @author caleb + */ +public class TestFileClass { + + public static void main(String[] args) throws ClassNotFoundException, InstantiationException + { + ClassLoader loader = ClassLoader.getSystemClassLoader(); + loader.setDefaultAssertionStatus(true); + Class c = loader.loadClass("Test"); + Test myObj = (Test) c.newInstance(); + } +} + +class Test { + + public static void main(String[] args) + { + + java.io.File file = new java.io.File("image/us.gif"); + System.out.println("Does it exist? " + file.exists()); + System.out.println("The file has " + file.length() + " bytes"); + System.out.println("Can it be read? " + file.canRead()); + System.out.println("Can it be written? " + file.canWrite()); + System.out.println("Is it a directory? " + file.isDirectory()); + System.out.println("Is it a file? " + file.isFile()); + System.out.println("Is it absolute? " + file.isAbsolute()); + System.out.println("Is it hidden? " + file.isHidden()); + System.out.println("Absolute path is " + + file.getAbsolutePath()); + System.out.println("Last modified on " + + new java.util.Date(file.lastModified())); + assert (0 == 1); + } +} diff --git a/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/WriteDataWithAutoClose.java b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/WriteDataWithAutoClose.java new file mode 100644 index 0000000..736c6e4 --- /dev/null +++ b/Semester 2/Assignments/fileClassTest/src/main/java/com/calebfontenot/fileclasstest/WriteDataWithAutoClose.java @@ -0,0 +1,31 @@ +/* + * 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.fileclasstest; + +/** + * + * @author caleb + */ +public class WriteDataWithAutoClose { + + public static void main(String[] args) throws Exception + { + java.io.File file = new java.io.File("scores.txt"); + if (file.exists()) { + System.out.println("File already exists"); + System.exit(0); + } + + try ( + // Create a file + java.io.PrintWriter output = new java.io.PrintWriter(file);) { + // Write formatted output to the file + output.print("John T Smith "); + output.println(90); + output.print("Eric K Jones "); + output.println(85); + } + } +} diff --git a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromWeb1.java b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromWeb1.java index 1e9ca42..fc1c753 100644 --- a/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromWeb1.java +++ b/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/src/main/java/com/mycompany/lab6/exceptions_calebfontenot/ReadFileFromWeb1.java @@ -19,17 +19,12 @@ public class ReadFileFromWeb1 { String URLString; try { URLinput = new Scanner(System.in).nextLine(); - URLinput = ""; + //URLinput = ""; if (URLinput.isEmpty()) { URLString = "https://calebfontenot.com"; } else { URLString = URLinput; } - try { - } catch (Exception ex) { - System.out.println(ex); - URLString = "https://calebfontenot.com"; - } java.net.URL url = new java.net.URL(URLString); int count = 0, divCount = 0, pCount = 0; diff --git a/Semester 2/Assignments/lab7_CalebFontenot/pom.xml b/Semester 2/Assignments/lab7_CalebFontenot/pom.xml new file mode 100644 index 0000000..fb59ea7 --- /dev/null +++ b/Semester 2/Assignments/lab7_CalebFontenot/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.calebfontenot + lab7_CalebFontenot + 1.0-SNAPSHOT + jar + + UTF-8 + 17 + 17 + com.calebfontenot.lab7_calebfontenot.Lab7_CalebFontenot + + \ No newline at end of file diff --git a/Semester 2/Assignments/lab7_CalebFontenot/precticeExecptionNFiles.pdf b/Semester 2/Assignments/lab7_CalebFontenot/precticeExecptionNFiles.pdf new file mode 100644 index 0000000..a4b5dfb Binary files /dev/null and b/Semester 2/Assignments/lab7_CalebFontenot/precticeExecptionNFiles.pdf differ diff --git a/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/Lab7_CalebFontenot.java b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/Lab7_CalebFontenot.java new file mode 100644 index 0000000..a21dfa5 --- /dev/null +++ b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/Lab7_CalebFontenot.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package com.calebfontenot.lab7_calebfontenot; + +/** + * + * @author caleb + */ +public class Lab7_CalebFontenot { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/OOM.java b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/OOM.java new file mode 100644 index 0000000..d8ca371 --- /dev/null +++ b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/OOM.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.lab7_calebfontenot; + +/** + * + * @author caleb + */ +public class OOM { + public static void main(String[] args) + { + try { + Integer[][] oomArray = new Integer[20000][20000]; + for (int i = 0; i < oomArray.length; ++i ) { + for (int j = 0; j < oomArray.length; ++j ) { + oomArray[i][j] = i * j; + //System.out.println(oomArray[i][j]); + } + } + } catch (OutOfMemoryError ex) { + System.out.println("Out of memory! " + ex); + } + } +} diff --git a/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/removeAllOccurances.java b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/removeAllOccurances.java new file mode 100644 index 0000000..0544356 --- /dev/null +++ b/Semester 2/Assignments/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/removeAllOccurances.java @@ -0,0 +1,39 @@ +/* + * 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.lab7_calebfontenot; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class removeAllOccurances { + public static void main(String[] args) throws FileNotFoundException + { + Scanner input = new Scanner(System.in); + System.out.print("Enter a path to a file: "); + String sourcePath = input.nextLine(); + System.out.print("Replace what with what? (ex. If you want to replace John with Mary, type: \'John Mary\'): "); + String source = input.next(); + String target = input.next(); + System.out.print("Enter the output file path: "); + String destinationPath = input.nextLine(); + + File sourceFile = new File(sourcePath); + File destinationFile = new File(destinationPath); + String[] fileContents = new String[(int) sourceFile.length()]; + try (Scanner sourceScanner = new Scanner(sourceFile)) { + for (int i = 0; i < sourceFile.length(); ++i) { + fileContents[i] = sourceScanner.nextLine(); + } + } + for (int i = 0; i < fileContents.length; ++i) { + System.out.println(fileContents[i]); + } + } +}