Skip to content

Commit 4f84329

Browse files
Completed Unit 2 Assignment Requirements
1 parent cdead6a commit 4f84329

File tree

15 files changed

+260
-0
lines changed

15 files changed

+260
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix a error in sudo code
10+
* See Chapter 11 Find the Error Question 1.
11+
*/
12+
import java.io.File;
13+
import java.io.FileNotFoundException;
14+
import java.util.Scanner;
15+
16+
public class ErrorOne { // Created class to store error - Not apart of error example
17+
void fixErrorOne() { // Created method to store error - Not apart of error example
18+
try // Placed Try block before catch block
19+
{
20+
File file = new File("MyFile.txt");
21+
Scanner inputFile = new Scanner(file);
22+
}
23+
catch (FileNotFoundException e)
24+
{
25+
System.out.println("File not found.");
26+
}
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix a error in sudo code
10+
* See Chapter 11 Find the Error Question 3.
11+
*/
12+
public class ErrorThree { // Created class to store sudo code
13+
public void fixErrorThree() { // Created method to store sudo code
14+
CharSequence str = null; // Initialized for line 6
15+
try
16+
{
17+
int number = Integer.parseInt((String) str); // Casted to String
18+
}
19+
catch (NumberFormatException e) // Reordered due to ranking of specialized exceptions
20+
{
21+
System.out.println(str + " is not a number.");
22+
}
23+
catch (IllegalArgumentException e) // Reordered due to ranking of specialized exceptions
24+
{
25+
System.out.println("Bad number format.");
26+
}
27+
catch (Exception e) // Reordered due to ranking of specialized exceptions
28+
{
29+
System.out.println(e.getMessage());
30+
}
31+
}
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix a error in sudo code
10+
* See Chapter 11 Find the Error Question 2.
11+
*/
12+
import java.io.File;
13+
import java.util.InputMismatchException;
14+
import java.util.Scanner;
15+
16+
public class ErrorTwo { // Created class to store error question - Not apart of sudo code
17+
public void fixErrorTwo() {
18+
// Added declarations to remove errors
19+
File file;
20+
Scanner inputFile = null;
21+
int input;
22+
23+
try
24+
{
25+
input = inputFile.nextInt();
26+
}
27+
catch (InputMismatchException e)
28+
{
29+
System.out.println(e.getMessage());
30+
}
31+
finally // Moved below catch block
32+
{
33+
inputFile.close();
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to answer the question "what will this sudo code output when ran?"
10+
* See Chapter 11 Algorithm Workbench Question 1.
11+
*/
12+
public class ExceptionTest {
13+
public static void main(String[] args) {
14+
int number;
15+
String str;
16+
17+
try
18+
{
19+
str = "xyz";
20+
number = Integer.parseInt(str);
21+
System.out.println("A");
22+
}
23+
catch(NumberFormatException e)
24+
{
25+
System.out.println("B");
26+
}
27+
catch(IllegalArgumentException e)
28+
{
29+
System.out.println("C");
30+
}
31+
System.out.println("D");
32+
}
33+
/*
34+
* The program will output:
35+
* B
36+
* D
37+
* */
38+
}
11.4 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to answer the question "what will this sudo code output when ran?"
10+
* See Chapter 11 Algorithm Workbench Question 2.
11+
*/
12+
public class ExceptionTest {
13+
public static void main(String[] args)
14+
{
15+
int number;
16+
String str;
17+
try
18+
{
19+
str = "xyz";
20+
number = Integer.parseInt(str);
21+
System.out.println("A");
22+
}
23+
catch(NumberFormatException e)
24+
{
25+
System.out.println("B");
26+
}
27+
catch(IllegalArgumentException e)
28+
{
29+
System.out.println("C");
30+
}
31+
finally
32+
{
33+
System.out.println("D");
34+
}
35+
System.out.println("E");
36+
}
37+
/*
38+
* The program will output:
39+
* B
40+
* D
41+
* E
42+
* */
43+
}
12.3 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/17/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This class file was written to show a method of searching an array for a specified value.
10+
* See Chapter 11 Algorithm Workbench Question 3.
11+
*/
12+
public class AlgorithmWorkbenchThree {
13+
public static int numericArraySearch(int[] array, int value) throws Exception {
14+
int i = 0; // for loop
15+
int specifiedValue = -1; // variable for the value is found
16+
boolean found = false; // flag for showing result
17+
18+
while (!found && i < array.length) { // search array
19+
if (array[i] == value) {
20+
found = true;
21+
specifiedValue = i;
22+
}
23+
i++;
24+
}
25+
26+
if (specifiedValue == -1)
27+
throw new Exception("Element not found.");
28+
else
29+
return specifiedValue;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
^rs}*s}*wƒ*sxz~*psvo
2+
S*kw*Uƒvo*Wk|~sx
3+
S*yvn*vsuo*~y*no€ovyz*pvv*pvonqon*kzzvsmk~syx}*yxo*nkƒ*py|*k*vs€sxq
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is my input file
2+
I am Kyle Martin
3+
I would like to develop full fledged applications one day for a living

0 commit comments

Comments
 (0)