Exceptions

master
Chloe Fontenot 🏳️‍⚧️ 2023-03-23 11:56:53 +07:00
parent fb70cf62b6
commit ce1015fdbe
4 changed files with 148 additions and 22 deletions

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
</properties>
</project-shared-configuration>

@ -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>-enableassertions</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>-enableassertions -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>-enableassertions</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>

@ -11,20 +11,29 @@ import java.util.Scanner;
* @author caleb
*/
public class ReadFileFromWeb1 {
public static void main(String[] args) {
public static void main(String[] args)
{
System.out.print("Enter a URL (defaults to \"https://calebfontenot.com\"): ");
String URLinput = new Scanner(System.in).nextLine();
String URLinput;
String URLString;
try {
URLinput = new Scanner(System.in).nextLine();
URLinput = "";
if (URLinput.isEmpty()) {
URLString = "https://calebfontenot.com";
}
else {
} 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;
String text ="";
String text = "";
Scanner input = new Scanner(url.openStream());
while (input.hasNext()) {
String line = input.nextLine();
@ -44,8 +53,7 @@ public class ReadFileFromWeb1 {
System.out.println(text);
} catch (java.net.MalformedURLException ex) {
System.out.println("Invalid URL");
}
catch (java.io.IOException ex) {
} catch (java.io.IOException ex) {
System.out.println("IO Errors!");
}
}

@ -11,31 +11,76 @@ import java.util.Scanner;
* @author caleb
*/
public class ToDecimal {
public static int hexToDecimal(String hex) {
int decimalValue =0;
public static int hexToDecimal(String hex)
{
int decimalValue = 0;
for (int i = 0; i < hex.length(); ++i) {
char hexChar = hex.charAt(i);
decimalValue = decimalValue * 16 + hexCharToDecimal(hexChar);
}
return decimalValue;
}
public static int hexCharToDecimal(char ch) {
public static int hexCharToDecimal(char ch)
{
ch = Character.toUpperCase(ch);
if (ch >= 'A' && ch <= 'F') {
return 10 + ch - 'A';
} else if (ch >= '0' && ch <= '9'){ // ch is '0', '1', or '9'
} else if (ch >= '0' && ch <= '9') { // ch is '0', '1', or '9'
return ch - '0';
} else {
throw new NumberFormatException("Invalid hex character");
}
}
public static void main(String[] args) {
/**
*
* @param binaryString the binary number to convert to decimal
* @return decimal number
* @throws NumberFormatException
* @throws NullPointerException
*/
public static int binToDecimal(String binaryString) throws NumberFormatException, NullPointerException
{
int returnInt = 0, binary = 1;
// Validate number first
if (binaryString == null) {
throw new NullPointerException("string is null");
}
for (int i = 0; i < binaryString.length() - 1; ++i) {
if (binaryString.charAt(i) != '0' && binaryString.charAt(i) != '1') {
throw new NumberFormatException(binaryString + " is not a binary number!");
}
}
binaryString = binaryString.trim();
for (int i = binaryString.length() - 1; i >= 0; --i) {
//System.out.println("bin" + binaryString.charAt(i));
if (binaryString.charAt(i) == '1') {
//System.out.println("Adding " + binary);
returnInt += binary;
}
binary *= 2;
//System.out.println(binary);
}
return returnInt;
}
public static void main(String[] args)
{
try {
binToDecimal("Jeff Bezos");
} catch (NumberFormatException ex) {
System.out.println(ex);
System.out.println("Binary number validation works!");
}
System.out.println(binToDecimal("1010"));
Scanner input = new Scanner(System.in);
System.out.print("Enter a hex number or q/Q to quit: ");
String hex = input.nextLine();
while ("q".equals(hex.toLowerCase()) == false) {
System.out.println("The decimal value for hex number " + hex + " is " + hexToDecimal(hex.toUpperCase()));
System.out.print("Emter a hex number: ");
System.out.print("Enter a hex number: ");
hex = input.nextLine();
}