Explorar el Código

Merge branch 'master' of https://github.com/tflucke/CPE103

Conflicts:
	.gitignore
	Lab1/bin/ListWork.class
	Lab2/bin/Separator.class
	Lab2/src/Separator.java
Tom Flucke hace 10 años
padre
commit
dc4e53cc54
Se han modificado 4 ficheros con 43 adiciones y 28 borrados
  1. 2 1
      .gitignore
  2. BIN
      Lab1/bin/ListWork.class
  3. 29 16
      Lab1/src/ListWork.java
  4. 12 11
      Lab2/src/Separator.java

+ 2 - 1
.gitignore

@@ -1,2 +1,3 @@
 .metadata
-bin/
+.recommenders
+bin/

BIN
Lab1/bin/ListWork.class


+ 29 - 16
Lab1/src/ListWork.java

@@ -1,4 +1,3 @@
-import java.io.InputStreamReader;
 import java.util.Scanner;
 
 
@@ -31,14 +30,15 @@ public class ListWork
 		
 		System.out.println("Please input values (at least 10 integers) for this lab project!");
 		
-		Scanner scannerRead = new Scanner(new InputStreamReader(System.in));
+		Scanner scannerRead = new Scanner(System.in);
+		scannerRead.useDelimiter("\\s+");
 		int index = 0;
 		while (index < 10)
 		{
-			while (!scannerRead.hasNext("\\s"));
+			while (!scannerRead.hasNext());
 			try
 			{
-				intArray[index] = Integer.parseInt(scannerRead.next("\\s"));
+				intArray[index] = Integer.parseInt(scannerRead.next());
 		    	index ++;
 			}
 			catch (NumberFormatException nfe)
@@ -46,26 +46,39 @@ public class ListWork
 				
 			}
 		}
-		if (scannerRead.hasNextLine())
-		{
+		//if (scannerRead.hasNextLine())
+		//{
 			scannerRead.nextLine();
-		}
+		//}
 		
 		System.out.println("Would you like to search through this array? (y/n)");
-		while (scannerRead.nextLine().equalsIgnoreCase("Y"))
+		while(true) //()
 		{
-			System.out.println("What would you like to search for?");
-
-			try
+			String input = scannerRead.next(); 
+			if (input.equalsIgnoreCase("N"))
 			{
-				boolean res = search(intArray, Integer.parseInt(scannerRead.next("\\s")));
-				System.out.println(res? "Found":"Not Found");
+				break;
 			}
-			catch (NumberFormatException nfe)
+			else if (input.equalsIgnoreCase("Y"))
+			{
+				System.out.println("What would you like to search for?");
+
+				try
+				{
+					boolean res = search(intArray, Integer.parseInt(scannerRead.next()));
+					System.out.println(res? "Found":"Not Found");
+				}
+				catch (NumberFormatException nfe)
+				{
+					System.out.println("Not a valid entry");
+				}
+				System.out.println("Would you like to search through this array again? (y/n)");
+				scannerRead.nextLine();
+			}
+			else
 			{
-				System.out.println("Not a valid entry");
+				System.out.println("Invalid input, please try \"y\" or \"n\".");
 			}
-			System.out.println("Would you like to search through this array again? (y/n)");
 		}
 		scannerRead.close();
 		print(intArray);

+ 12 - 11
Lab2/src/Separator.java

@@ -1,8 +1,9 @@
-import java.util.Arrays;
+//import java.util.Arrays;
 import java.util.Scanner;
 
 
 public class Separator {
+	
 
 	public static void main(String[] args) 
 	{
@@ -14,7 +15,7 @@ public class Separator {
 		System.out.println("Please input values here:");
 		
 		Scanner scannerRead = new Scanner(System.in);
-		scannerRead.useDelimiter("\\s");
+		scannerRead.useDelimiter("\\s+");
 		
 		int intIndex = 0;
 		int floatIndex = 0;
@@ -53,19 +54,19 @@ public class Separator {
 			}
 			
 		}
-		
+		scannerRead.close();
 		System.out.println("Abort mission");
-		System.out.print("Integers: ");
-		for (int i : intArray)
+		
+		System.out.print("Integers:");
+		for(int x = 0; x < intIndex; x++)
 		{
-			System.out.print(i+" ");
+			System.out.print(" " + intArray[x]);
 		}
-		System.out.println();
-		System.out.print("Floats: ");
-		for (float f : floatArray)
+		System.out.print("\nFloats:");
+		for(int x = 0; x < floatIndex; x++)
 		{
-			System.out.print(f+" ");
-		}
+			System.out.print(" " + floatArray[x]);
+		}		
 		
 	}