Lab7
This commit is contained in:
parent
ce1015fdbe
commit
466e438eee
2
.gitignore
vendored
2
.gitignore
vendored
@ -115,3 +115,5 @@
|
|||||||
/Semester 2/Assignments/MP4_CalebFontenot/target/
|
/Semester 2/Assignments/MP4_CalebFontenot/target/
|
||||||
/Semester 2/Assignments/Exceptions/target/
|
/Semester 2/Assignments/Exceptions/target/
|
||||||
/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/target/
|
/Semester 2/Assignments/lab6-Exceptions_CalebFontenot/target/
|
||||||
|
/Semester 2/Assignments/fileClassTest/target/
|
||||||
|
/Semester 2/Assignments/lab7_CalebFontenot/target/
|
||||||
|
55
Semester 2/Assignments/fileClassTest/nbactions.xml
Normal file
55
Semester 2/Assignments/fileClassTest/nbactions.xml
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<actions>
|
||||||
|
<action>
|
||||||
|
<actionName>run</actionName>
|
||||||
|
<packagings>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
</packagings>
|
||||||
|
<goals>
|
||||||
|
<goal>process-classes</goal>
|
||||||
|
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
|
||||||
|
</goals>
|
||||||
|
<properties>
|
||||||
|
<exec.vmArgs>-ea</exec.vmArgs>
|
||||||
|
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||||
|
<exec.appArgs></exec.appArgs>
|
||||||
|
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||||
|
<exec.executable>java</exec.executable>
|
||||||
|
</properties>
|
||||||
|
</action>
|
||||||
|
<action>
|
||||||
|
<actionName>debug</actionName>
|
||||||
|
<packagings>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
</packagings>
|
||||||
|
<goals>
|
||||||
|
<goal>process-classes</goal>
|
||||||
|
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
|
||||||
|
</goals>
|
||||||
|
<properties>
|
||||||
|
<exec.vmArgs>-ea -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
|
||||||
|
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||||
|
<exec.appArgs></exec.appArgs>
|
||||||
|
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||||
|
<exec.executable>java</exec.executable>
|
||||||
|
<jpda.listen>true</jpda.listen>
|
||||||
|
</properties>
|
||||||
|
</action>
|
||||||
|
<action>
|
||||||
|
<actionName>profile</actionName>
|
||||||
|
<packagings>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
</packagings>
|
||||||
|
<goals>
|
||||||
|
<goal>process-classes</goal>
|
||||||
|
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
|
||||||
|
</goals>
|
||||||
|
<properties>
|
||||||
|
<exec.vmArgs>-ea</exec.vmArgs>
|
||||||
|
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
|
||||||
|
<exec.mainClass>${packageClassName}</exec.mainClass>
|
||||||
|
<exec.executable>java</exec.executable>
|
||||||
|
<exec.appArgs></exec.appArgs>
|
||||||
|
</properties>
|
||||||
|
</action>
|
||||||
|
</actions>
|
15
Semester 2/Assignments/fileClassTest/pom.xml
Normal file
15
Semester 2/Assignments/fileClassTest/pom.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.calebfontenot</groupId>
|
||||||
|
<artifactId>fileClassTest</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<exec.mainClass>com.calebfontenot.fileclasstest.FileClassTest</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
2
Semester 2/Assignments/fileClassTest/scores.txt
Normal file
2
Semester 2/Assignments/fileClassTest/scores.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
John T Smith 90
|
||||||
|
Eric K Jones 85
|
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,17 +19,12 @@ public class ReadFileFromWeb1 {
|
|||||||
String URLString;
|
String URLString;
|
||||||
try {
|
try {
|
||||||
URLinput = new Scanner(System.in).nextLine();
|
URLinput = new Scanner(System.in).nextLine();
|
||||||
URLinput = "";
|
//URLinput = "";
|
||||||
if (URLinput.isEmpty()) {
|
if (URLinput.isEmpty()) {
|
||||||
URLString = "https://calebfontenot.com";
|
URLString = "https://calebfontenot.com";
|
||||||
} else {
|
} else {
|
||||||
URLString = URLinput;
|
URLString = URLinput;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println(ex);
|
|
||||||
URLString = "https://calebfontenot.com";
|
|
||||||
}
|
|
||||||
|
|
||||||
java.net.URL url = new java.net.URL(URLString);
|
java.net.URL url = new java.net.URL(URLString);
|
||||||
int count = 0, divCount = 0, pCount = 0;
|
int count = 0, divCount = 0, pCount = 0;
|
||||||
|
14
Semester 2/Assignments/lab7_CalebFontenot/pom.xml
Normal file
14
Semester 2/Assignments/lab7_CalebFontenot/pom.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.calebfontenot</groupId>
|
||||||
|
<artifactId>lab7_CalebFontenot</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<exec.mainClass>com.calebfontenot.lab7_calebfontenot.Lab7_CalebFontenot</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
</project>
|
Binary file not shown.
@ -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!");
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user