Selaa lähdekoodia

Initial commit

Tom Flucke 10 vuotta sitten
commit
8b6b0f1f45
6 muutettua tiedostoa jossa 110 lisäystä ja 0 poistoa
  1. 1 0
      .gitignore
  2. 6 0
      Lab1/.classpath
  3. 17 0
      Lab1/.project
  4. 12 0
      Lab1/.settings/org.eclipse.jdt.core.prefs
  5. BIN
      Lab1/bin/ListWork.class
  6. 74 0
      Lab1/src/ListWork.java

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.metadata

+ 6 - 0
Lab1/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Lab1/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Lab1</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 12 - 0
Lab1/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+#Mon Sep 21 11:08:00 PDT 2015
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

BIN
Lab1/bin/ListWork.class


+ 74 - 0
Lab1/src/ListWork.java

@@ -0,0 +1,74 @@
+import java.io.InputStreamReader;
+import java.util.Scanner;
+
+
+public class ListWork 
+{
+	
+	public static <T> boolean search(T[] arr, T target)
+	{
+		for (T x: arr)
+		{
+			if(x.equals(target))
+			{
+				return true;
+			}
+		}
+		return false;
+	}
+	
+	public static <T> void print (T[] arr)
+	{
+		for(T x: arr)
+		{
+			System.out.println(x);
+		}
+	}
+	
+	public static void main(String[] args)
+	{
+		Integer[] intArray = new Integer[10];
+		
+		System.out.println("Please input values (at least 10 integers) for this lab project!");
+		
+		Scanner scannerRead = new Scanner(new InputStreamReader(System.in));
+		int index = 0;
+		while (index < 10)
+		{
+			while (!scannerRead.hasNext("\\s"));
+			try
+			{
+				intArray[index] = Integer.parseInt(scannerRead.next("\\s"));
+		    	index ++;
+			}
+			catch (NumberFormatException nfe)
+			{
+				
+			}
+		}
+		if (scannerRead.hasNextLine())
+		{
+			scannerRead.nextLine();
+		}
+		
+		System.out.println("Would you like to search through this array? (y/n)");
+		while (scannerRead.nextLine().equalsIgnoreCase("Y"))
+		{
+			System.out.println("What would you like to search for?");
+
+			try
+			{
+				boolean res = search(intArray, Integer.parseInt(scannerRead.next("\\s")));
+				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.close();
+		print(intArray);
+	}
+	
+}