1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Main {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void main(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {
System.System.System.out.println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have "
+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");
System.System.System.out.println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything "
+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "
+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");
System.System.System.out.println();.println();.println();.println();.println();.println();
System.System.System.out.println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number "
+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "
+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");
System.System.System.out.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");
printMainMenu();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void printMainMenu() {
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter "
+ "it");+ "it");+ "it");+ "it");+ "it");+ "it");+ "it");+ "it");
System.System.System.out.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");
System.System.System.out.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");
System.System.System.out.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");
System.System.System.out.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");
System.System.System.out.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");
System.System.System.out.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");
System.System.System.out.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");
System.System.System.out.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");
System.System.System.out.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");
while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {
try {try {try {try {
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
Arithmetic.Arithmetic.Arithmetic.arithmeticMain();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
FlowControl.FlowControl.FlowControl.flowControlMain();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
Loops.Loops.Loops.loopsMain();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
Methods.Methods.Methods.methodsMain();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Main.java
1.1 of 4 2014.12.04 18:55:26
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
Operators.Operators.Operators.operatorsMain();
} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {
Variables.Variables.Variables.variablesMain();
} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {
IfElseStatements.IfElseStatements.IfElseStatements.ifElseMain();
} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {
Strings.Strings.Strings.stringMain();
} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {
System.System.System.exit(0);
}}
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");
System.System.System.out.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");
System.System.System.out.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");
System.System.System.out.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");
System.System.System.out.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");
System.System.System.out.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");
System.System.System.out.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");
System.System.System.out.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");
System.System.System.out.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");
System.System.System.out.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Main.java
2.1 of 4 2014.12.04 18:55:26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Arithmetic {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void arithmetic(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
arithmeticMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void arithmeticMain() {
//Variables are initiated//Variables are initiated
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");
System.System.System.out.println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's "
+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");
//This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read
System.System.System.out.println();.println();.println();.println();.println();
//User is asked to choose an example to run//User is asked to choose an example to run
System.System.System.out.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");
System.System.System.out.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");
System.System.System.out.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");
System.System.System.out.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");
System.System.System.out.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");
System.System.System.out.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");
System.System.System.out.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");
System.System.System.out.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
method if the user inputs an incorrect value.method if the user inputs an incorrect value.
*/
while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
/* User is given the choice of multiple methods that involve/* User is given the choice of multiple methods that involve/* User is given the choice of multiple methods that involve
ArithmenticsArithmentics
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
addition();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
subtraction();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
multiplication();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
division();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
modulus();
} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java
1.1 of 18 2014.12.04 18:55:22
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {
Main.Main.Main.printMainMenu();
} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {
System.System.System.exit(0);
}}
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
arithmeticMain();
/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable
and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints
the method choicesthe method choices
*/*/
} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read//read
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");
System.System.System.out.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");
System.System.System.out.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");
System.System.System.out.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");
System.System.System.out.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");
System.System.System.out.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");
System.System.System.out.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");
System.System.System.out.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void addition() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
int sum;int sum;int sum;int sum;int sum;
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");
System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;
System.System.System.out.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);
//Sets successAddition to true so while loop ends//Sets successAddition to true so while loop ends
successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java
2.1 of 18 2014.12.04 18:55:22
successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void subtraction() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
int result;int result;int result;int result;int result;
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");
System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;
System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);
//Sets successSubtraction to true so while loop ends//Sets successSubtraction to true so while loop ends
successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void multiplication() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
int result;int result;int result;int result;int result;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java
3.1 of 18 2014.12.04 18:55:22
int result;int result;int result;int result;int result;
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");
System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;
System.System.System.out.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);
//Sets successMultiplication to true so while loop ends//Sets successMultiplication to true so while loop ends
successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void division() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initiated//Variables are initiated
int result;int result;int result;int result;int result;
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");
System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;
System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);
//Sets successDivision to true so while loop ends//Sets successDivision to true so while loop ends
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java
4.1 of 18 2014.12.04 18:55:22
//Sets successDivision to true so while loop ends//Sets successDivision to true so while loop ends
successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void modulus() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initiated//Variables are initiated
int result;int result;int result;int result;int result;
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");
System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;
System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);
//Sets successModulus to true so while loop ends//Sets successModulus to true so while loop ends
successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java
5.1 of 18 2014.12.04 18:55:22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class FlowControl {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void flowControl(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
flowControlMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void flowControlMain() {
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");
System.System.System.out.println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have "
+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");
System.System.System.out.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");
System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");
System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.
*/*/
while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
/* User is given the choice of different methods that/* User is given the choice of different methods that
* explain how flow control is handled in Java.* explain how flow control is handled in Java.
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
sleepExample();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
Main.Main.Main.printMainMenu();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
System.System.System.exit(0);
}}
//Sets success to true so while loop ends//Sets success to true so while loop ends
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
flowControlMain();
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the
*example choices.*example choices.
*/*/
} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java
1.1 of 6 2014.12.04 18:55:24
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");
System.System.System.out.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");
System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");
System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
//Method uses boolean to determine whether the user can sleep in or not.//Method uses boolean to determine whether the user can sleep in or not.
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sleepExample() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
//User friendly explaination//User friendly explaination
System.System.System.out.println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can "
+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "
+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");
//User is asked whether today is a weekday or not.//User is asked whether today is a weekday or not.
System.System.System.out.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");
boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();
//User is asked whether he or she is on vacation.//User is asked whether he or she is on vacation.
System.System.System.out.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");
boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();
System.System.System.out.println();.println();.println();.println();.println();
//If true, user can sleep in.//If true, user can sleep in.
if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {
System.System.System.out.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");
System.System.System.out.println();.println();.println();.println();.println();
//If false, user cannot sleep in//If false, user cannot sleep in
} else {} else {} else {} else {} else {} else {
System.System.System.out.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");
System.System.System.out.println();.println();.println();.println();.println();
}}
//Sets successSE to true so while loop ends//Sets successSE to true so while loop ends
successSE = true;successSE = true;successSE = true;successSE = true;successSE = true;successSE = true;successSE = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java
2.1 of 6 2014.12.04 18:55:24
102
103
104
105
106
107
108
109
110
111
112
113
114
} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java
3.1 of 6 2014.12.04 18:55:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Loops {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void loops(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
loopsMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void loopsMain(){
//Variables are initiated//Variables are initiated
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");
System.System.System.out.println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a "
+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "
+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "
+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");
System.System.System.out.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");
System.System.System.out.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");
System.System.System.out.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
/*While loop is used to allow the user to re-enter the value for a/*While loop is used to allow the user to re-enter the value for a/*While loop is used to allow the user to re-enter the value for a
method if the user inputs an incorrect valuemethod if the user inputs an incorrect value
*/
while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try{try{try{
/*User is given the choice of multiple methods that involve/*User is given the choice of multiple methods that involve
loopsloops
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
forLoop();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
whileLoop();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
doWhileLoop();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
Main.Main.Main.printMainMenu();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
System.System.System.exit(0);
}}
//Sets successLoopsMain to true so while loop ends//Sets successLoopsMain to true so while loop ends
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java
1.1 of 10 2014.12.04 18:55:26
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//Sets successLoopsMain to true so while loop ends//Sets successLoopsMain to true so while loop ends
successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;
loopsMain();
/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable
and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints
the method choicesthe method choices
*/*/
}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");
System.System.System.out.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");
System.System.System.out.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");
System.System.System.out.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void forLoop() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables initiated//Variables initiated
int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;
Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.in);
boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;
while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {
try {try {try {try {
System.System.System.out.println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show "
+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");
System.System.System.out.println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the "
+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "
+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "
+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");
System.System.System.out.println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be "
+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "
+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");
System.System.System.out.println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit "
+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "
+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "
+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");
System.System.System.out.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");
lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();
System.System.System.out.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");
hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();
//For loop initiated//For loop initiated
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java
2.1 of 10 2014.12.04 18:55:26
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//For loop initiated//For loop initiated
for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {
result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;
}}
System.System.System.out.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);
//Sets successForLoop to true so while loop ends//Sets successForLoop to true so while loop ends
successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {
System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");
System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void whileLoop() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables initiated//Variables initiated
Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.in);
boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;
while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {
try {try {try {try {
System.System.System.out.println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For "
+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "
+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");
System.System.System.out.println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount "
+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "
+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");
int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();
System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");
while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {
System.System.System.out.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");
money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;
}}
//Sets successWhileLoop to true so while loop ends//Sets successWhileLoop to true so while loop ends
successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {
System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");
System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java
3.1 of 10 2014.12.04 18:55:26
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void doWhileLoop() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initiated//Variables are initiated
int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;
Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.in);
boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;
while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {
try {try {try {try {
System.System.System.out.println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first "
+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "
+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");
System.System.System.out.println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering "
+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");
System.System.System.out.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");
do {do {do {do {
n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();
if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {
System.System.System.out.println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. "
+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");
} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {
System.System.System.out.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");
//Tries is set to 2 to terminate loop early since pin//Tries is set to 2 to terminate loop early since pin
//is correct//is correct
tries = 2;tries = 2;tries = 2;tries = 2;tries = 2;tries = 2;tries = 2;
} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {
System.System.System.out.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");
}}
tries++;tries++;tries++;tries++;
} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);
//Sets successDoWhileLoop to true so while loop ends//Sets successDoWhileLoop to true so while loop ends
successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {
System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");
System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
password.next();password.next();password.next();password.next();password.next();password.next();password.next();
}}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java
4.1 of 10 2014.12.04 18:55:26
204
205
206
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java
5.1 of 10 2014.12.04 18:55:26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Methods {
public static doublepublic static doublepublic static doublepublic static doublepublic static doublepublic static doublepublic static double number, answer;
//Method to calculate square root initiated//Method to calculate square root initiated
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void calculateSquare(double number){(double number){(double number){(double number){(double number){(double number){
double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.sqrt(number);
System.System.System.out.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot);
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void methods(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
methodsMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void methodsMain(){
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");
System.System.System.out.println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they "
+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "
+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");
System.System.System.out.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");
System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");
System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.
*/*/
while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try{try{try{
/* User is given the choice of different methods that/* User is given the choice of different methods that
* explain how methods are handled in Java.* explain how methods are handled in Java.
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
squareRoot();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
Main.Main.Main.printMainMenu();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
System.System.System.exit(0);
}}
//Sets success to true so while loop ends//Sets success to true so while loop ends
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java
1.1 of 6 2014.12.04 18:55:28
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
95
96
97
98
99
100
101
102
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
methodsMain();
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the
*example choices.*example choices.
*/*/
}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");
System.System.System.out.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");
System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");
System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
//Method uses another method to determine the square root of a number//Method uses another method to determine the square root of a number
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void squareRoot() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();
final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.in);
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a "
+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "
+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");
System.System.System.out.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");
number = sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();
//calculateSquare() method is called//calculateSquare() method is called
challenge.challenge.challenge.calculateSquare(number);
//Sets success to true so while loop ends//Sets success to true so while loop ends
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java
2.1 of 6 2014.12.04 18:55:28
102
103
104
105
106
107
108
109
110
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java
3.1 of 6 2014.12.04 18:55:28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Operators {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operators(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {
operatorsMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operatorsMain() {
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");
System.System.System.out.println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating "
+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//User is asked to choose an example to run.//User is asked to choose an example to run.
System.System.System.out.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");
System.System.System.out.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");
System.System.System.out.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");
System.System.System.out.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.
*/*/
while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
/* User is given the choice of x different methods that/* User is given the choice of x different methods that
* explains how strings are handled in Java.* explains how strings are handled in Java.
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
absoluteEqual();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
floorCeiling();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
sumLimit();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
Main.Main.Main.printMainMenu();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
System.System.System.exit(0);
}}
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
operatorsMain());
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java
1.1 of 10 2014.12.04 18:55:28
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
95
96
97
98
99
100
101
102
operatorsMain());
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the
*Example choices.*Example choices.
*/*/
} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");
System.System.System.out.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");
System.System.System.out.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");
System.System.System.out.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
// Method determines the absolute value of two integers and compares them// Method determines the absolute value of two integers and compares them
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void absoluteEqual() {
//This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined "
+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "
+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");
System.System.System.out.println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if "
+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;
boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
invalid variableinvalid variable
*/
while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
//Asks user to input the first number//Asks user to input the first number
System.System.System.out.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");
//User inputs the first number//User inputs the first number
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
//Asks user to input the second number//Asks user to input the second number
System.System.System.out.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");
//User inputs the second number//User inputs the second number
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
/*Determines the Absolute Values of the first and second/*Determines the Absolute Values of the first and second/*Determines the Absolute Values of the first and second
*numbers the user inputed*numbers the user inputed
*/*/
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java
2.1 of 10 2014.12.04 18:55:28
102
103
104
105
106
107
108
109
110
*/*/
int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.abs(num1);
int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.abs(num2);
//Tests if the two absolute values ae equal//Tests if the two absolute values ae equal
if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {
//If equal, prints out they are equal//If equal, prints out they are equal
System.System.System.out.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);
} else {} else {} else {} else {} else {} else {
//If not equal, prints out they are not equal//If not equal, prints out they are not equal
System.System.System.out.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);
}}
//Sets successAE to true so while loop ends.//Sets successAE to true so while loop ends.
successAE = true;successAE = true;successAE = true;successAE = true;successAE = true;successAE = true;successAE = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed*and lets the user know the input is not allowed
*/*/
} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
//Method determines the floor and ceiling of a variable//Method determines the floor and ceiling of a variable
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void floorCeiling() {
//This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the "
+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");
System.System.System.out.println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and "
+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "
+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable*invalid variable
*/*/
while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");
double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();
System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");
System.System.System.out.println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: "
+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.ceil(number));
System.System.System.out.println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math.floor(number));
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read//read
System.System.System.out.println();.println();.println();.println();.println();
//Sets successFC to true so while loop ends//Sets successFC to true so while loop ends
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java
3.1 of 10 2014.12.04 18:55:28
//Sets successFC to true so while loop ends//Sets successFC to true so while loop ends
successFC = true;successFC = true;successFC = true;successFC = true;successFC = true;successFC = true;successFC = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed. Reprints*and lets the user know the input is not allowed. Reprints*and lets the user know the input is not allowed. Reprints
*floorCeiling example*floorCeiling example
*/*/
} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read//read
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sumLimit() {
//This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read
System.System.System.out.println();.println();.println();.println();.println();
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
int sum;int sum;int sum;int sum;int sum;
boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable*invalid variable
*/*/
while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the "
+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");
System.System.System.out.println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two "
+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");
//Asks user to input the first number//Asks user to input the first number
System.System.System.out.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");
//User inputs the first number//User inputs the first number
int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();
//Asks user to input the second number//Asks user to input the second number
System.System.System.out.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");
//User inputs the second number//User inputs the second number
int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();
//Variable sum is the sum of the two integers the user inputed//Variable sum is the sum of the two integers the user inputed
sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;
//Converts integer num1 to string number1//Converts integer num1 to string number1
String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.toString(num1);
//Converts integer sum to string sum1//Converts integer sum to string sum1
String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.toString(sum);
/*Integer integer1 is equal to the amount of elements/*Integer integer1 is equal to the amount of elements/*Integer integer1 is equal to the amount of elements
*contained within the string number1*contained within the string number1
*/*/
int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java
4.1 of 10 2014.12.04 18:55:28
int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();
/*Integer total is equal to the amount of elements contained/*Integer total is equal to the amount of elements contained
*within the string sum1*within the string sum1
*/*/
int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();
System.System.System.out.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);
//Sets successSL to true so while loop ends//Sets successSL to true so while loop ends
successSL = true;successSL = true;successSL = true;successSL = true;successSL = true;successSL = true;successSL = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed and reprints*and lets the user know the input is not allowed and reprints
*sumLimit example.*sumLimit example.
*/*/
} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read//read
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java
5.1 of 10 2014.12.04 18:55:28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Variables {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void variables(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
variablesMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void variablesMain(){
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");
System.System.System.out.println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or "
+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");
System.System.System.out.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");
System.System.System.out.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");
System.System.System.out.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");
System.System.System.out.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");
while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){
try{try{try{
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
nameAgeSalary();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
inputOfData();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
Main.Main.Main.printMainMenu();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
System.System.System.exit(0);
}}
variablesMain();
}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");
System.System.System.out.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");
System.System.System.out.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");
System.System.System.out.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");
System.System.System.out.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java
1.1 of 12 2014.12.04 18:55:30
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
System.System.System.out.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void nameAgeSalary() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initiated//Variables are initiated
Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.in);
String name;String name;String name;String name;String name;
int age;int age;int age;int age;int age;
float salary;float salary;float salary;float salary;float salary;
boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");
name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();
System.System.System.out.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");
age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();
System.System.System.out.println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old "
+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");
System.System.System.out.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");
salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();
System.System.System.out.println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not "
+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");
//Sets successNameAgeSalary to true so while loop ends//Sets successNameAgeSalary to true so while loop ends
successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
sup.next();sup.next();sup.next();sup.next();sup.next();sup.next();sup.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void inputOfData() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initialized//Variables are initialized
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java
2.1 of 12 2014.12.04 18:55:30
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//Variables are initialized//Variables are initialized
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so "
+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");
System.System.System.out.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");
String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();
System.System.System.out.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");
String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();
System.System.System.out.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");
int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();
while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {
System.System.System.out.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");
System.System.System.out.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");
grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();
}}
System.System.System.out.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");
int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();
System.System.System.out.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");
String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();
System.System.System.out.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");
float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();
while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {
System.System.System.out.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");
System.System.System.out.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");
gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();
}}
System.System.System.out.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);
System.System.System.out.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);
System.System.System.out.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);
System.System.System.out.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);
System.System.System.out.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);
//Sets successInputOfData to true so while loop ends//Sets successInputOfData to true so while loop ends
successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java
3.1 of 12 2014.12.04 18:55:30
153
154
155
156
157
158
159
160
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java
4.1 of 12 2014.12.04 18:55:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class IfElseStatements {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void ifelse(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
ifElseMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void ifElseMain(){
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");
System.System.System.out.println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form "
+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");
System.System.System.out.println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can "
+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "
+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");
System.System.System.out.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");
System.System.System.out.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");
System.System.System.out.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.
*/*/
while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try{try{try{
/*User is given the choice of three different methods that use/*User is given the choice of three different methods that use
If-Else Statements.If-Else Statements.
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
oddEven();
} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {
multiwayIfElse();
} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {
operatingSystem();
} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {
Main.Main.Main.printMainMenu();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
System.System.System.exit(0);
}}
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java
1.1 of 15 2014.12.04 18:55:24
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
ifElseMain();
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints
the example choices.the example choices.
*/*/
}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");
System.System.System.out.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");
System.System.System.out.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");
System.System.System.out.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");
System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");
System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
//Method determines whether a Integer is even or odd.//Method determines whether a Integer is even or odd.
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void oddEven() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables used are instatiated.//Variables used are instatiated.
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;
/*While loop is set up to reprint the method incase the user inputs a/*While loop is set up to reprint the method incase the user inputs a
invalid variable.invalid variable.
*/
while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {
//Initiates Try-Catch Statement for exception.//Initiates Try-Catch Statement for exception.
try {try {try {try {
//User is asked to input a integer//User is asked to input a integer
System.System.System.out.println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to "
+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "
+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "
+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");
//User inputs integer//User inputs integer
int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();
/*If-Else Statement is used to determine whether the integer is/*If-Else Statement is used to determine whether the integer is
even or odd based on the modulus of 2.even or odd based on the modulus of 2.
*/*/
if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {
System.System.System.out.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");
} else {} else {} else {} else {} else {} else {
System.System.System.out.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");
}}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java
2.1 of 15 2014.12.04 18:55:24
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
}}
//Sets successOddEven to true so while loop ends//Sets successOddEven to true so while loop ends
successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;
} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {
System.System.System.out.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");
System.System.System.out.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void multiwayIfElse() {
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initialized.//Variables are initialized.
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer;
int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;
boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;
/*While loop is setup to reprint the method incase user inputs an/*While loop is setup to reprint the method incase user inputs an
invalid variable.invalid variable.
*/
while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {
//Initiates Try-Catch Statement for exception//Initiates Try-Catch Statement for exception
try {try {try {try {
System.System.System.out.println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else "
+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "
+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "
+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "
+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");
//User inputs data//User inputs data
System.System.System.out.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");
int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();
System.System.System.out.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");
String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();
//Multiway If-Else statement is used to determine number of//Multiway If-Else statement is used to determine number of//Multiway If-Else statement is used to determine number of
//free books.//free books.
if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {
isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;
if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {
freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;
} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {
freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;
}}
} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {
isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;
if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {
freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java
3.1 of 15 2014.12.04 18:55:24
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;
} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {
freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;
}}
}}
//System prints out number of free books//System prints out number of free books
System.System.System.out.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);
//Sets successMultiwayIfElse to true so while loop ends//Sets successMultiwayIfElse to true so while loop ends
successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;
} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {
System.System.System.out.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");
System.System.System.out.println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and "
+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operatingSystem(){
//This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read.
System.System.System.out.println();.println();.println();.println();.println();
//Variables are initialized//Variables are initialized
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
invalid variable.invalid variable.
*/
while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the "
+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "
+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");
System.System.System.out.println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the "
+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "
+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");
System.System.System.out.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");
System.System.System.out.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");
System.System.System.out.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");
System.System.System.out.println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an "
+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");
int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();
System.System.System.out.println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most "
+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");
switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {
case 1:case 1:case 1:case 1:case 1:
System.System.System.out.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");
break;break;break;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java
4.1 of 15 2014.12.04 18:55:24
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
break;break;break;
case 2:case 2:case 2:case 2:case 2:
System.System.System.out.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");
break;break;break;
case 3:case 3:case 3:case 3:case 3:
System.System.System.out.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");
break;break;break;
default:default:default:
System.System.System.out.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");
break;break;break;
}}
//Sets successOperatingSystem to true so while loop ends//Sets successOperatingSystem to true so while loop ends
successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
System.System.System.out.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java
5.1 of 15 2014.12.04 18:55:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package finalproject;package finalproject;package finalproject;package finalproject;
import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;
import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;
public classpublic classpublic classpublic class Strings {
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void string(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){
stringMain();
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void stringMain(){
Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in);
int choice;int choice;int choice;int choice;int choice;
boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");
System.System.System.out.println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or "
+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
//User is asked to choose an example to run.//User is asked to choose an example to run.
System.System.System.out.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");
System.System.System.out.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");
System.System.System.out.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");
System.System.System.out.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");
System.System.System.out.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");
System.System.System.out.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");
System.System.System.out.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");
/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a
* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.
*/*/
while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){
// Initiates try-catch statement for exception// Initiates try-catch statement for exception
try{try{try{
/* User is given the choice of x different methods that/* User is given the choice of x different methods that
* explains how strings are handled in Java.* explains how strings are handled in Java.
*/*/
choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();
if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {
smellingRats();
} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){
sesquipedalian();
} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){
stringSplit();
} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){
exctractTheDomain();
} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {
Main.Main.Main.printMainMenu();
} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {
System.System.System.exit(00));
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java
1.1 of 15 2014.12.04 18:55:30
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
System.System.System.exit(00));
}}
success = true;success = true;success = true;success = true;success = true;success = true;success = true;
stringMain();
/*Catch statement is used incase user inputs invalid variables and/*Catch statement is used incase user inputs invalid variables and
*lets the user know the input is not allowed. Reprints the Example*lets the user know the input is not allowed. Reprints the Example
*choices.*choices.
*/*/*/
}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");
System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
System.System.System.out.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");
System.System.System.out.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");
System.System.System.out.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");
System.System.System.out.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");
System.System.System.out.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");
System.System.System.out.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");
System.System.System.out.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");
sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();
}}
}
}
// Method determines where the word "rat" is in a string.// Method determines where the word "rat" is in a string.
public static booleanpublic static booleanpublic static booleanpublic static booleanpublic static booleanpublic static boolean ratSmeller(String x) {(String x) {(String x) {(String x) {(String x) {(String x) {(String x) {
String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";
int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();
int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();
boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;
for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){
if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){
foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true;
break;break;break;
}}
}}
return foundRat;return foundRat;return foundRat;return foundRat;return foundRat;
}
// Method inputs to ratSmeller()then prints out result// Method inputs to ratSmeller()then prints out result
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void smellingRats() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java
2.1 of 15 2014.12.04 18:55:30
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
*/*/
while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it "
+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");
String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();
System.System.System.out.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " + ratSmeller(searchWord));(searchWord));(searchWord));(searchWord));(searchWord));
//Sets successSmellingRats to true so while loop ends//Sets successSmellingRats to true so while loop ends
successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
//Method is initialized to return the length of a string//Method is initialized to return the length of a string
public static intpublic static intpublic static intpublic static intpublic static intpublic static intpublic static int sesquipedalianLength(String word) {(String word) {(String word) {(String word) {(String word) {(String word) {(String word) {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();
return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength;
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sesquipedalian() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");
String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();
System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");
System.System.System.out.println(sesquipedalianLength(word));
//Sets successSesquipedalian to true so while loop ends//Sets successSesquipedalian to true so while loop ends
successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java
3.1 of 15 2014.12.04 18:55:30
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void stringSplit() {
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.in);
boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");
String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();
String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");
String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];
String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];
System.System.System.out.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName
+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);
//Sets successStringSplit to true so while loop ends//Sets successStringSplit to true so while loop ends
successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
name.next();name.next();name.next();name.next();name.next();name.next();name.next();
}}
}
}
//Method is initialized to extract domain name//Method is initialized to extract domain name
public static Stringpublic static Stringpublic static Stringpublic static Stringpublic static Stringpublic static Stringpublic static String extractDomain(String email) {(String email) {(String email) {(String email) {(String email) {(String email) {(String email) {
String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");
String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];
return exctractDomain;return exctractDomain;return exctractDomain;return exctractDomain;return exctractDomain;
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java
4.1 of 15 2014.12.04 18:55:30
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
}
public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void exctractTheDomain() {
Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in);
boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;
/*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an
*invalid variable.*invalid variable.
*/*/
while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {
//Initiates try-catch statement for exception//Initiates try-catch statement for exception
try {try {try {try {
System.System.System.out.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");
String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();
System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");
System.System.System.out.println(extractDomain(email));
//Sets successExctractTheDomain to true so while loop ends//Sets successExctractTheDomain to true so while loop ends
successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;
/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables
*and lets the user know the input is not allowed.*and lets the user know the input is not allowed.
*/*/
} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {
System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");
//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to
//read.//read.
System.System.System.out.println();.println();.println();.println();.println();
scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();
}}
}
}
}
C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java
5.1 of 15 2014.12.04 18:55:30
Sources Used
https://docs.google.com/presentation/d/1pEy2soUsjinyOPxtCZUr6AehAgo6ixJM7Bxy9Ft31z0/
pub?start=false&loop=false&delayms=3000
https://docs.google.com/presentation/d/
10UdufF8RvT5YQ_QHiqKh_uVxAKFdQXTLeNSd5KFqSeA/pub?
start=false&loop=false&delayms=3000
https://docs.google.com/presentation/d/
1DF48K0oCKdz0hvcl4w8ZW9sLMJRz8sGDHmvsrj9U5as/pub?
start=false&loop=false&delayms=3000
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html
https://docs.google.com/presentation/d/1lisZqOPp4R3q6YzGUhu-wnxvQeJmfB6x4MUsytfynFg/
pub?start=false&loop=false&delayms=3000
http://www.programmr.com/area-method-example
https://docs.google.com/presentation/d/
1oCsztgHmUfkZ2x28LuaZbsW5bne8og7CFdhULd7lxN0/pub?
start=false&loop=false&delayms=3000
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
http://docs.oracle.com/javase/tutorial/essential/exceptions/
http://www.programmr.com/try-catch
http://docs.oracle.com/javase/tutorial/java/concepts/index.html
https://docs.google.com/presentation/d/
1fDeKqhW84pI90AdJWRpvVoAOScHN9fJApp5CCNqge0U/pub?
start=false&loop=false&delayms=3000
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
http://www.programmr.com/extend-box-class-include-color
http://docs.oracle.com/javase/tutorial/java/data/strings.html
https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html

Final Project

  • 1.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Main { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void main(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) { System.System.System.out.println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have ".println("This Program was written using examples I have " + "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester.");+ "learned throughout the entire semester."); System.System.System.out.println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything ".println("To make things easier to understand, everything " + "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able "+ "was seperated into 7 different sections that you are able " + "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see.");+ "to see."); System.System.System.out.println();.println();.println();.println();.println();.println(); System.System.System.out.println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number ".println("You'll be nagviating by entering the number " + "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing "+ "associtated with the section or example and pressing " + "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter.");+ "enter."); System.System.System.out.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin.");.println("Now let us begin."); printMainMenu(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void printMainMenu() { Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter ".println("This is the main menu, choose a section to enter " + "it");+ "it");+ "it");+ "it");+ "it");+ "it");+ "it");+ "it"); System.System.System.out.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic"); System.System.System.out.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control"); System.System.System.out.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops"); System.System.System.out.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods"); System.System.System.out.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators"); System.System.System.out.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables"); System.System.System.out.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements"); System.System.System.out.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings"); System.System.System.out.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit"); while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) { try {try {try {try { choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { Arithmetic.Arithmetic.Arithmetic.arithmeticMain(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { FlowControl.FlowControl.FlowControl.flowControlMain(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { Loops.Loops.Loops.loopsMain(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { Methods.Methods.Methods.methodsMain(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Main.java 1.1 of 4 2014.12.04 18:55:26
  • 2.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 Operators.Operators.Operators.operatorsMain(); } else if(choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) { Variables.Variables.Variables.variablesMain(); } else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) { IfElseStatements.IfElseStatements.IfElseStatements.ifElseMain(); } else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) {} else if (choice == 8) { Strings.Strings.Strings.stringMain(); } else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) {} else if (choice == 9) { System.System.System.exit(0); }} success = true;success = true;success = true;success = true;success = true;success = true;success = true; } catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) {} catch (InputMismatchException ePrintMainMenu) { System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section");.println("Choose a Section"); System.System.System.out.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic");.println("1. Arithmetic"); System.System.System.out.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control");.println("2. Flow Control"); System.System.System.out.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops");.println("3. Loops"); System.System.System.out.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods");.println("4. Methods"); System.System.System.out.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators");.println("5. Operators"); System.System.System.out.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables");.println("6. Variables"); System.System.System.out.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements");.println("7. If Else Statements"); System.System.System.out.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings");.println("8. Strings"); System.System.System.out.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit");.println("9. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Main.java 2.1 of 4 2014.12.04 18:55:26
  • 4.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Arithmetic { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void arithmetic(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ arithmeticMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void arithmeticMain() { //Variables are initiated//Variables are initiated Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section");.println("You have selected the Arithmetics Section"); System.System.System.out.println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's ".println("Arithemtic is pretty self explanatory, it's " + "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program.");+ "math used within a program."); //This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read System.System.System.out.println();.println();.println();.println();.println(); //User is asked to choose an example to run//User is asked to choose an example to run System.System.System.out.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example"); System.System.System.out.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition"); System.System.System.out.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction"); System.System.System.out.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication"); System.System.System.out.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division"); System.System.System.out.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus"); System.System.System.out.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu"); System.System.System.out.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a method if the user inputs an incorrect value.method if the user inputs an incorrect value. */ while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { /* User is given the choice of multiple methods that involve/* User is given the choice of multiple methods that involve/* User is given the choice of multiple methods that involve ArithmenticsArithmentics */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { addition(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { subtraction(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { multiplication(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { division(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { modulus(); } else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) { C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java 1.1 of 18 2014.12.04 18:55:22
  • 6.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 } else if(choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) { Main.Main.Main.printMainMenu(); } else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) {} else if (choice == 7) { System.System.System.exit(0); }} success = true;success = true;success = true;success = true;success = true;success = true;success = true; arithmeticMain(); /*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints the method choicesthe method choices */*/ } catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) {} catch (InputMismatchException eArithmeticMain) { System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read//read System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example");.println("Choose a Arithmetic Example"); System.System.System.out.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition");.println("1. Addition"); System.System.System.out.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction");.println("2. Subtraction"); System.System.System.out.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication");.println("3. Multiplication"); System.System.System.out.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division");.println("4. Division"); System.System.System.out.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus");.println("5. Modulus"); System.System.System.out.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu");.println("6. Main Menu"); System.System.System.out.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit");.println("7. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void addition() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); int sum;int sum;int sum;int sum;int sum; Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false;boolean successAddition = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) {while (!successAddition) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example.");.println("This is a simple addition example."); System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: "); int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: "); int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2; System.System.System.out.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum);.println("The sum is: " + sum); //Sets successAddition to true so while loop ends//Sets successAddition to true so while loop ends successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java 2.1 of 18 2014.12.04 18:55:22
  • 8.
    successAddition = true;successAddition= true;successAddition = true;successAddition = true;successAddition = true;successAddition = true;successAddition = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) {} catch (InputMismatchException eAddition) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void subtraction() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); int result;int result;int result;int result;int result; Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false;boolean successSubtraction = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) {while (!successSubtraction) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example.");.println("This is a simple subtraction example."); System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: "); int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: "); int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2;result = num1 - num2; System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result); //Sets successSubtraction to true so while loop ends//Sets successSubtraction to true so while loop ends successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true;successSubtraction = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) {} catch (InputMismatchException eSubtraction) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void multiplication() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); int result;int result;int result;int result;int result; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java 3.1 of 18 2014.12.04 18:55:22
  • 10.
    int result;int result;intresult;int result;int result; Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false;boolean successMultiplication = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) {while (!successMultiplication) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example.");.println("This is a simple multiplication example."); System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: "); int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: "); int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2;result = num1 * num2; System.System.System.out.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result);.println("The product is: " + result); //Sets successMultiplication to true so while loop ends//Sets successMultiplication to true so while loop ends successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true;successMultiplication = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) {} catch (InputMismatchException eMultiplication) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void division() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initiated//Variables are initiated int result;int result;int result;int result;int result; Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false;boolean successDivision = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) {while (!successDivision) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example.");.println("This is a simple division example."); System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: "); int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: "); int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2;result = num1 / num2; System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result); //Sets successDivision to true so while loop ends//Sets successDivision to true so while loop ends C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java 4.1 of 18 2014.12.04 18:55:22
  • 12.
    //Sets successDivision totrue so while loop ends//Sets successDivision to true so while loop ends successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true;successDivision = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) {} catch (InputMismatchException eDivision) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void modulus() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initiated//Variables are initiated int result;int result;int result;int result;int result; Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false;boolean successModulus = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) {while (!successModulus) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example.");.println("This is a simple modulus example."); System.System.System.out.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: ");.print("Enter a Integer: "); int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); System.System.System.out.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: ");.print("Enter another Integer: "); int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2;result = num1 % num2; System.System.System.out.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result);.println("The result is: " + result); //Sets successModulus to true so while loop ends//Sets successModulus to true so while loop ends successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true;successModulus = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) {} catch (InputMismatchException eModulus) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Arithmetic.java 5.1 of 18 2014.12.04 18:55:22
  • 14.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class FlowControl { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void flowControl(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ flowControlMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void flowControlMain() { Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section");.println("You have selected the Flow Control Section"); System.System.System.out.println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have ".println("Flow Control is used if one actions can have " + "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens.");+ "multiple outcomes depending on what happens."); //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example"); System.System.System.out.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep"); System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu"); System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a * Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value. */*/ while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { /* User is given the choice of different methods that/* User is given the choice of different methods that * explain how flow control is handled in Java.* explain how flow control is handled in Java. */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { sleepExample(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { Main.Main.Main.printMainMenu(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { System.System.System.exit(0); }} //Sets success to true so while loop ends//Sets success to true so while loop ends success = true;success = true;success = true;success = true;success = true;success = true;success = true; flowControlMain(); /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the *example choices.*example choices. */*/ } catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) {} catch (InputMismatchException eFlowControlMain) { System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java 1.1 of 6 2014.12.04 18:55:24
  • 16.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 System.System.System.out.println("You can't dothat!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example");.println("Choose a Flow Control Example"); System.System.System.out.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep");.println("1. Sleep"); System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu"); System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } //Method uses boolean to determine whether the user can sleep in or not.//Method uses boolean to determine whether the user can sleep in or not. public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sleepExample() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false;boolean successSE = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) {while (!successSE) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { //User friendly explaination//User friendly explaination System.System.System.out.println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can ".println("The user is asks whether he or she can " + "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or "+ "sleep in based on whether it is a weekday and/or " + "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation.");+ "he or she is on vacation."); //User is asked whether today is a weekday or not.//User is asked whether today is a weekday or not. System.System.System.out.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): ");.print("Is it a weekday today?(true or false): "); boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean();boolean w = scanner.nextBoolean(); //User is asked whether he or she is on vacation.//User is asked whether he or she is on vacation. System.System.System.out.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): ");.print("Are you on vacation?(true or false): "); boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean();boolean v = scanner.nextBoolean(); System.System.System.out.println();.println();.println();.println();.println(); //If true, user can sleep in.//If true, user can sleep in. if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) {if (w == true && v == true) { System.System.System.out.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D");.println("You can sleep in! :D"); System.System.System.out.println();.println();.println();.println();.println(); //If false, user cannot sleep in//If false, user cannot sleep in } else {} else {} else {} else {} else {} else { System.System.System.out.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :(");.println("You cannot sleep in. :("); System.System.System.out.println();.println();.println();.println();.println(); }} //Sets successSE to true so while loop ends//Sets successSE to true so while loop ends successSE = true;successSE = true;successSE = true;successSE = true;successSE = true;successSE = true;successSE = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) { C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java 2.1 of 6 2014.12.04 18:55:24
  • 18.
    102 103 104 105 106 107 108 109 110 111 112 113 114 } catch (InputMismatchExceptioneSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) {} catch (InputMismatchException eSleepExample) { System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/FlowControl.java 3.1 of 6 2014.12.04 18:55:24
  • 19.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Loops { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void loops(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ loopsMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void loopsMain(){ //Variables are initiated//Variables are initiated Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false;boolean successLoopsMain = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section");.println("You have selected the Loops Section"); System.System.System.out.println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a ".println("Loops are used to to repeat actions within a " + "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, "+ "program. They can be use in conjunction with exceptions, " + "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to "+ "exceptions being try-catch statements that are used to " + "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing.");+ "prevent the program from crashing."); //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example"); System.System.System.out.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop"); System.System.System.out.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop"); System.System.System.out.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); /*While loop is used to allow the user to re-enter the value for a/*While loop is used to allow the user to re-enter the value for a/*While loop is used to allow the user to re-enter the value for a method if the user inputs an incorrect valuemethod if the user inputs an incorrect value */ while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){while (!successLoopsMain){ //Initiates try-catch statement for exception//Initiates try-catch statement for exception try{try{try{ /*User is given the choice of multiple methods that involve/*User is given the choice of multiple methods that involve loopsloops */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { forLoop(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { whileLoop(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { doWhileLoop(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { Main.Main.Main.printMainMenu(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { System.System.System.exit(0); }} //Sets successLoopsMain to true so while loop ends//Sets successLoopsMain to true so while loop ends C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java 1.1 of 10 2014.12.04 18:55:26
  • 21.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 //Sets successLoopsMain totrue so while loop ends//Sets successLoopsMain to true so while loop ends successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true;successLoopsMain = true; loopsMain(); /*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable/*Catch statement is used incase user inputs an invalid variable and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints the method choicesthe method choices */*/ }catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){}catch (InputMismatchException eLoops){ System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example");.println("Choose a Loop Example"); System.System.System.out.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop");.println("1. For Loop"); System.System.System.out.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop");.println("2. While Loop"); System.System.System.out.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop");.println("3. Do Loop"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void forLoop() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables initiated//Variables initiated int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0;int i, lo, hi, result = 0; Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.Scanner forScanner = new Scanner(System.in); boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false;boolean successForLoop = false; while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) {while (!successForLoop) { try {try {try {try { System.System.System.out.println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show ".println("A simple operation will be used to show " + "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works.");+ "off how a For Loop works."); System.System.System.out.println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the ".println("A For Loop is made up of three parts, the " + "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the "+ "initial variable, the variable that determines the " + "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that "+ "limit, and a iteration of the initial variable that " + "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run.");+ "allows the loop to run."); System.System.System.out.println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be ".println("For this example, you the user will be " + "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) "+ "asked to enter a lower limit (initial variable) " + "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit).");+ "and a upper limit (variable of limit)."); System.System.System.out.println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit ".println("The loop will then add the lower limit " + "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one "+ "to itself along with the lower limit adding one " + "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is "+ "to itself for each run until the lower limit is " + "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit.");+ "less than or equal to the upper limit."); System.System.System.out.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: ");.println("Enter the lower limit: "); lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt();lo = forScanner.nextInt(); System.System.System.out.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: ");.println("Enter the upper limit: "); hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt();hi = forScanner.nextInt(); //For loop initiated//For loop initiated C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java 2.1 of 10 2014.12.04 18:55:26
  • 23.
    102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 //For loop initiated//Forloop initiated for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) {for (i = lo; i <= hi; i++) { result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i;result = result + i; }} System.System.System.out.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result);.println("The result is " + result); //Sets successForLoop to true so while loop ends//Sets successForLoop to true so while loop ends successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true;successForLoop = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) {} catch (InputMismatchException eForLoop) { System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type"); System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next();forScanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void whileLoop() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables initiated//Variables initiated Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.Scanner whileScanner = new Scanner(System.in); boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false;boolean successWhileLoop = false; while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) {while (!successWhileLoop) { try {try {try {try { System.System.System.out.println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For ".println("A While Loop works very similarly to a For " + "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the "+ "Loop. Difference is instead of one line of code the " + "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out.");+ "variables are spread out."); System.System.System.out.println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount ".println("Enter an integer signifying the amount " + "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable "+ "of money Mary has in her purse that is divisable " + "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10.");+ "by 10."); int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt();int money = whileScanner.nextInt(); System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: "); while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) {while (money > 0) { System.System.System.out.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy");.println("$" + money + " buy"); money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10;money = money - 10; }} //Sets successWhileLoop to true so while loop ends//Sets successWhileLoop to true so while loop ends successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true;successWhileLoop = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) {} catch (InputMismatchException eWhileLoop) { System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type"); System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java 3.1 of 10 2014.12.04 18:55:26
  • 25.
    153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 //read.//read. System.System.System.out.println();.println();.println();.println();.println(); whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next();whileScanner.next(); }} } } public static voidpublicstatic voidpublic static voidpublic static voidpublic static voidpublic static void doWhileLoop() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initiated//Variables are initiated int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0;int n, pin = 12345, tries = 0; Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.Scanner password = new Scanner(System.in); boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false;boolean successDoWhileLoop = false; while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) {while (!successDoWhileLoop) { try {try {try {try { System.System.System.out.println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first ".println("A Do-While Loop is a While Loop that first " + "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run "+ "runs the equation guaranting at least one run " + "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end.");+ "before actually running the loop at the end."); System.System.System.out.println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering ".println("Example would be when you are entering " + "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345.");+ "a pin. Hint the pin is 12345."); System.System.System.out.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password");.println("Enter your password"); do {do {do {do { n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt();n = password.nextInt(); if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) {if (n != pin && tries == 2) { System.System.System.out.println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. ".println("You have run out of tries. " + "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked");+ "Account Locked"); } else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) {} else if (n == pin) { System.System.System.out.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted");.println("Accepted"); //Tries is set to 2 to terminate loop early since pin//Tries is set to 2 to terminate loop early since pin //is correct//is correct tries = 2;tries = 2;tries = 2;tries = 2;tries = 2;tries = 2;tries = 2; } else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) {} else if (n != pin) { System.System.System.out.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined");.print("Declined"); }} tries++;tries++;tries++;tries++; } while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2);} while (tries <= 2); //Sets successDoWhileLoop to true so while loop ends//Sets successDoWhileLoop to true so while loop ends successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true;successDoWhileLoop = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) {} catch (InputMismatchException eDoWhileLoop) { System.System.System.out.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type");.println("Wrong Variable Type"); System.System.System.out.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number");.println("Use a whole number"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); password.next();password.next();password.next();password.next();password.next();password.next();password.next(); }} } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Loops.java 4.1 of 10 2014.12.04 18:55:26
  • 27.
  • 28.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Methods { public static doublepublic static doublepublic static doublepublic static doublepublic static doublepublic static doublepublic static double number, answer; //Method to calculate square root initiated//Method to calculate square root initiated public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void calculateSquare(double number){(double number){(double number){(double number){(double number){(double number){ double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.double squareRoot = Math.sqrt(number); System.System.System.out.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot);.println(squareRoot); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void methods(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ methodsMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void methodsMain(){ Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section");.println("You have selected the Methods Section"); System.System.System.out.println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they ".println("Methods are used for multiple reasons. But they " + "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used "+ "are typically used to simplify processes that are be used " + "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program.");+ "throughout the program."); //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example"); System.System.System.out.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root"); System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu"); System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a * Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value. */*/ while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){ //Initiates try-catch statement for exception//Initiates try-catch statement for exception try{try{try{ /* User is given the choice of different methods that/* User is given the choice of different methods that * explain how methods are handled in Java.* explain how methods are handled in Java. */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { squareRoot(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { Main.Main.Main.printMainMenu(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { System.System.System.exit(0); }} //Sets success to true so while loop ends//Sets success to true so while loop ends success = true;success = true;success = true;success = true;success = true;success = true;success = true; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java 1.1 of 6 2014.12.04 18:55:28
  • 30.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97 98 99 100 101 102 success = true;success= true;success = true;success = true;success = true;success = true;success = true; methodsMain(); /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the *example choices.*example choices. */*/ }catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){}catch (InputMismatchException eMethods){ System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example");.println("Choose a Method Example"); System.System.System.out.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root");.println("1. Square Root"); System.System.System.out.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu");.println("2. Main Menu"); System.System.System.out.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit");.println("3. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } //Method uses another method to determine the square root of a number//Method uses another method to determine the square root of a number public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void squareRoot() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods();Methods challenge = new Methods(); final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.final Scanner sc = new Scanner(System.in); boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a ".println("Example finds the square root of a " + "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called "+ "rational number by using a method called " + "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()");+ "calculateSquare()"); System.System.System.out.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: ");.print("Enter a number: "); number = sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble();= sc.nextDouble(); //calculateSquare() method is called//calculateSquare() method is called challenge.challenge.challenge.calculateSquare(number); //Sets success to true so while loop ends//Sets success to true so while loop ends success = true;success = true;success = true;success = true;success = true;success = true;success = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) {} catch (InputMismatchException eSquareRoot) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java 2.1 of 6 2014.12.04 18:55:28
  • 32.
    102 103 104 105 106 107 108 109 110 //This println isused to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Methods.java 3.1 of 6 2014.12.04 18:55:28
  • 33.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Operators { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operators(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) {(String[] args) { operatorsMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operatorsMain() { Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section");.println("You have selected the Operators Section"); System.System.System.out.println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating ".println("Operators are typically used for manipulating " + "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome.");+ "data for whatever is needed for the outcome."); //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //User is asked to choose an example to run.//User is asked to choose an example to run. System.System.System.out.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example"); System.System.System.out.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals"); System.System.System.out.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling"); System.System.System.out.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a * Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value. */*/ while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) {while (!success) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { /* User is given the choice of x different methods that/* User is given the choice of x different methods that * explains how strings are handled in Java.* explains how strings are handled in Java. */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { absoluteEqual(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { floorCeiling(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { sumLimit(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { Main.Main.Main.printMainMenu(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { System.System.System.exit(0); }} success = true;success = true;success = true;success = true;success = true;success = true;success = true; operatorsMain()); C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java 1.1 of 10 2014.12.04 18:55:28
  • 35.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 95 96 97 98 99 100 101 102 operatorsMain()); /*Catch statement isused incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed. Reprints the*and lets the user know the input is not allowed. Reprints the *Example choices.*Example choices. */*/ } catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) {} catch (InputMismatchException eOperators) { System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example");.println("Choose a Operator Example"); System.System.System.out.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals");.println("1. Absolute Equals"); System.System.System.out.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling");.println("2. Floor and Ceiling"); System.System.System.out.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit");.println("3. Sum Limit"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } // Method determines the absolute value of two integers and compares them// Method determines the absolute value of two integers and compares them public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void absoluteEqual() { //This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined ".println("The absolute value of two integers is determined " + "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the "+ "by using the method Math.abs(), which returns the " + "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers.");+ "absolute values of the two integers."); System.System.System.out.println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if ".println("The two values are then compared to determine if " + "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal.");+ "their absolute values equal."); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true;boolean equal = true; boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false;boolean successAE = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an invalid variableinvalid variable */ while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) {while (!successAE) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { //Asks user to input the first number//Asks user to input the first number System.System.System.out.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: ");.print("Enter the 1st number: "); //User inputs the first number//User inputs the first number int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); //Asks user to input the second number//Asks user to input the second number System.System.System.out.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: ");.print("Enter the 2nd number: "); //User inputs the second number//User inputs the second number int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); /*Determines the Absolute Values of the first and second/*Determines the Absolute Values of the first and second/*Determines the Absolute Values of the first and second *numbers the user inputed*numbers the user inputed */*/ C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java 2.1 of 10 2014.12.04 18:55:28
  • 37.
    102 103 104 105 106 107 108 109 110 */*/ int num3 =Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.int num3 = Math.abs(num1); int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.int num4 = Math.abs(num2); //Tests if the two absolute values ae equal//Tests if the two absolute values ae equal if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) {if (num3 == num4) { //If equal, prints out they are equal//If equal, prints out they are equal System.System.System.out.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal);.println("Result is: " + equal); } else {} else {} else {} else {} else {} else { //If not equal, prints out they are not equal//If not equal, prints out they are not equal System.System.System.out.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal);.println("Result is: " + !equal); }} //Sets successAE to true so while loop ends.//Sets successAE to true so while loop ends. successAE = true;successAE = true;successAE = true;successAE = true;successAE = true;successAE = true;successAE = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed*and lets the user know the input is not allowed */*/ } catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) {} catch (InputMismatchException eAbsoluteEqual) { System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } //Method determines the floor and ceiling of a variable//Method determines the floor and ceiling of a variable public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void floorCeiling() { //This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the ".println("The floor and ceiling a number is simply the " + "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number.");+ "two real numbers that surround a rational number."); System.System.System.out.println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and ".println("In this case, the methods Math.floor() and " + "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine "+ "Math.ceiling() will be used on a Double to determine " + "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling.");+ "the two Integers that are the floor and ceiling."); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false;boolean successFC = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable*invalid variable */*/ while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) {while (!successFC) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { System.System.System.out.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: ");.print("Input using a Double like 4.5: "); double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble();double number = scanner.nextDouble(); System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: "); System.System.System.out.println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: ".println("The ceiling is: " + (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.+ (int) Math.ceil(number)); System.System.System.out.println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math..println("The floor is: " + (int) Math.floor(number)); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read//read System.System.System.out.println();.println();.println();.println();.println(); //Sets successFC to true so while loop ends//Sets successFC to true so while loop ends C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java 3.1 of 10 2014.12.04 18:55:28
  • 39.
    //Sets successFC totrue so while loop ends//Sets successFC to true so while loop ends successFC = true;successFC = true;successFC = true;successFC = true;successFC = true;successFC = true;successFC = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed. Reprints*and lets the user know the input is not allowed. Reprints*and lets the user know the input is not allowed. Reprints *floorCeiling example*floorCeiling example */*/ } catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) {} catch (InputMismatchException eFloorCeiling) { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read//read System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sumLimit() { //This println is used to sperate methods to make it easier to read//This println is used to sperate methods to make it easier to read System.System.System.out.println();.println();.println();.println();.println(); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); int sum;int sum;int sum;int sum;int sum; boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false;boolean successSL = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable*invalid variable */*/ while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) {while (!successSL) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the ".println("The sum limit of two integers is the " + "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum.");+ "amount of elements within the sum."); System.System.System.out.println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two ".println("Example would be the number 25 has two " + "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements.");+ "elements while the number 136 has three elements."); //Asks user to input the first number//Asks user to input the first number System.System.System.out.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:");.println("Enter the 1st number:"); //User inputs the first number//User inputs the first number int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt();int num1 = scanner.nextInt(); //Asks user to input the second number//Asks user to input the second number System.System.System.out.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:");.println("Enter the 2nd number:"); //User inputs the second number//User inputs the second number int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt();int num2 = scanner.nextInt(); //Variable sum is the sum of the two integers the user inputed//Variable sum is the sum of the two integers the user inputed sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2;sum = num1 + num2; //Converts integer num1 to string number1//Converts integer num1 to string number1 String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.String number1 = Integer.toString(num1); //Converts integer sum to string sum1//Converts integer sum to string sum1 String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.String sum1 = Integer.toString(sum); /*Integer integer1 is equal to the amount of elements/*Integer integer1 is equal to the amount of elements/*Integer integer1 is equal to the amount of elements *contained within the string number1*contained within the string number1 */*/ int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length(); C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java 4.1 of 10 2014.12.04 18:55:28
  • 40.
    int integer1 =number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length();int integer1 = number1.length(); /*Integer total is equal to the amount of elements contained/*Integer total is equal to the amount of elements contained *within the string sum1*within the string sum1 */*/ int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length();int total = sum1.length(); System.System.System.out.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total);.println("The length of the sum is: " + total); //Sets successSL to true so while loop ends//Sets successSL to true so while loop ends successSL = true;successSL = true;successSL = true;successSL = true;successSL = true;successSL = true;successSL = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed and reprints*and lets the user know the input is not allowed and reprints *sumLimit example.*sumLimit example. */*/ } catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) {} catch (InputMismatchException eSumLimit) { System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read//read System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Operators.java 5.1 of 10 2014.12.04 18:55:28
  • 42.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Variables { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void variables(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ variablesMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void variablesMain(){ Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section");.println("You have selected the Variables Section"); System.System.System.out.println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or ".println("Variables whether it be numbers, letters, or " + "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system.");+ "even characters is data the user inputs into the system."); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example"); System.System.System.out.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary"); System.System.System.out.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data"); System.System.System.out.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu"); System.System.System.out.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit"); while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){ try{try{try{ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { nameAgeSalary(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { inputOfData(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { Main.Main.Main.printMainMenu(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { System.System.System.exit(0); }} variablesMain(); }catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){}catch (InputMismatchException e){ System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example");.println("Choose a Variable Example"); System.System.System.out.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary");.println("1. Name, Age, and Salary"); System.System.System.out.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data");.println("2. The Input Of Data"); System.System.System.out.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu");.println("3. Main Menu"); System.System.System.out.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit"); C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java 1.1 of 12 2014.12.04 18:55:30
  • 44.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 System.System.System.out.println("4. Quit");.println("4. Quit");.println("4.Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit");.println("4. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void nameAgeSalary() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initiated//Variables are initiated Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.Scanner sup = new Scanner(System.in); String name;String name;String name;String name;String name; int age;int age;int age;int age;int age; float salary;float salary;float salary;float salary;float salary; boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false;boolean successNameAgeSalary = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) {while (!successNameAgeSalary) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?");.println("Hello. What is your name?"); name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next();name = sup.next(); System.System.System.out.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?");.println("Hi " + name + "! How old are you?"); age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt();age = sup.nextInt(); System.System.System.out.println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old ".println("So you're " + age + " eh? That's not old " + "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!");+ "at all!"); System.System.System.out.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?");.println("How much do you make " + name + "?"); salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat();salary = sup.nextFloat(); System.System.System.out.println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not ".println(salary + "! I hope that's per hour and not " + "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!");+ "per year! LOL!"); //Sets successNameAgeSalary to true so while loop ends//Sets successNameAgeSalary to true so while loop ends successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true;successNameAgeSalary = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) {} catch (InputMismatchException eNameAgeSalary) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); sup.next();sup.next();sup.next();sup.next();sup.next();sup.next();sup.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void inputOfData() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initialized//Variables are initialized C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java 2.1 of 12 2014.12.04 18:55:30
  • 46.
    102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 //Variables are initialized//Variablesare initialized Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false;boolean successInputOfData = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) {while (!successInputOfData) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so ".println("Please enter the following information so " + "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:");+ "I can can sell it for profit!:"); System.System.System.out.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: ");.print("First name: "); String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next();String firstName = scanner.next(); System.System.System.out.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: ");.print("Last name: "); String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next();String lastName = scanner.next(); System.System.System.out.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): ");.print("Grade (9-12): "); int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt();int grade = scanner.nextInt(); while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) {while (grade < 9 || grade > 12) { System.System.System.out.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade");.println("Invalid Grade"); System.System.System.out.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)");.println("Grade (9-12)"); grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt();grade = scanner.nextInt(); }} System.System.System.out.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: ");.print("Student ID: "); int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt();int studentID = scanner.nextInt(); System.System.System.out.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: ");.print("Login: "); String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next();String login = scanner.next(); System.System.System.out.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): ");.print("GPA (0.00-4.00): "); float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat();float gpa = scanner.nextFloat(); while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) {while (gpa < 0 || gpa > 4) { System.System.System.out.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA");.println("Invalid GPA"); System.System.System.out.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): ");.println("GPA (0.0-4.0): "); gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat();gpa = scanner.nextFloat(); }} System.System.System.out.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login);.println("Login:" + login); System.System.System.out.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID);.println("ID:" + studentID); System.System.System.out.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName);.println("Name:" + lastName + "; " + firstName); System.System.System.out.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa);.println("GPA:" + gpa); System.System.System.out.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade);.println("Grade:" + grade); //Sets successInputOfData to true so while loop ends//Sets successInputOfData to true so while loop ends successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true;successInputOfData = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) {} catch (InputMismatchException eInputOfData) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Variables.java 3.1 of 12 2014.12.04 18:55:30
  • 48.
  • 49.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class IfElseStatements { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void ifelse(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ ifElseMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void ifElseMain(){ Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section");.println("You have selected the If Else Statements Section"); System.System.System.out.println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form ".println("If-Else Statements are actually a specific form " + "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control.");+ "of flow control."); System.System.System.out.println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can ".println("They are typically used when multiple actions can " + "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x "+ "happen within a program. A simple explanation can be if x " + "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen.");+ "happens, then y will happen."); //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example"); System.System.System.out.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?"); System.System.System.out.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member"); System.System.System.out.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a * Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value. */*/ while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){while (!success){ //Initiates try-catch statement for exception//Initiates try-catch statement for exception try{try{try{ /*User is given the choice of three different methods that use/*User is given the choice of three different methods that use If-Else Statements.If-Else Statements. */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { oddEven(); } else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) {} else if (choice == 2) { multiwayIfElse(); } else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) {} else if (choice == 3) { operatingSystem(); } else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) {} else if (choice == 4) { Main.Main.Main.printMainMenu(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { System.System.System.exit(0); }} success = true;success = true;success = true;success = true;success = true;success = true;success = true; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java 1.1 of 15 2014.12.04 18:55:24
  • 51.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 success = true;success= true;success = true;success = true;success = true;success = true;success = true; ifElseMain(); /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables and lets the user know the input is not allowed. Also reprintsand lets the user know the input is not allowed. Also reprints the example choices.the example choices. */*/ }catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){}catch (InputMismatchException eIfElseStatements){ System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!");.println("You can't do that!"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example");.println("Choose a If-Else Example"); System.System.System.out.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?");.println("1. Is a Number Odd or Even?"); System.System.System.out.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member");.println("2. Benifits of being a premium member"); System.System.System.out.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?");.println("3. What operating system do you use?"); System.System.System.out.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu");.println("4. Main Menu"); System.System.System.out.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit");.println("5. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } //Method determines whether a Integer is even or odd.//Method determines whether a Integer is even or odd. public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void oddEven() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables used are instatiated.//Variables used are instatiated. Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false;boolean successOddEven = false; /*While loop is set up to reprint the method incase the user inputs a/*While loop is set up to reprint the method incase the user inputs a invalid variable.invalid variable. */ while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) {while (!successOddEven) { //Initiates Try-Catch Statement for exception.//Initiates Try-Catch Statement for exception. try {try {try {try { //User is asked to input a integer//User is asked to input a integer System.System.System.out.println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to ".println("Example uses a If-Else Statement to " + "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even "+ "determine whether the integer you input is even " + "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to "+ "or odd by determiing if its modulus 2 is equal to " + "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0.");+ "0."); //User inputs integer//User inputs integer int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt();int num = scanner.nextInt(); /*If-Else Statement is used to determine whether the integer is/*If-Else Statement is used to determine whether the integer is even or odd based on the modulus of 2.even or odd based on the modulus of 2. */*/ if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) {if (num % 2 == 0) { System.System.System.out.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even");.println("The number you input is even"); } else {} else {} else {} else {} else {} else { System.System.System.out.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd");.println("The number you input is odd"); }} C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java 2.1 of 15 2014.12.04 18:55:24
  • 53.
    102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 }} //Sets successOddEven totrue so while loop ends//Sets successOddEven to true so while loop ends successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true;successOddEven = true; } catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) {} catch (InputMismatchException eOddEven) { System.System.System.out.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type");.println("Wrong Intput Type"); System.System.System.out.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)");.println("Try again using Integers (Whole Numbers)"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void multiwayIfElse() { //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initialized.//Variables are initialized. Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer;boolean isPremiumCustomer; int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0;int freeBooks = 0; boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false;boolean successMultiwayIfElse = false; /*While loop is setup to reprint the method incase user inputs an/*While loop is setup to reprint the method incase user inputs an invalid variable.invalid variable. */ while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) {while (!successMultiwayIfElse) { //Initiates Try-Catch Statement for exception//Initiates Try-Catch Statement for exception try {try {try {try { System.System.System.out.println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else ".println("Example uses a Mulitway If-Else " + "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you "+ "Statement to determine how many free books you " + "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a "+ "shall recieve based on whether you are a " + "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving "+ "premium member or just a regular ol' book loving " + "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer.");+ "customer."); //User inputs data//User inputs data System.System.System.out.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:");.println("Enter the number of books:"); int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt();int nBooksPurchased = scanner.nextInt(); System.System.System.out.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):");.println("Is Premium Customer? (Y/N):"); String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next();String ans = scanner.next(); //Multiway If-Else statement is used to determine number of//Multiway If-Else statement is used to determine number of//Multiway If-Else statement is used to determine number of //free books.//free books. if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) {if (ans.equals("y") || ans.equals("Y")) { isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true;isPremiumCustomer = true; if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) {if (nBooksPurchased >= 8) { freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2; } else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) {} else if (nBooksPurchased >= 5) { freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1; }} } else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) {} else if (ans.equals("n") || ans.equals("N")) { isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false;isPremiumCustomer = false; if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) {if (nBooksPurchased >= 12) { freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java 3.1 of 15 2014.12.04 18:55:24
  • 55.
    153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 freeBooks = 2;freeBooks= 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2;freeBooks = 2; } else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) {} else if (nBooksPurchased >= 7) { freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1;freeBooks = 1; }} }} //System prints out number of free books//System prints out number of free books System.System.System.out.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks);.println("Free Books: " + freeBooks); //Sets successMultiwayIfElse to true so while loop ends//Sets successMultiwayIfElse to true so while loop ends successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true;successMultiwayIfElse = true; } catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) {} catch (InputMismatchException eMultiwayIfElse) { System.System.System.out.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input");.println("Wrong Input"); System.System.System.out.println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and ".println("Use Integers for the amount of books and " + "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status");+ "either Y/y/N/n for membership status"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void operatingSystem(){ //This println is used to sperate methods to make it easier to read.//This println is used to sperate methods to make it easier to read. System.System.System.out.println();.println();.println();.println();.println(); //Variables are initialized//Variables are initialized Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false;boolean successOperatingSystem = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an invalid variable.invalid variable. */ while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) {while (!successOperatingSystem) { // Initiates try-catch statement for exception// Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the ".println("Enter the number that corresonds to the " + "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with "+ "Operating System you are most comfortable with " + "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks.");+ "using for your day to day tasks."); System.System.System.out.println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the ".println("Example will then print out the " + "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a "+ "Operating System of your choosing using a " + "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement.");+ "Switch-Case Statement."); System.System.System.out.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux");.println("1- Linux"); System.System.System.out.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X");.println("2- Mac OS X"); System.System.System.out.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7");.println("3- Windows 7"); System.System.System.out.println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an ".println("Any other number will be treated as an " + "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: ");+ "unknown operating system: "); int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt();int os = scanner.nextInt(); System.System.System.out.println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most ".println("The Operating System you are most " + "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is ");+ "comfortable with using is "); switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) {switch (os) { case 1:case 1:case 1:case 1:case 1: System.System.System.out.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux");.print("Linux"); break;break;break; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java 4.1 of 15 2014.12.04 18:55:24
  • 57.
    204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 break;break;break; case 2:case 2:case2:case 2:case 2: System.System.System.out.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X");.print("Mac OS X"); break;break;break; case 3:case 3:case 3:case 3:case 3: System.System.System.out.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7");.print("Windows 7"); break;break;break; default:default:default: System.System.System.out.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS");.println("some Unknown OS"); break;break;break; }} //Sets successOperatingSystem to true so while loop ends//Sets successOperatingSystem to true so while loop ends successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true;successOperatingSystem = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) {} catch (InputMismatchException eOperatingSystem) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); System.System.System.out.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS");.println("Use an Integer to signify the OS"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/IfElseStatements.java 5.1 of 15 2014.12.04 18:55:24
  • 58.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package finalproject;package finalproject;packagefinalproject;package finalproject; import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException;import java.util.InputMismatchException; import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner;import java.util.Scanner; public classpublic classpublic classpublic class Strings { public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void string(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){(String[] args){ stringMain(); } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void stringMain(){ Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.Scanner sc = new Scanner(System.in); int choice;int choice;int choice;int choice;int choice; boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false;boolean success = false; System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section");.println("You have selected the Strings Section"); System.System.System.out.println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or ".println("Strings are typically used to input words or " + "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate.");+ "even sentences for the program to use or manipulate."); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); //User is asked to choose an example to run.//User is asked to choose an example to run. System.System.System.out.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example"); System.System.System.out.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats"); System.System.System.out.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian"); System.System.System.out.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split"); System.System.System.out.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain"); System.System.System.out.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu"); System.System.System.out.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit"); /* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a/* While loop is used to allow the user to re-enter the value for a * Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value.* Method if he or she inputs a incorrect value. */*/ while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){while(!success){ // Initiates try-catch statement for exception// Initiates try-catch statement for exception try{try{try{ /* User is given the choice of x different methods that/* User is given the choice of x different methods that * explains how strings are handled in Java.* explains how strings are handled in Java. */*/ choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt();choice = sc.nextInt(); if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) {if (choice == 1) { smellingRats(); } else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){} else if (choice == 2){ sesquipedalian(); } else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){} else if (choice == 3){ stringSplit(); } else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){} else if (choice == 4){ exctractTheDomain(); } else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) {} else if (choice == 5) { Main.Main.Main.printMainMenu(); } else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) {} else if (choice == 6) { System.System.System.exit(00)); C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java 1.1 of 15 2014.12.04 18:55:30
  • 60.
    51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 System.System.System.exit(00)); }} success = true;success= true;success = true;success = true;success = true;success = true;success = true; stringMain(); /*Catch statement is used incase user inputs invalid variables and/*Catch statement is used incase user inputs invalid variables and *lets the user know the input is not allowed. Reprints the Example*lets the user know the input is not allowed. Reprints the Example *choices.*choices. */*/*/ }catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) {}catch (InputMismatchException eStrings) { System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that");.println("You can't do that"); System.System.System.out.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again");.println("Try Again"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); System.System.System.out.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example");.println("Choose a String Example"); System.System.System.out.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats");.println("1. Smelling Rats"); System.System.System.out.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian");.println("2. Sesquipedalian"); System.System.System.out.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split");.println("3. String Split"); System.System.System.out.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain");.println("4. Extract the Domain"); System.System.System.out.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu");.println("5. Main Menu"); System.System.System.out.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit");.println("6. Quit"); sc.next();sc.next();sc.next();sc.next();sc.next();sc.next();sc.next(); }} } } // Method determines where the word "rat" is in a string.// Method determines where the word "rat" is in a string. public static booleanpublic static booleanpublic static booleanpublic static booleanpublic static booleanpublic static boolean ratSmeller(String x) {(String x) {(String x) {(String x) {(String x) {(String x) {(String x) { String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat";String findWord = "rat"; int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length();int searchXLength = x.length(); int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length();int findWordLength = findWord.length(); boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false;boolean foundRat = false; for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){for (int i = 0; i <= (searchXLength - findWordLength); i++){ if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){if (x.regionMatches(i, findWord, 0, findWordLength)){ foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true;foundRat = true; break;break;break; }} }} return foundRat;return foundRat;return foundRat;return foundRat;return foundRat; } // Method inputs to ratSmeller()then prints out result// Method inputs to ratSmeller()then prints out result public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void smellingRats() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false;boolean successSmellingRats = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java 2.1 of 15 2014.12.04 18:55:30
  • 62.
    102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 */*/ while (!successSmellingRats) {while(!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) {while (!successSmellingRats) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it ".println("Enter a word and we will tell you if it " + "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: ");+ "contains the string 'rat' in it: "); String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine();String searchWord = scanner.nextLine(); System.System.System.out.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " +.println("Output: " + ratSmeller(searchWord));(searchWord));(searchWord));(searchWord));(searchWord)); //Sets successSmellingRats to true so while loop ends//Sets successSmellingRats to true so while loop ends successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true;successSmellingRats = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) {} catch (InputMismatchException eSmellingRats) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } //Method is initialized to return the length of a string//Method is initialized to return the length of a string public static intpublic static intpublic static intpublic static intpublic static intpublic static intpublic static int sesquipedalianLength(String word) {(String word) {(String word) {(String word) {(String word) {(String word) {(String word) { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length();int sesquipedalianLength = word.length(); return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength;return sesquipedalianLength; } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void sesquipedalian() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false;boolean successSesquipedalian = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) {while (!successSesquipedalian) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: ");.println("Please enter a word: "); String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine();String word = scanner.nextLine(); System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: "); System.System.System.out.println(sesquipedalianLength(word)); //Sets successSesquipedalian to true so while loop ends//Sets successSesquipedalian to true so while loop ends successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true;successSesquipedalian = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java 3.1 of 15 2014.12.04 18:55:30
  • 64.
    153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 *and lets theuser know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) {} catch (InputMismatchException eSesquipedalian) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } public static voidpublic static voidpublic static voidpublic static voidpublic static voidpublic static void stringSplit() { //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.Scanner name = new Scanner(System.in); boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false;boolean successStringSplit = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) {while (!successStringSplit) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: ");.print("Enter the full name: "); String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine();String fullName = name.nextLine(); String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" ");String[] str = fullName.split(" "); String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0];String firstName = str[0]; String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1];String lastName = str[1]; System.System.System.out.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName.println("The names after split is: " + lastName + ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName);+ ", " + firstName); //Sets successStringSplit to true so while loop ends//Sets successStringSplit to true so while loop ends successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true;successStringSplit = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) {} catch (InputMismatchException eStringSplit) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); name.next();name.next();name.next();name.next();name.next();name.next();name.next(); }} } } //Method is initialized to extract domain name//Method is initialized to extract domain name public static Stringpublic static Stringpublic static Stringpublic static Stringpublic static Stringpublic static Stringpublic static String extractDomain(String email) {(String email) {(String email) {(String email) {(String email) {(String email) {(String email) { String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@");String domain[] = email.split("@"); String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1];String exctractDomain = domain[1]; return exctractDomain;return exctractDomain;return exctractDomain;return exctractDomain;return exctractDomain; C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java 4.1 of 15 2014.12.04 18:55:30
  • 66.
    204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 } public static voidpublicstatic voidpublic static voidpublic static voidpublic static voidpublic static void exctractTheDomain() { Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.Scanner scanner = new Scanner(System.in); boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false;boolean successExctractTheDomain = false; /*While loop is set up to reprint the method incase user inputs an/*While loop is set up to reprint the method incase user inputs an *invalid variable.*invalid variable. */*/ while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) {while (!successExctractTheDomain) { //Initiates try-catch statement for exception//Initiates try-catch statement for exception try {try {try {try { System.System.System.out.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: ");.println("Please enter an email address: "); String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine();String email = scanner.nextLine(); System.System.System.out.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: ");.println("Output: "); System.System.System.out.println(extractDomain(email)); //Sets successExctractTheDomain to true so while loop ends//Sets successExctractTheDomain to true so while loop ends successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true;successExctractTheDomain = true; /*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables/*Catch statement is used incase user inputs invalid variables *and lets the user know the input is not allowed.*and lets the user know the input is not allowed. */*/ } catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) {} catch (InputMismatchException eExctractTheDomain) { System.System.System.out.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable");.println("Wrong Variable"); //This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to//This println is used to sperate methods to make it easier to //read.//read. System.System.System.out.println();.println();.println();.println();.println(); scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next();scanner.next(); }} } } } C:/Users/Mike/Documents/NetBeansProjects/FinalProject/src/finalproject/Strings.java 5.1 of 15 2014.12.04 18:55:30
  • 68.
    Sources Used https://docs.google.com/presentation/d/1pEy2soUsjinyOPxtCZUr6AehAgo6ixJM7Bxy9Ft31z0/ pub?start=false&loop=false&delayms=3000 https://docs.google.com/presentation/d/ 10UdufF8RvT5YQ_QHiqKh_uVxAKFdQXTLeNSd5KFqSeA/pub? start=false&loop=false&delayms=3000 https://docs.google.com/presentation/d/ 1DF48K0oCKdz0hvcl4w8ZW9sLMJRz8sGDHmvsrj9U5as/pub? start=false&loop=false&delayms=3000 http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html https://docs.google.com/presentation/d/1lisZqOPp4R3q6YzGUhu-wnxvQeJmfB6x4MUsytfynFg/ pub?start=false&loop=false&delayms=3000 http://www.programmr.com/area-method-example https://docs.google.com/presentation/d/ 1oCsztgHmUfkZ2x28LuaZbsW5bne8og7CFdhULd7lxN0/pub? start=false&loop=false&delayms=3000 http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html http://docs.oracle.com/javase/tutorial/essential/exceptions/ http://www.programmr.com/try-catch http://docs.oracle.com/javase/tutorial/java/concepts/index.html https://docs.google.com/presentation/d/ 1fDeKqhW84pI90AdJWRpvVoAOScHN9fJApp5CCNqge0U/pub? start=false&loop=false&delayms=3000 http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html http://www.programmr.com/extend-box-class-include-color http://docs.oracle.com/javase/tutorial/java/data/strings.html
  • 69.