Skip to content

Commit

Permalink
mild fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JishnuS420 committed Apr 16, 2024
1 parent 199914d commit 6381940
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions _notebooks/2024-04-03-Algorhytmic-Blog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -107,42 +107,41 @@
"\n",
"public class Algorhytmic {\n",
"\n",
" static class Collectable implements Comparable<Collectable> {\n",
" public static class Collectable implements Comparable<Collectable> { // Comparable allows for instances of Collectable to be compared with eachother by using compareto \n",
" int number;\n",
" String name;\n",
" String classroom;\n",
"\n",
" public Collectable(int number, String name, String classroom) {\n",
" public Collectable(int number, String name, String classroom) { // Constructors\n",
" this.number = number;\n",
" this.name = name;\n",
" this.classroom = classroom;\n",
" }\n",
"\n",
" @Override\n",
" public int compareTo(Collectable other) {\n",
" return this.name.compareToIgnoreCase(other.name);\n",
" public int compareTo(Collectable other) { // Returns as integers\n",
" return this.name.compareToIgnoreCase(other.name); // This overrides the compareto method to enable one collectable object to another collectable object\n",
" }\n",
"\n",
" @Override\n",
" public String toString() {\n",
" return \"{\\\"number\\\":\" + number + \", \\\"name\\\":\\\"\" + name + \"\\\", \\\"classroom\\\":\\\"\" + classroom + \"\\\"}\";\n",
" public String toString() { \n",
" return \"{\\\"number\\\":\" + number + \", \\\"name\\\":\\\"\" + name + \"\\\", \\\"classroom\\\":\\\"\" + classroom + \"\\\"}\"; // Overrides the toString method so it concats and displays in JSON format\n",
" }\n",
" }\n",
"\n",
" static class FlowerGroup {\n",
" ArrayList<Collectable> members;\n",
" ArrayList<Collectable> members; // Declares than the ArrayList members holds instances of Collectables\n",
"\n",
" public FlowerGroup(ArrayList<Collectable> members) {\n",
" this.members = members;\n",
" public FlowerGroup(ArrayList<Collectable> members) { // Constructors\n",
" this.members = members; \n",
" }\n",
"\n",
" // Bubble Sort\n",
" public void bubbleSort() {\n",
" int n = members.size();\n",
" int n = members.size(); // takes the number of objects in the members arrayList\n",
" for (int i = 0; i < n - 1; i++) {\n",
" for (int j = 0; j < n - i - 1; j++) {\n",
" if (members.get(j).compareTo(members.get(j + 1)) > 0) {\n",
" // Swap members[j] and members[j+1]\n",
" Collectable temp = members.get(j);\n",
" members.set(j, members.get(j + 1));\n",
" members.set(j + 1, temp);\n",
Expand Down Expand Up @@ -259,9 +258,11 @@
" return result.toString();\n",
" }\n",
" }\n",
" \n",
" public static void main(String[] args) { // setting up tester data\n",
"\n",
" public static void main(String[] args) {\n",
" ArrayList<Collectable> members = new ArrayList<>();\n",
"\n",
" members.add(new Collectable(1, \"Alara\", \"CSP\"));\n",
" members.add(new Collectable(2, \"Abigail\", \"CSP\"));\n",
" members.add(new Collectable(3, \"Aditi\", \"CSP\"));\n",
Expand Down Expand Up @@ -311,7 +312,7 @@
" }\n",
"}\n",
"\n",
"Algorhytmic.main(null)\n"
"Algorhytmic.main(null)"
]
},
{
Expand Down

0 comments on commit 6381940

Please sign in to comment.