From 8831441ca10edb97e2896174a0031d1aa53e7e3d Mon Sep 17 00:00:00 2001 From: Tien Han Date: Tue, 9 Jan 2024 09:50:37 -0800 Subject: [PATCH 1/5] Add in isUnique method header --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ src/Main.java | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 6f29fee..1acf042 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 930198c..858c16a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,5 +11,13 @@ public static void main(String[] args) { // for you, but you can always add more by pressing . System.out.println("i = " + i); } + + //Quick Test + boolean result = isUnique("always"); + System.out.println(result); + } + + public static boolean isUnique(String word) { + return false; } } \ No newline at end of file From 761a8e2977e2f216d88d88fdab1cce7ca48880d5 Mon Sep 17 00:00:00 2001 From: Tien Han Date: Tue, 9 Jan 2024 10:21:54 -0800 Subject: [PATCH 2/5] Add in functionality for isUnique() --- src/Main.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 858c16a..6cb3bcf 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,5 @@ +import java.util.ArrayList; + //TIP To Run code, press or // click the icon in the gutter. public class Main { @@ -15,9 +17,26 @@ public static void main(String[] args) { //Quick Test boolean result = isUnique("always"); System.out.println(result); + boolean result2 = isUnique("cat"); + System.out.println(result2); } + /** + * isUnique checks if all characters in a given string are unique + * @param word the given string to test + * @return true if string is unique and false if not unique + */ public static boolean isUnique(String word) { - return false; + ArrayList characters = new ArrayList<>(); + + for (int i = 0; i < word.length(); i++) { + Character character = word.charAt(i); + if (characters.contains(character)) { + return false; + } else { + characters.add(character); + } + } + return true; } } \ No newline at end of file From ed3ac585b23233aa898cc171fe3f6f53190e92fb Mon Sep 17 00:00:00 2001 From: Tien Han Date: Wed, 10 Jan 2024 01:16:02 -0800 Subject: [PATCH 3/5] Add additional comments about possible solutions --- src/Main.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Main.java b/src/Main.java index 6cb3bcf..dd996f0 100644 --- a/src/Main.java +++ b/src/Main.java @@ -21,6 +21,10 @@ public static void main(String[] args) { System.out.println(result2); } + //Another way to do this is to use indexOf("a") and lastIndexOf("a") + //If they both return different indexes, then it is not unique + //Another way to do this is the "inchworm" technique, where we look at a character + //And search through the rest of the string to see if it repeats /** * isUnique checks if all characters in a given string are unique * @param word the given string to test From 5779e8ed50d2de6f75b0c1a79f90a104ea6ebf16 Mon Sep 17 00:00:00 2001 From: Tien Han <40409262+tien-han@users.noreply.github.com> Date: Wed, 10 Jan 2024 01:25:45 -0800 Subject: [PATCH 4/5] Create README.md --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..31b9ffb --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# isUnique + +### Description +This repository holds my submission to an assignment for SDEV301 Systems Programming at Green River College. The purpose of this assignment was to review Github forking and provide a light introduction back into algorithms (using Java). + +`isUnique` is an algorithm that takes in a given string and returns `true` if all characters in the string are unique and `false` if they are not. + +For example: +- "cat" would return `true`, as all characters in "cat" are unique. +- "catch" would return `false`, as the character "c" is occurs twice. + +### How to Run the Project +This code can be run as-is with the IntelliJ IDEA IDE from Jetbrains, as long as [Java has been installed](https://www.oracle.com/java/technologies/downloads/) locally. From bc95d285bec1e3ca24a945e6efd894ec7698259f Mon Sep 17 00:00:00 2001 From: Tien Han Date: Thu, 18 Jan 2024 11:45:45 -0800 Subject: [PATCH 5/5] Clean up comments in Main.java --- src/Main.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Main.java b/src/Main.java index dd996f0..936a69c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,16 +1,17 @@ +/** + * SDEV 301: Systems Programming + * + * @author Kendrick Hang, Tien Han + * @version 1.0 + */ + import java.util.ArrayList; -//TIP To Run code, press or -// click the icon in the gutter. public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); + System.out.print("Hello and welcome!"); for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . System.out.println("i = " + i); }