From b6808d49c38c655ed84abcc94e6c4b989ca07ea9 Mon Sep 17 00:00:00 2001 From: Eugene Fischer Date: Wed, 17 Jun 2020 17:12:55 -0500 Subject: [PATCH] initial commit --- Sorting/WordSortResult.java | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Sorting/WordSortResult.java diff --git a/Sorting/WordSortResult.java b/Sorting/WordSortResult.java new file mode 100644 index 0000000..eecc88a --- /dev/null +++ b/Sorting/WordSortResult.java @@ -0,0 +1,78 @@ +package Sorting; + +import java.time.Duration; +import java.util.Locale; +import java.text.NumberFormat; +/** + * This is a class to hold the efficiencty results of a sorter. We will use this + * because we can only have one return value from a method, but want to get more + * than one piece of data from each sorter. + * + * We will write several constructors for this class, as not all sorting algorithms + * will use all of the fields. For example, radix sort does not use comparisons. + * Counting sort does not use swaps. + * + * Writing several constructors for difference situations is an example of + * "polymorphism" -- the quality of object oriented design that lets a single + * interface have multiple implementations. + * + * The methods that call the constructor of SortResult don't know it has lots of + * them, they only know what data they have to give it. + */ +public class WordSortResult { + + private String sortType; + private String[] sortedArray; + private String comparisonsUsed; + private String writesUsed; + private String timeUsed; + + public WordSortResult(String st, String[] a, long c, long w, Duration t){ + sortType = st; + sortedArray = a; + NumberFormat nf = NumberFormat.getInstance(Locale.US); + if(c==0){ + comparisonsUsed = "No"; + } + else{ + comparisonsUsed = nf.format(c); + } + writesUsed = nf.format(w); + timeUsed = nf.format(t.toMillis()); + } + + + public String getSortType(){ + return sortType; + } + + public String[] getSortedArray(){ + return sortedArray; + } + + public String getTimeUsed(){ + return timeUsed; + } + + public String getComparisonsUsed(){ + return comparisonsUsed; + } + + public String getWritesUsed(){ + return writesUsed; + } + + public String getSortCount(){ + NumberFormat nf = NumberFormat.getInstance(Locale.US); + return nf.format(sortedArray.length); + } + + public String getMin(){ + return sortedArray[0]; + } + + public String getMax(){ + return sortedArray[sortedArray.length-1]; + } + +} \ No newline at end of file