Initial commit

master
Noah Pederson 6 years ago
parent 40092ab92a
commit 4fd94efc85
  1. 2
      .idea/modules.xml
  2. 11
      Chapter11/Chapter11.iml
  3. 54
      Chapter11/src/Exceptions.java
  4. 11
      Chapter14/Chapter14.iml
  5. 36
      Chapter14/src/LetterCounter.java
  6. 21
      Chapter14/src/PhoneTokenizor.java

@ -3,6 +3,8 @@
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Chapter10/Chapter10.iml" filepath="$PROJECT_DIR$/Chapter10/Chapter10.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter11/Chapter11.iml" filepath="$PROJECT_DIR$/Chapter11/Chapter11.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter14/Chapter14.iml" filepath="$PROJECT_DIR$/Chapter14/Chapter14.iml" />
<module fileurl="file://$PROJECT_DIR$/Chapter9/Chapter9.iml" filepath="$PROJECT_DIR$/Chapter9/Chapter9.iml" />
<module fileurl="file://$PROJECT_DIR$/School.iml" filepath="$PROJECT_DIR$/School.iml" />
</modules>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,54 @@
import java.util.Scanner;
/**
* Created by noah on 6/2/2016.
*/
public class Exceptions {
public static void main(String... args) {
Exceptions e = new Exceptions();
e.Run();
}
private void Run() {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter the letter n: ");
String s = scanner.nextLine();
if (s.isEmpty())
s = null;
try {
if (!s.equals("n")) {
throw new NotNException("NOT n!");
}
if (!s.equalsIgnoreCase("N")) {
throw new OtherException("NOT N!");
}
} catch (NotNException e) {
System.out.println("That's not an 'n'.");
Run();
} catch (OtherException oe) {
System.out.println("That's not an n, but that's alright.");
} catch (NullPointerException np) {
System.out.println("You didn't enter anything");
}
System.out.println("Done");
}
//Inner classes yay!
private class NotNException extends Exception {
public NotNException(String s) {
super(s);
}
}
private class OtherException extends Exception {
public OtherException(String message) {
super(message);
}
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,36 @@
import java.util.Scanner;
/**
* Created by noah on 6/2/2016.
*/
public class LetterCounter {
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter a string: ");
String input = scanner.nextLine();
input = input.toUpperCase();
int[] count = new int[26];
//loops through all characters using ASCII (starting at 65)
for (int ascii = 65; ascii < 90; ascii++) {
int i = 0;
do {
char c = (char) ascii;
if (i == 0) {
i = input.indexOf(c, i);
} else {
i = input.indexOf(c, i + 1);
}
if (i == 0)
i++;
if (i > -1)
count[ascii - 65]++;
} while (i > -1);
}
for (int i = 0; i < 26; i++) {
System.out.format("%5c%5d\n", (char) i + 65, count[i]);
}
}
}

@ -0,0 +1,21 @@
/**
* Created by noah on 6/2/2016.
*/
public class PhoneTokenizor {
public static void main(String... args) {
String testPhoneNumber = "(555) 555-5555";
String[] split = testPhoneNumber.split("[)]");
String areaCode = split[0].substring(1); //Seen as I can only use .split() I can't use .find() to select the first instance of numbers [1-9] to make this easier
String[] secondSplit = split[1].split("[-]");
String first3 = secondSplit[0].substring(1);
String last4 = secondSplit[1];
String phoneNumber = first3 + last4;
System.out.println("Area code: " + areaCode);
System.out.println("Phone number: " + phoneNumber);
System.out.println("Done");
}
}
Loading…
Cancel
Save