From d6217db9e9769afd6d187c1f669c74e17b9428d7 Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Fri, 10 Nov 2023 13:34:41 -0600 Subject: [PATCH] FindMax --- .gitignore | 1 + .../pom.xml | 14 +++++ .../FindMax.java | 62 +++++++++++++++++++ ...ab_CalebFontenot_MaximumOrderedString.java | 16 +++++ 4 files changed, 93 insertions(+) create mode 100644 Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/pom.xml create mode 100644 Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java create mode 100644 Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/Lab_CalebFontenot_MaximumOrderedString.java diff --git a/.gitignore b/.gitignore index ca7b1f2..c7e40e2 100644 --- a/.gitignore +++ b/.gitignore @@ -193,3 +193,4 @@ /Semester 3/Assignments/LinkedList/nbproject/private/ /Semester 3/Assignments/LinkedList/build/ /Semester 3/Assignments/MP6_CalebFontenot/target/ +/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/target/ diff --git a/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/pom.xml b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/pom.xml new file mode 100644 index 0000000..c95badc --- /dev/null +++ b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + edu.slcc.asdv.caleb + Lab_CalebFontenot_MaximumOrderedString + 1.0-SNAPSHOT + jar + + UTF-8 + 20 + 20 + edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring.Lab_CalebFontenot_MaximumOrderedString + + \ No newline at end of file diff --git a/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java new file mode 100644 index 0000000..47bcc0c --- /dev/null +++ b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java @@ -0,0 +1,62 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Scanner; + +/** + * + * @author caleb + */ +public class FindMax { + public static String findMax(String input) { + ArrayList possibleSubStr = new ArrayList<>(); + String currentStr = ""; + for (int i = 0; i < input.length() -2; ++i) { + currentStr = input.charAt(i) + ""; + for(int j = i + 1; j < input.length() -1; ++j) { + if (input.toLowerCase().charAt(i) < input.toLowerCase().charAt(j)) { + currentStr += input.charAt(j); + } else { + possibleSubStr.add(currentStr); + break; + } + } + } + Collections.sort(possibleSubStr, new CompareSize()); + //System.out.println(possibleSubStr); + return possibleSubStr.get(0); + } + public static void main(String[] args) + { + //System.out.print("Enter a string: "); + //Scanner input = new Scanner(System.in); + String inputString = "abcdabcdefgzabcdefadcdefab"; + //input.nextLine(); + System.out.print("The maximum sorted subString is: "); + System.out.println(findMax(inputString)); + } +} +class CompareSize implements Comparator { + + @Override + public int compare(Object o1, Object o2) + { + int str1 = ((String) o1).length(); + int str2 = ((String) o2).length(); + if (str1 > str2) { + return -1; + } else if(str1 == str2) { + return 0; + } else if (str1 < str2) { + return 1; + } + return Integer.MAX_VALUE; + } + +} \ No newline at end of file diff --git a/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/Lab_CalebFontenot_MaximumOrderedString.java b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/Lab_CalebFontenot_MaximumOrderedString.java new file mode 100644 index 0000000..e5f50d7 --- /dev/null +++ b/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/Lab_CalebFontenot_MaximumOrderedString.java @@ -0,0 +1,16 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + */ + +package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring; + +/** + * + * @author caleb + */ +public class Lab_CalebFontenot_MaximumOrderedString { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +}