SlideShare una empresa de Scribd logo
1 de 9
Descargar para leer sin conexión
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
1 import java.util.ArrayList;
2 import java.util.Scanner;
3 import java.util.Stack;
4
5 import javax.swing.plaf.synth.SynthSeparatorUI;
6
7 //Tori Hoff Integration Project for COP 2006 this is
8 //a collaboration of all of my projects so far
9 public class INtegrationTori {
10
11 public static void main(String[] args) {
12 Scanner keyboard = new Scanner(System.in);
13 System.out.println("Hello this is my integration Project. Everything"
14 + " following is the project i have been working on" + " all year in COP 2006.");
15 String cont = "continue";
16 do {// while loop
17 System.out.println("Please choose the following program you would like to run");
18 System.out.println("1. For Echo on your input");
19 System.out.println("2. for Integer Division");
20 System.out.println("3. For birthday Switch Statement");
21 System.out.println("4. for more integer division");
22 System.out.println("5. for double IF statement");
23 System.out.println("6. for sum of entered digits loop");
24 System.out.println("7. for sum of integers within a number");
25 System.out.println("8. for a for Loop");
26 System.out.println("9. for your favorite number exercise");
27 System.out.println("10. to learn what my favorite song is ");
28 System.out.println("11. for a parallel array on the days in a month ");
29 System.out.println("12. for an array to find the largest integer ");
30 System.out.println("13. stack exercise ");
31 System.out.println("14. to work with strings ");
32 System.out.println("15. For a 2d array ");
33 System.out.println("16. To print the smallest value in an array ");
34 System.out.println("17. For an array list ");
35 System.out.println("18. for example of inheritance");
36
37 try {
38 int project;
39 project = keyboard.nextInt();
40 switch (project) {
41 case 1:
42 echo(keyboard);// keyboard is argument to my call of the echo method
43 break;
44 case 2:
45 integerDivision();
46 break;
47 case 3:
48 findingBirthday(keyboard);
49 break;
50 case 4:
51 divisionIf(keyboard);
52 break;
53 case 5:
54 returnValue();
55 break;
56 case 6:
57 runningTotal(keyboard);
58 break;
59 case 7:
60 getNumber(keyboard);
61 break;
62 case 8:
63 forLoop(keyboard);
64 break;
65 case 9:
66 relational(keyboard);
-1-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
67 break;
68 case 10:
69 Jukebox myjukebox = new Jukebox();// object myjukebox similar to a
70 // call to a special method
71 myjukebox.setSong("Beautiful Soul");// argument
72 myjukebox.play();
73 break;
74 case 11:
75 anArray();
76 break;
77 case 12:
78 largestArray();
79 break;
80 case 13:
81 stackDemo(keyboard);
82 break;
83 case 14:
84 stringPlay(keyboard);
85 break;
86 case 15:
87 arrayTwo();
88 break;
89 case 16:
90 smallestValue();
91 break;
92 case 17:
93 anotherArray(keyboard);
94 break;
95 case 18:
96 inheritance();
97 break;
98 }
99 System.out.println("Thank you for choosing number " + project + " :)");
100 } catch (Exception e) {
101 System.out.println("Error");
102 }
103 System.out.println("Please enter continue to continue the program");
104 cont = keyboard.next();
105 } while (cont.equals("continue"));
106 }
107
108 public static String findingBirthday(Scanner keyboard) {// parameter
109 // switch
110 try {
111 System.out.println("Enter the your birthday month number");
112 int month;
113 month = keyboard.nextInt();
114 String birthdayMonth = "Invalid Input";
115 switch (month) {
116 case 1:
117 birthdayMonth = "January";
118 break;
119 case 2:
120 birthdayMonth = "Febuary";
121 break;
122 case 3:
123 birthdayMonth = "March";
124 break;
125 case 4:
126 birthdayMonth = "April";
127 break;
128 case 5:
129 birthdayMonth = "May";
130 break;
131 case 6:
132 birthdayMonth = "June";
-2-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
133 break;
134 case 7:
135 birthdayMonth = "July";
136 break;
137 case 8:
138 birthdayMonth = "August";
139 break;
140 case 9:
141 birthdayMonth = "September";
142 break;
143 case 10:
144 birthdayMonth = "October";
145 break;
146 case 11:
147 birthdayMonth = "November:";
148 break;
149 case 12:
150 birthdayMonth = "December";
151 break;
152 default:
153 System.out.println("INVALID");
154 }
155 System.out.println("Your birthday is in " + birthdayMonth);
156 return birthdayMonth;
157 } catch (Exception e) {
158 System.out.println("Error");
159 }
160 return null;
161 }
162
163 public static void returnValue() {
164 try {
165 double aNumber = 3;// double if statement and declared variable of type
166 // double to equal 3
167 if (aNumber >= 0) {
168 if (aNumber == 0) {
169 System.out.println("3 is equal to 0");
170 } else {
171 System.out.println("3 is not equal to 0");
172 }
173 }
174 System.out.println("3 is greater than 0");
175 } catch (Exception e) {
176 System.out.println("Error");
177 }
178 }
179
180 public static void divisionIf(Scanner keyboard) {
181 try {
182 System.out.println("Enter any integer (divident): ");
183 double divident = keyboard.nextInt();
184 System.out.println("Enter any integer (divisor): ");
185 double divisor = keyboard.nextInt();
186 System.out.println("The (rounded) answer for " + divident + " divided by " +
divisor + " is: ");
187 if (divisor == 0) {
188 System.out.println("Cannot divide by 0 ");
189 } else {
190 System.out.println(divident / divisor);
191 }
192 } catch (Exception e) {
193 System.out.println("Error");
194 }
195 }
196
197 public static void integerDivision() {
-3-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
198 /*
199 * integer division, (make sure you either use double or a decimal because
200 * an integer divided by an integer does not work all of these 'variables'
201 * that i am assigning numbers to are holding the values that i give them...
202 * they hold value
203 */
204 try {
205 double num1 = 3;
206 double num2 = 15;
207 double num3 = 10;
208 num2 += num3;
209 System.out.println(num2);
210 System.out.println(num2 / num1);
211 System.out.println(++num1 + 1);
212 System.out.println(num1++ + 1);// pay attention to if you do the ++before
213 // or after the variable
214 System.out.println(num1);
215 System.out.println(num2 * num1);
216 } catch (Exception e) {
217 System.out.println("Error");
218 }
219 }
220
221 public static void echo(Scanner keyboard) {
222 System.out.println("Please enter what you want to be echoed: ");
223 String someText = keyboard.next();
224 String echo = "";
225 echo = someText;
226 System.out.println(echo);
227 }
228
229 public static void runningTotal(Scanner keyboard) {
230 try {
231 int numEntered;
232 int numSum = 0;
233 int count = 1;
234 System.out.println("This program will sum the five integers you input");
235 while (count < 6) {
236 System.out.println("Please enter your " + count + "number ");
237 numEntered = keyboard.nextInt();
238 numSum += numEntered;
239 count++;
240 }
241 System.out.println("The total sum is " + numSum);
242 } catch (Exception e) {
243 System.out.println("Error");
244 }
245 }
246
247 public static void getNumber(Scanner keyboard) {
248 System.out.println("This progrm will add up the integers in the" + " number you
enter, please enter a number ");
249 try {
250 int subscript = 0;
251 String numEntered = keyboard.nextLine();
252 int numSum = 0;
253 while (subscript < numEntered.length()) {
254 char aChar = numEntered.charAt(subscript);
255 int x = Character.getNumericValue(aChar);
256 numSum = numSum + x;
257 subscript++;
258 }
259 System.out.println(numSum);
260 } catch (Exception e) {
261 System.out.println("Error");
262 }
-4-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
263 }
264
265 public static void forLoop(Scanner keyboard) {
266 int startNum;
267 try {
268 System.out.println("Enter the number:");
269 startNum = keyboard.nextInt();
270 for (; startNum >= 1; startNum--) {
271 System.out.println(startNum);
272 }
273 } catch (Exception e) {
274 System.out.println("Error");
275 }
276 }
277
278 public static void relational(Scanner keyboard) {
279 int numChoice = 0;
280 try {
281
282 System.out.println("Enter your favorite number");
283 numChoice = keyboard.nextInt();
284 if (numChoice >= 10 || numChoice <= 50) {
285 System.out.println("Your favorite number is between 10 and 50");
286 } else {
287 throw new ArithmeticException();
288 }
289 } catch (ArithmeticException a) {
290 System.out.println("You entered the boring number " + numChoice);
291 } catch (Exception e) {
292 System.out.println("That cant be your favorite number its not a number");
293 }
294 }
295
296 public static void anArray() {
297 int[] numDays = { 31, 28, 31 };
298 String[] months = { "Jan", "Feb", "Mar" };
299 for (int i = 0; i < numDays.length; i++) {
300 System.out.println(months[i] + " has " + numDays[i] + " days");
301 }
302
303 }
304
305 public static void largestArray() {
306 int largest;
307 int sum = 0;
308 int indexOfLargest = 0;
309 int[] array1 = { 100, 200, 300 };
310 largest = array1[0];
311 for (int i = 0; i < array1.length; i++) {
312 if (largest < array1[i]) {
313 sum += array1[i];
314 largest = array1[i];
315 indexOfLargest = i;
316 }
317 }
318
319 System.out.println("Largest: " + largest + " Sum " + sum + "Found at index: " +
indexOfLargest);
320 }
321
322 public static void stackDemo(Scanner keyboard) {
323 try{
324 Stack s = new Stack();
325 int a = 0;
326 int b = 0;
327 System.out.println("Enter number ");
-5-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
328 a = keyboard.nextInt();
329 s.push(a);
330 System.out.println("Stack: " + s);
331 System.out.println("Enter another number ");
332 b = keyboard.nextInt();
333 s.push(b);
334 System.out.println("Stack is now : " + s);
335 }
336 catch(Exception e){
337 System.out.println("Error");
338 }
339
340 }
341
342 public static void stringPlay(Scanner keyboard) {
343 try{
344 String fullName = "";
345 String firstName = "";
346 String lastName = "";
347 System.out.println("Enter the full name:");
348 fullName = keyboard.nextLine();
349
350 System.out.println("The names after split is:");
351
352 String[] split = fullName.split(" ");
353 firstName = split[0];
354 lastName = split[1];
355
356 System.out.println(firstName + "' " + lastName);
357 }
358 catch (Exception e){
359 System.out.println("Error");
360 }
361 }
362
363 public static void arrayTwo() {
364 int search = 2;
365 int[][] math = new int[3][3];
366 for (int i = 0; i < math.length; i++) {
367 for (int j = 0; j < math[i].length; j++) {
368 math[i][j] = i * j;
369 }
370 }
371 for (int i = 0; i < math.length; i++) {
372 for (int j = 0; j < math[i].length; j++) {
373 System.out.print(math[i][j]);
374 }
375 System.out.println();
376 }
377 for (int i = 0; i < math.length; i++) {
378 for (int j = 0; j < math[i].length; j++) {
379 if (search == math[i][j]) {
380 System.out.println(search + " is found at row: " + i + " and column: " + j);
381 }
382
383 }
384 }
385 }
386
387 public static void smallestValue() {
388 int smallest;
389 int[] array1 = { 100, 200, 300 };
390 smallest = array1[0];
391 for (int i = 0; i < array1.length; i++) {
392 if (smallest > array1[i]) {
393 smallest = array1[i];
-6-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
394 }
395 System.out.println("smallest value is: " + smallest);
396 }
397 }
398
399 public static void anotherArray(Scanner keyboard) {
400 ArrayList<String> list = new ArrayList<String>();
401 list.add("Hello");
402 list.add(" my name is ");
403 String name = "";
404 System.out.println("Please enter your name ");
405 name = keyboard.nextLine();
406 list.add(name);
407 System.out.println(list);
408
409 }
410 public static void inheritance() {// this is inheritance because car IS A
411 // machine
412 Car mercedes = new Car();
413 Car bmw = new Car();
414 mercedes.start();
415 mercedes.stop();//object mercedes is using super class machine method stop in
subclass car which is polymorphic
416 mercedes.honk();
417 System.out.println("Your car speed is: ");
418 mercedes.setSpeed(70);
419 System.out.println(mercedes.getSpeed());
420 Machine[] garage = new Machine[2];
421 bmw.setMake("BMW");
422 garage[0] = mercedes;
423 garage[1] = bmw;
424 mercedes.setMake("Mercedes"); //this array shows polymorphism because i can use the
methods
425 //from two different classes together because one is
a super class and one is a subclass
426 System.out.println("Here are the cars in your garage: ");
427 for (int i = 0; i< garage.length; i++){
428 System.out.println(garage[i].getMake());
429 }
430 }
431
432 }// closing brackets leave these
433
434 class Jukebox {
435 String song;
436
437 public void setSong(String s) {// string s is a parameter
438 this.song = s;
439 }// this is a type of object for this song
440
441 public String getSong() {
442 return song;
443 }
444
445 public void play() {
446 System.out.println(getSong());
447 }
448 }
449
450 class Machine {
451 private String make;
452 public void start() {
453 System.out.println("Machine has started");
454 }
455
456 public void stop() {
-7-
C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM
457 System.out.println("Machine has stopped");
458 }
459 public String getMake(){
460 return make;
461 }
462 public void setMake(String car){
463 make = car;
464 }
465 }
466
467 class Car extends Machine {//car IS A machine therefore all following methods car can use
468 //car is polymorphic because it is a type of machine and has multiple inheritance
469 private int speed;
470 public int getSpeed(){
471 return speed;
472 }
473 public void setSpeed(int s){
474 speed = s;
475 }
476
477 public void honk() {
478 System.out.println("Car is honking ");
479 }
480 }
481
-8-
merged_document_3

Más contenido relacionado

La actualidad más candente

CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessThomas Gregory
 
Hashing enderecamento aberto bean - bean
Hashing enderecamento aberto bean - beanHashing enderecamento aberto bean - bean
Hashing enderecamento aberto bean - beanElaine Cecília Gatto
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregoryzakiakhmad
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84Mahmoud Samir Fayed
 
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG CampinasFabio Akita
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA ProgramTrenton Asbury
 
Enjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentEnjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentThiago Fernandes Massa
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harianKhairunnisaPekanbaru
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202Mahmoud Samir Fayed
 
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...Jeroen Baten
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Mumbai B.Sc.IT Study
 
Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPERNikolay Klendar
 

La actualidad más candente (19)

CyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation ProcessCyberLink LabelPrint 2.5 Exploitation Process
CyberLink LabelPrint 2.5 Exploitation Process
 
Hashing enderecamento aberto bean - bean
Hashing enderecamento aberto bean - beanHashing enderecamento aberto bean - bean
Hashing enderecamento aberto bean - bean
 
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom GregoryExploit Development: EzServer Buffer Overflow oleh Tom Gregory
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
 
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.2 book - Part 16 of 84
 
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
 
14 thread
14 thread14 thread
14 thread
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
 
Enjoyable Front-end Development with Reagent
Enjoyable Front-end Development with ReagentEnjoyable Front-end Development with Reagent
Enjoyable Front-end Development with Reagent
 
Fia fabila
Fia fabilaFia fabila
Fia fabila
 
201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian201913001 khairunnisa progres_harian
201913001 khairunnisa progres_harian
 
java assignment
java assignmentjava assignment
java assignment
 
The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202The Ring programming language version 1.8 book - Part 31 of 202
The Ring programming language version 1.8 book - Part 31 of 202
 
54240326 copy
54240326   copy54240326   copy
54240326 copy
 
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
T-DOSE 2015: Using Python, PHP, JQuery and Linux to visualize the heartrate a...
 
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
Internet Technology (Practical Questions Paper) [CBSGS - 75:25 Pattern] {Mast...
 
Security Events correlation with ESPER
Security Events correlation with ESPERSecurity Events correlation with ESPER
Security Events correlation with ESPER
 
Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Network security
Network securityNetwork security
Network security
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 

Similar a merged_document_3 (20)

Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Insertion Sort Code
Insertion Sort CodeInsertion Sort Code
Insertion Sort Code
 
Hashing endereçamento aberto - main
Hashing endereçamento aberto - mainHashing endereçamento aberto - main
Hashing endereçamento aberto - main
 
PSI 3 Integration
PSI 3 IntegrationPSI 3 Integration
PSI 3 Integration
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Comp102 lec 6
Comp102   lec 6Comp102   lec 6
Comp102 lec 6
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Studyx4
Studyx4Studyx4
Studyx4
 
C#.net
C#.netC#.net
C#.net
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 
Network security
Network securityNetwork security
Network security
 
The Art of Clean Code
The Art of Clean CodeThe Art of Clean Code
The Art of Clean Code
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Java practical
Java practicalJava practical
Java practical
 

merged_document_3

  • 1. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 1 import java.util.ArrayList; 2 import java.util.Scanner; 3 import java.util.Stack; 4 5 import javax.swing.plaf.synth.SynthSeparatorUI; 6 7 //Tori Hoff Integration Project for COP 2006 this is 8 //a collaboration of all of my projects so far 9 public class INtegrationTori { 10 11 public static void main(String[] args) { 12 Scanner keyboard = new Scanner(System.in); 13 System.out.println("Hello this is my integration Project. Everything" 14 + " following is the project i have been working on" + " all year in COP 2006."); 15 String cont = "continue"; 16 do {// while loop 17 System.out.println("Please choose the following program you would like to run"); 18 System.out.println("1. For Echo on your input"); 19 System.out.println("2. for Integer Division"); 20 System.out.println("3. For birthday Switch Statement"); 21 System.out.println("4. for more integer division"); 22 System.out.println("5. for double IF statement"); 23 System.out.println("6. for sum of entered digits loop"); 24 System.out.println("7. for sum of integers within a number"); 25 System.out.println("8. for a for Loop"); 26 System.out.println("9. for your favorite number exercise"); 27 System.out.println("10. to learn what my favorite song is "); 28 System.out.println("11. for a parallel array on the days in a month "); 29 System.out.println("12. for an array to find the largest integer "); 30 System.out.println("13. stack exercise "); 31 System.out.println("14. to work with strings "); 32 System.out.println("15. For a 2d array "); 33 System.out.println("16. To print the smallest value in an array "); 34 System.out.println("17. For an array list "); 35 System.out.println("18. for example of inheritance"); 36 37 try { 38 int project; 39 project = keyboard.nextInt(); 40 switch (project) { 41 case 1: 42 echo(keyboard);// keyboard is argument to my call of the echo method 43 break; 44 case 2: 45 integerDivision(); 46 break; 47 case 3: 48 findingBirthday(keyboard); 49 break; 50 case 4: 51 divisionIf(keyboard); 52 break; 53 case 5: 54 returnValue(); 55 break; 56 case 6: 57 runningTotal(keyboard); 58 break; 59 case 7: 60 getNumber(keyboard); 61 break; 62 case 8: 63 forLoop(keyboard); 64 break; 65 case 9: 66 relational(keyboard); -1-
  • 2. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 67 break; 68 case 10: 69 Jukebox myjukebox = new Jukebox();// object myjukebox similar to a 70 // call to a special method 71 myjukebox.setSong("Beautiful Soul");// argument 72 myjukebox.play(); 73 break; 74 case 11: 75 anArray(); 76 break; 77 case 12: 78 largestArray(); 79 break; 80 case 13: 81 stackDemo(keyboard); 82 break; 83 case 14: 84 stringPlay(keyboard); 85 break; 86 case 15: 87 arrayTwo(); 88 break; 89 case 16: 90 smallestValue(); 91 break; 92 case 17: 93 anotherArray(keyboard); 94 break; 95 case 18: 96 inheritance(); 97 break; 98 } 99 System.out.println("Thank you for choosing number " + project + " :)"); 100 } catch (Exception e) { 101 System.out.println("Error"); 102 } 103 System.out.println("Please enter continue to continue the program"); 104 cont = keyboard.next(); 105 } while (cont.equals("continue")); 106 } 107 108 public static String findingBirthday(Scanner keyboard) {// parameter 109 // switch 110 try { 111 System.out.println("Enter the your birthday month number"); 112 int month; 113 month = keyboard.nextInt(); 114 String birthdayMonth = "Invalid Input"; 115 switch (month) { 116 case 1: 117 birthdayMonth = "January"; 118 break; 119 case 2: 120 birthdayMonth = "Febuary"; 121 break; 122 case 3: 123 birthdayMonth = "March"; 124 break; 125 case 4: 126 birthdayMonth = "April"; 127 break; 128 case 5: 129 birthdayMonth = "May"; 130 break; 131 case 6: 132 birthdayMonth = "June"; -2-
  • 3. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 133 break; 134 case 7: 135 birthdayMonth = "July"; 136 break; 137 case 8: 138 birthdayMonth = "August"; 139 break; 140 case 9: 141 birthdayMonth = "September"; 142 break; 143 case 10: 144 birthdayMonth = "October"; 145 break; 146 case 11: 147 birthdayMonth = "November:"; 148 break; 149 case 12: 150 birthdayMonth = "December"; 151 break; 152 default: 153 System.out.println("INVALID"); 154 } 155 System.out.println("Your birthday is in " + birthdayMonth); 156 return birthdayMonth; 157 } catch (Exception e) { 158 System.out.println("Error"); 159 } 160 return null; 161 } 162 163 public static void returnValue() { 164 try { 165 double aNumber = 3;// double if statement and declared variable of type 166 // double to equal 3 167 if (aNumber >= 0) { 168 if (aNumber == 0) { 169 System.out.println("3 is equal to 0"); 170 } else { 171 System.out.println("3 is not equal to 0"); 172 } 173 } 174 System.out.println("3 is greater than 0"); 175 } catch (Exception e) { 176 System.out.println("Error"); 177 } 178 } 179 180 public static void divisionIf(Scanner keyboard) { 181 try { 182 System.out.println("Enter any integer (divident): "); 183 double divident = keyboard.nextInt(); 184 System.out.println("Enter any integer (divisor): "); 185 double divisor = keyboard.nextInt(); 186 System.out.println("The (rounded) answer for " + divident + " divided by " + divisor + " is: "); 187 if (divisor == 0) { 188 System.out.println("Cannot divide by 0 "); 189 } else { 190 System.out.println(divident / divisor); 191 } 192 } catch (Exception e) { 193 System.out.println("Error"); 194 } 195 } 196 197 public static void integerDivision() { -3-
  • 4. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 198 /* 199 * integer division, (make sure you either use double or a decimal because 200 * an integer divided by an integer does not work all of these 'variables' 201 * that i am assigning numbers to are holding the values that i give them... 202 * they hold value 203 */ 204 try { 205 double num1 = 3; 206 double num2 = 15; 207 double num3 = 10; 208 num2 += num3; 209 System.out.println(num2); 210 System.out.println(num2 / num1); 211 System.out.println(++num1 + 1); 212 System.out.println(num1++ + 1);// pay attention to if you do the ++before 213 // or after the variable 214 System.out.println(num1); 215 System.out.println(num2 * num1); 216 } catch (Exception e) { 217 System.out.println("Error"); 218 } 219 } 220 221 public static void echo(Scanner keyboard) { 222 System.out.println("Please enter what you want to be echoed: "); 223 String someText = keyboard.next(); 224 String echo = ""; 225 echo = someText; 226 System.out.println(echo); 227 } 228 229 public static void runningTotal(Scanner keyboard) { 230 try { 231 int numEntered; 232 int numSum = 0; 233 int count = 1; 234 System.out.println("This program will sum the five integers you input"); 235 while (count < 6) { 236 System.out.println("Please enter your " + count + "number "); 237 numEntered = keyboard.nextInt(); 238 numSum += numEntered; 239 count++; 240 } 241 System.out.println("The total sum is " + numSum); 242 } catch (Exception e) { 243 System.out.println("Error"); 244 } 245 } 246 247 public static void getNumber(Scanner keyboard) { 248 System.out.println("This progrm will add up the integers in the" + " number you enter, please enter a number "); 249 try { 250 int subscript = 0; 251 String numEntered = keyboard.nextLine(); 252 int numSum = 0; 253 while (subscript < numEntered.length()) { 254 char aChar = numEntered.charAt(subscript); 255 int x = Character.getNumericValue(aChar); 256 numSum = numSum + x; 257 subscript++; 258 } 259 System.out.println(numSum); 260 } catch (Exception e) { 261 System.out.println("Error"); 262 } -4-
  • 5. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 263 } 264 265 public static void forLoop(Scanner keyboard) { 266 int startNum; 267 try { 268 System.out.println("Enter the number:"); 269 startNum = keyboard.nextInt(); 270 for (; startNum >= 1; startNum--) { 271 System.out.println(startNum); 272 } 273 } catch (Exception e) { 274 System.out.println("Error"); 275 } 276 } 277 278 public static void relational(Scanner keyboard) { 279 int numChoice = 0; 280 try { 281 282 System.out.println("Enter your favorite number"); 283 numChoice = keyboard.nextInt(); 284 if (numChoice >= 10 || numChoice <= 50) { 285 System.out.println("Your favorite number is between 10 and 50"); 286 } else { 287 throw new ArithmeticException(); 288 } 289 } catch (ArithmeticException a) { 290 System.out.println("You entered the boring number " + numChoice); 291 } catch (Exception e) { 292 System.out.println("That cant be your favorite number its not a number"); 293 } 294 } 295 296 public static void anArray() { 297 int[] numDays = { 31, 28, 31 }; 298 String[] months = { "Jan", "Feb", "Mar" }; 299 for (int i = 0; i < numDays.length; i++) { 300 System.out.println(months[i] + " has " + numDays[i] + " days"); 301 } 302 303 } 304 305 public static void largestArray() { 306 int largest; 307 int sum = 0; 308 int indexOfLargest = 0; 309 int[] array1 = { 100, 200, 300 }; 310 largest = array1[0]; 311 for (int i = 0; i < array1.length; i++) { 312 if (largest < array1[i]) { 313 sum += array1[i]; 314 largest = array1[i]; 315 indexOfLargest = i; 316 } 317 } 318 319 System.out.println("Largest: " + largest + " Sum " + sum + "Found at index: " + indexOfLargest); 320 } 321 322 public static void stackDemo(Scanner keyboard) { 323 try{ 324 Stack s = new Stack(); 325 int a = 0; 326 int b = 0; 327 System.out.println("Enter number "); -5-
  • 6. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 328 a = keyboard.nextInt(); 329 s.push(a); 330 System.out.println("Stack: " + s); 331 System.out.println("Enter another number "); 332 b = keyboard.nextInt(); 333 s.push(b); 334 System.out.println("Stack is now : " + s); 335 } 336 catch(Exception e){ 337 System.out.println("Error"); 338 } 339 340 } 341 342 public static void stringPlay(Scanner keyboard) { 343 try{ 344 String fullName = ""; 345 String firstName = ""; 346 String lastName = ""; 347 System.out.println("Enter the full name:"); 348 fullName = keyboard.nextLine(); 349 350 System.out.println("The names after split is:"); 351 352 String[] split = fullName.split(" "); 353 firstName = split[0]; 354 lastName = split[1]; 355 356 System.out.println(firstName + "' " + lastName); 357 } 358 catch (Exception e){ 359 System.out.println("Error"); 360 } 361 } 362 363 public static void arrayTwo() { 364 int search = 2; 365 int[][] math = new int[3][3]; 366 for (int i = 0; i < math.length; i++) { 367 for (int j = 0; j < math[i].length; j++) { 368 math[i][j] = i * j; 369 } 370 } 371 for (int i = 0; i < math.length; i++) { 372 for (int j = 0; j < math[i].length; j++) { 373 System.out.print(math[i][j]); 374 } 375 System.out.println(); 376 } 377 for (int i = 0; i < math.length; i++) { 378 for (int j = 0; j < math[i].length; j++) { 379 if (search == math[i][j]) { 380 System.out.println(search + " is found at row: " + i + " and column: " + j); 381 } 382 383 } 384 } 385 } 386 387 public static void smallestValue() { 388 int smallest; 389 int[] array1 = { 100, 200, 300 }; 390 smallest = array1[0]; 391 for (int i = 0; i < array1.length; i++) { 392 if (smallest > array1[i]) { 393 smallest = array1[i]; -6-
  • 7. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 394 } 395 System.out.println("smallest value is: " + smallest); 396 } 397 } 398 399 public static void anotherArray(Scanner keyboard) { 400 ArrayList<String> list = new ArrayList<String>(); 401 list.add("Hello"); 402 list.add(" my name is "); 403 String name = ""; 404 System.out.println("Please enter your name "); 405 name = keyboard.nextLine(); 406 list.add(name); 407 System.out.println(list); 408 409 } 410 public static void inheritance() {// this is inheritance because car IS A 411 // machine 412 Car mercedes = new Car(); 413 Car bmw = new Car(); 414 mercedes.start(); 415 mercedes.stop();//object mercedes is using super class machine method stop in subclass car which is polymorphic 416 mercedes.honk(); 417 System.out.println("Your car speed is: "); 418 mercedes.setSpeed(70); 419 System.out.println(mercedes.getSpeed()); 420 Machine[] garage = new Machine[2]; 421 bmw.setMake("BMW"); 422 garage[0] = mercedes; 423 garage[1] = bmw; 424 mercedes.setMake("Mercedes"); //this array shows polymorphism because i can use the methods 425 //from two different classes together because one is a super class and one is a subclass 426 System.out.println("Here are the cars in your garage: "); 427 for (int i = 0; i< garage.length; i++){ 428 System.out.println(garage[i].getMake()); 429 } 430 } 431 432 }// closing brackets leave these 433 434 class Jukebox { 435 String song; 436 437 public void setSong(String s) {// string s is a parameter 438 this.song = s; 439 }// this is a type of object for this song 440 441 public String getSong() { 442 return song; 443 } 444 445 public void play() { 446 System.out.println(getSong()); 447 } 448 } 449 450 class Machine { 451 private String make; 452 public void start() { 453 System.out.println("Machine has started"); 454 } 455 456 public void stop() { -7-
  • 8. C:UsersToriworkspaceIntegrationTorisrcINtegrationTori.java Thursday, April 14, 2016 5:11 PM 457 System.out.println("Machine has stopped"); 458 } 459 public String getMake(){ 460 return make; 461 } 462 public void setMake(String car){ 463 make = car; 464 } 465 } 466 467 class Car extends Machine {//car IS A machine therefore all following methods car can use 468 //car is polymorphic because it is a type of machine and has multiple inheritance 469 private int speed; 470 public int getSpeed(){ 471 return speed; 472 } 473 public void setSpeed(int s){ 474 speed = s; 475 } 476 477 public void honk() { 478 System.out.println("Car is honking "); 479 } 480 } 481 -8-