From 90dde683c937e0abeebf3849682ece05a052eff4 Mon Sep 17 00:00:00 2001 From: rohitde Date: Thu, 27 Apr 2023 08:37:38 -0700 Subject: [PATCH] labhacks car simultion random test --- .vscode/configurationCache.log | 2 +- .vscode/dryrun.log | 1 - .vscode/targets.log | 17 +- _notebooks/2023-03-27-chck2chall3.ipynb | 2 +- _notebooks/2023-04-01-sortalgo.ipynb | 26 +- _notebooks/2023-04-21-try3.ipynb | 288 ++++++++++++++++++++++ _notebooks/2023-04-24-carparts123.ipynb | 190 +++++++++++++++ _notebooks/2023-04-26-labhacks.ipynb | 312 ++++++++++++++++++++++++ 8 files changed, 804 insertions(+), 34 deletions(-) create mode 100644 _notebooks/2023-04-21-try3.ipynb create mode 100644 _notebooks/2023-04-24-carparts123.ipynb create mode 100644 _notebooks/2023-04-26-labhacks.ipynb diff --git a/.vscode/configurationCache.log b/.vscode/configurationCache.log index dde4830..58acd29 100644 --- a/.vscode/configurationCache.log +++ b/.vscode/configurationCache.log @@ -1 +1 @@ -{"buildTargets":[".FORCE","bash-jekyll","bash-nb","build","convert","help","quick-build","remove","restart-jekyll","server","server-detached","stop"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} \ No newline at end of file +{"buildTargets":[".FORCE","bash-jekyll","bash-nb","build","convert","help","make","quick-build","remove","restart-jekyll","server","server-detached","stop"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} \ No newline at end of file diff --git a/.vscode/dryrun.log b/.vscode/dryrun.log index 9aa6609..0e350c1 100644 --- a/.vscode/dryrun.log +++ b/.vscode/dryrun.log @@ -1,6 +1,5 @@ make --dry-run --always-make --keep-going --print-directory make: Entering directory `/Users/rohitde/vscode/rohitfastpages' cat Makefile - make: Leaving directory `/Users/rohitde/vscode/rohitfastpages' diff --git a/.vscode/targets.log b/.vscode/targets.log index 9b819c3..0cf244e 100644 --- a/.vscode/targets.log +++ b/.vscode/targets.log @@ -6,11 +6,8 @@ make all --print-data-base --no-builtin-variables --no-builtin-rules --question # PARTICULAR PURPOSE. # This program built for i386-apple-darwin11.3.0 - -make: *** No rule to make target `all'. Stop. - -# Make data base, printed on Fri Apr 7 04:19:50 2023 +# Make data base, printed on Thu Apr 27 08:35:07 2023 # Variables @@ -30,7 +27,6 @@ CURDIR := /Users/rohitde/vscode/rohitfastpages SHELL = /bin/sh # environment VSCODE_NLS_CONFIG = {"locale":"en-us","availableLanguages":{},"_languagePackSupport":true} - # environment _ = /usr/bin/make # makefile (from `Makefile', line 1) @@ -48,7 +44,7 @@ ELECTRON_RUN_AS_NODE = 1 # default .FEATURES := target-specific order-only second-expansion else-if archives jobserver check-symlink # environment -SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.pIqKLmTJyv/Listeners +SSH_AUTH_SOCK = /private/tmp/com.apple.launchd.dIE07Qcxsl/Listeners # automatic %F = $(notdir $%) # environment @@ -131,7 +127,6 @@ HOMEBREW_REPOSITORY = /opt/homebrew __CF_USER_TEXT_ENCODING = 0x1F5:0x0:0x0 # environment COMMAND_MODE = unix2003 - # default MAKEFILES := # automatic @@ -151,7 +146,7 @@ MAKELEVEL := 0 # environment CONDA_PREFIX = /Users/rohitde/opt/anaconda3 # environment -VSCODE_PID = 1692 +VSCODE_PID = 2770 # environment _CE_CONDA = # environment @@ -216,7 +211,6 @@ server-detached: .FORCE docker-compose up -d - # Not a target: Makefile: # Implicit rule search has been done. @@ -321,8 +315,11 @@ convert: .FORCE # # of strings in strcache: 1 # # of strcache buffers: 1 # strcache size: total = 4096 / max = 4096 / min = 4096 / avg = 4096 + +make: *** No rule to make target `all'. Stop. + # strcache free: total = 4087 / max = 4087 / min = 4087 / avg = 4087 -# Finished Make data base on Fri Apr 7 04:19:50 2023 +# Finished Make data base on Thu Apr 27 08:35:07 2023 diff --git a/_notebooks/2023-03-27-chck2chall3.ipynb b/_notebooks/2023-03-27-chck2chall3.ipynb index 55f8aac..fea7be9 100644 --- a/_notebooks/2023-03-27-chck2chall3.ipynb +++ b/_notebooks/2023-03-27-chck2chall3.ipynb @@ -1 +1 @@ -{"cells":[{"attachments":{},"cell_type":"markdown","metadata":{},"source":["# Challenge 3\n","> Generics and Collections\n","\n","- toc: true \n","- comments: true\n","- categories: [java]"]},{"cell_type":"code","execution_count":5,"metadata":{"vscode":{"languageId":"java"}},"outputs":[],"source":["/**\n"," * Implementation of a Double Linked List; forward and backward links point to adjacent Nodes.\n"," *\n"," */\n","\n"," public class LinkedList\n"," {\n"," private T data;\n"," private LinkedList prevNode, nextNode;\n"," \n"," /**\n"," * Constructs a new element\n"," *\n"," * @param data, data of object\n"," * @param node, previous node\n"," */\n"," public LinkedList(T data, LinkedList node)\n"," {\n"," this.setData(data);\n"," this.setPrevNode(node);\n"," this.setNextNode(null);\n"," }\n"," \n"," /**\n"," * Clone an object,\n"," *\n"," * @param node object to clone\n"," */\n"," public LinkedList(LinkedList node)\n"," {\n"," this.setData(node.data);\n"," this.setPrevNode(node.prevNode);\n"," this.setNextNode(node.nextNode);\n"," }\n"," \n"," /**\n"," * Setter for T data in DoubleLinkedNode object\n"," *\n"," * @param data, update data of object\n"," */\n"," public void setData(T data)\n"," {\n"," this.data = data;\n"," }\n"," \n"," /**\n"," * Returns T data for this element\n"," *\n"," * @return data associated with object\n"," */\n"," public T getData()\n"," {\n"," return this.data;\n"," }\n"," \n"," /**\n"," * Setter for prevNode in DoubleLinkedNode object\n"," *\n"," * @param node, prevNode to current Object\n"," */\n"," public void setPrevNode(LinkedList node)\n"," {\n"," this.prevNode = node;\n"," }\n"," \n"," /**\n"," * Setter for nextNode in DoubleLinkedNode object\n"," *\n"," * @param node, nextNode to current Object\n"," */\n"," public void setNextNode(LinkedList node)\n"," {\n"," this.nextNode = node;\n"," }\n"," \n"," \n"," /**\n"," * Returns reference to previous object in list\n"," *\n"," * @return the previous object in the list\n"," */\n"," public LinkedList getPrevious()\n"," {\n"," return this.prevNode;\n"," }\n"," \n"," /**\n"," * Returns reference to next object in list\n"," *\n"," * @return the next object in the list\n"," */\n"," public LinkedList getNext()\n"," {\n"," return this.nextNode;\n"," }\n"," \n"," }"]},{"cell_type":"code","execution_count":6,"metadata":{"vscode":{"languageId":"java"}},"outputs":[],"source":["/**\n"," * Queue Iterator\n"," *\n"," * 1. \"has a\" current reference in Queue\n"," * 2. supports iterable required methods for next that returns a generic T Object\n"," */\n","class QueueIterator implements Iterator {\n"," LinkedList current; // current element in iteration\n","\n"," // QueueIterator is pointed to the head of the list for iteration\n"," public QueueIterator(LinkedList head) {\n"," current = head;\n"," }\n","\n"," // hasNext informs if next element exists\n"," public boolean hasNext() {\n"," return current != null;\n"," }\n","\n"," // next returns data object and advances to next position in queue\n"," public T next() {\n"," T data = current.getData();\n"," current = current.getNext();\n"," return data;\n"," }\n","}\n","\n","/**\n"," * Queue: custom implementation\n"," * @author John Mortensen\n"," *\n"," * 1. Uses custom LinkedList of Generic type T\n"," * 2. Implements Iterable\n"," * 3. \"has a\" LinkedList for head and tail\n"," */\n","public class Queue implements Iterable {\n"," LinkedList head = null, tail = null;\n","\n"," /**\n"," * Add a new object at the end of the Queue,\n"," *\n"," * @param data, is the data to be inserted in the Queue.\n"," */\n"," public void add(T data) {\n"," // add new object to end of Queue\n"," LinkedList tail = new LinkedList<>(data, null);\n","\n"," if (this.head == null) // initial condition\n"," this.head = this.tail = tail;\n"," else { // nodes in queue\n"," this.tail.setNextNode(tail); // current tail points to new tail\n"," this.tail = tail; // update tail\n"," }\n"," }\n","\n"," /**\n"," * Returns the data of head.\n"," *\n"," * @return data, the dequeued data\n"," */\n"," public T delete() {\n"," T data = this.peek();\n"," if (this.tail != null) { // initial condition\n"," this.head = this.head.getNext(); // current tail points to new tail\n"," if (this.head != null) {\n"," this.head.setPrevNode(tail);\n"," }\n"," }\n"," return data;\n"," }\n","\n"," /**\n"," * Get the number of elements in the Queue.\n"," */\n"," public int size() {\n"," int count = 0;\n"," for (T data : this) {\n"," count++;\n"," }\n"," return count;\n"," }\n","\n"," /* \n"," * Returns true if Queue is empty.\n"," */\n"," public boolean isEmpty() {\n"," return this.head == null;\n"," }\n","\n"," /**\n"," * Return data in Queue.\n"," */\n"," public String toString() {\n"," String str = \"\";\n"," for (T data : this) {\n"," str += data + \" \";\n"," }\n"," return str;\n"," }\n","\n"," /**\n"," * Returns data as List.\n"," */\n"," public List asList() {\n"," List list = new ArrayList<>();\n"," for (T data : this) {\n"," list.add(data);\n"," }\n"," return list;\n"," }\n","\n"," /**\n"," * Returns the data of head.\n"," *\n"," * @return this.head.getData(), the head data in Queue.\n"," */\n"," public T peek() {\n"," return this.head.getData();\n"," }\n","\n"," /**\n"," * Returns the head object.\n"," *\n"," * @return this.head, the head object in Queue.\n"," */\n"," public LinkedList getHead() {\n"," return this.head;\n"," }\n","\n"," /**\n"," * Returns the tail object.\n"," *\n"," * @return this.tail, the last object in Queue\n"," */\n"," public LinkedList getTail() {\n"," return this.tail;\n"," }\n","\n"," /**\n"," * Returns the iterator object.\n"," *\n"," * @return this, instance of object\n"," */\n"," public Iterator iterator() {\n"," return new QueueIterator<>(this.head);\n"," }\n","}"]},{"cell_type":"code","execution_count":7,"metadata":{"vscode":{"languageId":"java"}},"outputs":[],"source":["/**\n"," * Queue Manager\n"," * 1. \"has a\" Queue\n"," * 2. support management of Queue tasks (aka: titling, adding a list, printing)\n"," */\n","class QueueManager {\n"," // queue data\n"," private final String name; // name of queue\n"," private int count = 0; // number of objects in queue\n"," public final Queue queue = new Queue<>(); // queue object\n","\n"," /**\n"," * Queue constructor\n"," * Title with empty queue\n"," */\n"," public QueueManager(String name) {\n"," this.name = name;\n"," }\n","\n"," /**\n"," * Queue constructor\n"," * Title with series of Arrays of Objects\n"," */\n"," public QueueManager(String name, T[]... seriesOfObjects) {\n"," this.name = name;\n"," this.addList(seriesOfObjects);\n"," }\n","\n"," /**\n"," * Add an element to queue\n"," */\n"," public void add(T data) {\n"," System.out.println(\"Enqueued data: \" + data);\n"," this.queue.add(data);\n"," this.count++;\n"," }\n","\n"," /**\n"," * Add a list of objects to queue\n"," */\n"," public void addList(T[]... seriesOfObjects) { //accepts multiple generic T lists\n"," for (T[] objects: seriesOfObjects)\n"," for (T data : objects) {\n"," this.queue.add(data);\n"," this.count++;\n"," }\n"," }\n","\n"," /**\n"," * Delete an element from queue\n"," */\n"," public void delete() {\n"," // print data else print null\n"," System.out.println(\"Dequeued data: \" + this.queue.delete());\n"," this.count--;\n"," }\n","\n"," /**\n"," * Print any array objects from queue\n"," */\n"," public void printQueue() {\n"," System.out.print(this.name + \" count: \" + count + \"\\n\" + \"Data: \");\n"," for (T data : queue)\n"," System.out.print(data + \" \");\n"," System.out.println();\n"," }\n","}"]},{"cell_type":"code","execution_count":14,"metadata":{"vscode":{"languageId":"java"}},"outputs":[{"name":"stdout","output_type":"stream","text":["Numbers count: 10\n","Data: 1 2 3 4 5 6 7 8 9 10 \n","Shuffled count: 10\n","Data: 9 6 8 10 2 1 4 3 7 5 \n","Enqueued data: Serendipity\n","Enqueued data: Quixotic\n","Enqueued data: Melancholy\n","Enqueued data: Perfidious\n","Words count: 5\n","Data: Ephemeral Serendipity Quixotic Melancholy Perfidious \n","Shuffled count: 5\n","Data: Serendipity Quixotic Ephemeral Perfidious Melancholy \n"]}],"source":["public class ShuffleQueue {\n","\n"," public static QueueManager shuffle(QueueManager q) {\n"," // convert the QueueManager to an ArrayList\n"," List list = new ArrayList(q.queue.asList());\n"," // Shuffle the ArrayList\n"," Collections.shuffle(list);\n"," // creating a new QueueManager with the shuffled elements\n"," QueueManager shuffled = new QueueManager(\"Shuffled\");\n"," shuffled.addList(list.toArray());\n"," return shuffled;\n"," }\n","\n"," public static void main(String[] args) {\n"," // array of integers\n"," Object[] numbers = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n"," // creating a QueueManager with the integers\n"," QueueManager q = new QueueManager(\"Numbers\", numbers);\n","\n"," q.printQueue();\n"," QueueManager shuffled = shuffle(q);\n"," shuffled.printQueue();\n"," \n"," // array of strings\n"," Object[] words = new String[] { \"Ephemeral\" };\n"," // creating a QueueManager with the string array\n"," QueueManager qw = new QueueManager(\"Words\", words);\n","\n"," qw.add(\"Serendipity\");\n"," qw.add(\"Quixotic\");\n"," qw.add(\"Melancholy\");\n"," qw.add(\"Perfidious\");\n","\n"," qw.printQueue();\n"," // shuffling the queue and store the result in a new QueueManager\n"," QueueManager shuffledwords = shuffle(qw);\n"," shuffledwords.printQueue();\n"," }\n","}\n","\n","ShuffleQueue.main(null);"]}],"metadata":{"kernelspec":{"display_name":"Java","language":"java","name":"java"},"language_info":{"codemirror_mode":"java","file_extension":".jshell","mimetype":"text/x-java-source","name":"Java","pygments_lexer":"java","version":"19.0.2+7-44"},"orig_nbformat":4},"nbformat":4,"nbformat_minor":2} +{"cells":[{"attachments":{},"cell_type":"markdown","metadata":{},"source":["# Challenge 3\n","> Generics and Collections\n","\n","- toc: true \n","- comments: true\n","- categories: [java]"]},{"cell_type":"code","execution_count":5,"metadata":{},"outputs":[],"source":["/**\n"," * Implementation of a Double Linked List; forward and backward links point to adjacent Nodes.\n"," *\n"," */\n","\n"," public class LinkedList\n"," {\n"," private T data;\n"," private LinkedList prevNode, nextNode;\n"," \n"," /**\n"," * Constructs a new element\n"," *\n"," * @param data, data of object\n"," * @param node, previous node\n"," */\n"," public LinkedList(T data, LinkedList node)\n"," {\n"," this.setData(data);\n"," this.setPrevNode(node);\n"," this.setNextNode(null);\n"," }\n"," \n"," /**\n"," * Clone an object,\n"," *\n"," * @param node object to clone\n"," */\n"," public LinkedList(LinkedList node)\n"," {\n"," this.setData(node.data);\n"," this.setPrevNode(node.prevNode);\n"," this.setNextNode(node.nextNode);\n"," }\n"," \n"," /**\n"," * Setter for T data in DoubleLinkedNode object\n"," *\n"," * @param data, update data of object\n"," */\n"," public void setData(T data)\n"," {\n"," this.data = data;\n"," }\n"," \n"," /**\n"," * Returns T data for this element\n"," *\n"," * @return data associated with object\n"," */\n"," public T getData()\n"," {\n"," return this.data;\n"," }\n"," \n"," /**\n"," * Setter for prevNode in DoubleLinkedNode object\n"," *\n"," * @param node, prevNode to current Object\n"," */\n"," public void setPrevNode(LinkedList node)\n"," {\n"," this.prevNode = node;\n"," }\n"," \n"," /**\n"," * Setter for nextNode in DoubleLinkedNode object\n"," *\n"," * @param node, nextNode to current Object\n"," */\n"," public void setNextNode(LinkedList node)\n"," {\n"," this.nextNode = node;\n"," }\n"," \n"," \n"," /**\n"," * Returns reference to previous object in list\n"," *\n"," * @return the previous object in the list\n"," */\n"," public LinkedList getPrevious()\n"," {\n"," return this.prevNode;\n"," }\n"," \n"," /**\n"," * Returns reference to next object in list\n"," *\n"," * @return the next object in the list\n"," */\n"," public LinkedList getNext()\n"," {\n"," return this.nextNode;\n"," }\n"," \n"," }"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[],"source":["/**\n"," * Queue Iterator\n"," *\n"," * 1. \"has a\" current reference in Queue\n"," * 2. supports iterable required methods for next that returns a generic T Object\n"," */\n","class QueueIterator implements Iterator {\n"," LinkedList current; // current element in iteration\n","\n"," // QueueIterator is pointed to the head of the list for iteration\n"," public QueueIterator(LinkedList head) {\n"," current = head;\n"," }\n","\n"," // hasNext informs if next element exists\n"," public boolean hasNext() {\n"," return current != null;\n"," }\n","\n"," // next returns data object and advances to next position in queue\n"," public T next() {\n"," T data = current.getData();\n"," current = current.getNext();\n"," return data;\n"," }\n","}\n","\n","/**\n"," * Queue: custom implementation\n"," * @author John Mortensen\n"," *\n"," * 1. Uses custom LinkedList of Generic type T\n"," * 2. Implements Iterable\n"," * 3. \"has a\" LinkedList for head and tail\n"," */\n","public class Queue implements Iterable {\n"," LinkedList head = null, tail = null;\n","\n"," /**\n"," * Add a new object at the end of the Queue,\n"," *\n"," * @param data, is the data to be inserted in the Queue.\n"," */\n"," public void add(T data) {\n"," // add new object to end of Queue\n"," LinkedList tail = new LinkedList<>(data, null);\n","\n"," if (this.head == null) // initial condition\n"," this.head = this.tail = tail;\n"," else { // nodes in queue\n"," this.tail.setNextNode(tail); // current tail points to new tail\n"," this.tail = tail; // update tail\n"," }\n"," }\n","\n"," /**\n"," * Returns the data of head.\n"," *\n"," * @return data, the dequeued data\n"," */\n"," public T delete() {\n"," T data = this.peek();\n"," if (this.tail != null) { // initial condition\n"," this.head = this.head.getNext(); // current tail points to new tail\n"," if (this.head != null) {\n"," this.head.setPrevNode(tail);\n"," }\n"," }\n"," return data;\n"," }\n","\n"," /**\n"," * Get the number of elements in the Queue.\n"," */\n"," public int size() {\n"," int count = 0;\n"," for (T data : this) {\n"," count++;\n"," }\n"," return count;\n"," }\n","\n"," /* \n"," * Returns true if Queue is empty.\n"," */\n"," public boolean isEmpty() {\n"," return this.head == null;\n"," }\n","\n"," /**\n"," * Return data in Queue.\n"," */\n"," public String toString() {\n"," String str = \"\";\n"," for (T data : this) {\n"," str += data + \" \";\n"," }\n"," return str;\n"," }\n","\n"," /**\n"," * Returns data as List.\n"," */\n"," public List asList() {\n"," List list = new ArrayList<>();\n"," for (T data : this) {\n"," list.add(data);\n"," }\n"," return list;\n"," }\n","\n"," /**\n"," * Returns the data of head.\n"," *\n"," * @return this.head.getData(), the head data in Queue.\n"," */\n"," public T peek() {\n"," return this.head.getData();\n"," }\n","\n"," /**\n"," * Returns the head object.\n"," *\n"," * @return this.head, the head object in Queue.\n"," */\n"," public LinkedList getHead() {\n"," return this.head;\n"," }\n","\n"," /**\n"," * Returns the tail object.\n"," *\n"," * @return this.tail, the last object in Queue\n"," */\n"," public LinkedList getTail() {\n"," return this.tail;\n"," }\n","\n"," /**\n"," * Returns the iterator object.\n"," *\n"," * @return this, instance of object\n"," */\n"," public Iterator iterator() {\n"," return new QueueIterator<>(this.head);\n"," }\n","}"]},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[],"source":["/**\n"," * Queue Manager\n"," * 1. \"has a\" Queue\n"," * 2. support management of Queue tasks (aka: titling, adding a list, printing)\n"," */\n","class QueueManager {\n"," // queue data\n"," private final String name; // name of queue\n"," private int count = 0; // number of objects in queue\n"," public final Queue queue = new Queue<>(); // queue object\n","\n"," /**\n"," * Queue constructor\n"," * Title with empty queue\n"," */\n"," public QueueManager(String name) {\n"," this.name = name;\n"," }\n","\n"," /**\n"," * Queue constructor\n"," * Title with series of Arrays of Objects\n"," */\n"," public QueueManager(String name, T[]... seriesOfObjects) {\n"," this.name = name;\n"," this.addList(seriesOfObjects);\n"," }\n","\n"," /**\n"," * Add an element to queue\n"," */\n"," public void add(T data) {\n"," System.out.println(\"Enqueued data: \" + data);\n"," this.queue.add(data);\n"," this.count++;\n"," }\n","\n"," /**\n"," * Add a list of objects to queue\n"," */\n"," public void addList(T[]... seriesOfObjects) { //accepts multiple generic T lists\n"," for (T[] objects: seriesOfObjects)\n"," for (T data : objects) {\n"," this.queue.add(data);\n"," this.count++;\n"," }\n"," }\n","\n"," /**\n"," * Delete an element from queue\n"," */\n"," public void delete() {\n"," // print data else print null\n"," System.out.println(\"Dequeued data: \" + this.queue.delete());\n"," this.count--;\n"," }\n","\n"," /**\n"," * Print any array objects from queue\n"," */\n"," public void printQueue() {\n"," System.out.print(this.name + \" count: \" + count + \"\\n\" + \"Data: \");\n"," for (T data : queue)\n"," System.out.print(data + \" \");\n"," System.out.println();\n"," }\n","}"]},{"cell_type":"code","execution_count":14,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Numbers count: 10\n","Data: 1 2 3 4 5 6 7 8 9 10 \n","Shuffled count: 10\n","Data: 9 6 8 10 2 1 4 3 7 5 \n","Enqueued data: Serendipity\n","Enqueued data: Quixotic\n","Enqueued data: Melancholy\n","Enqueued data: Perfidious\n","Words count: 5\n","Data: Ephemeral Serendipity Quixotic Melancholy Perfidious \n","Shuffled count: 5\n","Data: Serendipity Quixotic Ephemeral Perfidious Melancholy \n"]}],"source":["public class ShuffleQueue {\n","\n"," public static QueueManager shuffle(QueueManager q) {\n"," // convert the QueueManager to an ArrayList\n"," List list = new ArrayList(q.queue.asList());\n"," // Shuffle the ArrayList\n"," Collections.shuffle(list);\n"," // creating a new QueueManager with the shuffled elements\n"," QueueManager shuffled = new QueueManager(\"Shuffled\");\n"," shuffled.addList(list.toArray());\n"," return shuffled;\n"," }\n","\n"," public static void main(String[] args) {\n"," // array of integers\n"," Object[] numbers = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };\n"," // creating a QueueManager with the integers\n"," QueueManager q = new QueueManager(\"Numbers\", numbers);\n","\n"," q.printQueue();\n"," QueueManager shuffled = shuffle(q);\n"," shuffled.printQueue();\n"," \n"," // array of strings\n"," Object[] words = new String[] { \"Ephemeral\" };\n"," // creating a QueueManager with the string array\n"," QueueManager qw = new QueueManager(\"Words\", words);\n","\n"," qw.add(\"Serendipity\");\n"," qw.add(\"Quixotic\");\n"," qw.add(\"Melancholy\");\n"," qw.add(\"Perfidious\");\n","\n"," qw.printQueue();\n"," // shuffling the queue and store the result in a new QueueManager\n"," QueueManager shuffledwords = shuffle(qw);\n"," shuffledwords.printQueue();\n"," }\n","}\n","\n","ShuffleQueue.main(null);"]}],"metadata":{"kernelspec":{"display_name":"Java","language":"java","name":"java"},"language_info":{"codemirror_mode":"java","file_extension":".jshell","mimetype":"text/x-java-source","name":"java","pygments_lexer":"java","version":"19.0.2+7-44"},"orig_nbformat":4},"nbformat":4,"nbformat_minor":2} diff --git a/_notebooks/2023-04-01-sortalgo.ipynb b/_notebooks/2023-04-01-sortalgo.ipynb index 4389bf2..f3f6d0a 100644 --- a/_notebooks/2023-04-01-sortalgo.ipynb +++ b/_notebooks/2023-04-01-sortalgo.ipynb @@ -15,11 +15,7 @@ { "cell_type": "code", "execution_count": 66, - "metadata": { - "vscode": { - "languageId": "java" - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -205,11 +201,7 @@ { "cell_type": "code", "execution_count": 48, - "metadata": { - "vscode": { - "languageId": "java" - } - }, + "metadata": {}, "outputs": [], "source": [ "/* This is wrapper class...\n", @@ -275,11 +267,7 @@ { "cell_type": "code", "execution_count": 67, - "metadata": { - "vscode": { - "languageId": "java" - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -402,11 +390,7 @@ { "cell_type": "code", "execution_count": 76, - "metadata": { - "vscode": { - "languageId": "java" - } - }, + "metadata": {}, "outputs": [ { "name": "stdout", @@ -510,7 +494,7 @@ "codemirror_mode": "java", "file_extension": ".jshell", "mimetype": "text/x-java-source", - "name": "Java", + "name": "java", "pygments_lexer": "java", "version": "19.0.2+7-44" }, diff --git a/_notebooks/2023-04-21-try3.ipynb b/_notebooks/2023-04-21-try3.ipynb new file mode 100644 index 0000000..222da53 --- /dev/null +++ b/_notebooks/2023-04-21-try3.ipynb @@ -0,0 +1,288 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Random Test - Part 1,2,3\n", + "\n", + "- toc: true \n", + "- comments: true\n", + "- categories: [java]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bookcount: 0\n", + "Booktitle: Book1 Id: 8027 Super: REPL.$JShell$16G$Book@1b2e4e9a\n", + "Booktitle: Book2 Id: 786 Super: REPL.$JShell$16G$Book@fa73688\n", + "Bookcount: 2\n", + "Book1 shelflife: 5007731458\n", + "Booktitle: Barron's Computer Science \"A\" Id: 2653 Super: REPL.$JShell$16G$Book@63bb21ee\n", + "Booktitle: Angels and Demons Id: 7505 Super: REPL.$JShell$16G$Book@6001dfbf\n", + "Booktitle: Lion, Witch, and a Wardrobe Id: 1971 Super: REPL.$JShell$16G$Book@517350c8\n", + "Libary Book Count: 5\n", + "------Textbook------\n", + "Booktitle: e=MC^2 a Biography Id: 9039 Super: REPL.$JShell$13D$TextBook@33ca166e\n", + "Publisher : Pan Books (January 1, 2001)\n", + "shelflife textbook: 5006280250\n", + "textbook expires: true\n", + "------Textbook------\n", + "Booktitle: The Practice of Programming Id: 5674 Super: REPL.$JShell$13D$TextBook@7874f5cf\n", + "Publisher : Addison-Wesley Professional Computing\n", + "shelflife textbook: 5007632667\n", + "textbook expires: true\n", + "------Novel------\n", + "Booktitle: novel1 Id: 5397 Super: REPL.$JShell$12D$Novel@2e0c3b36\n", + "Author: authorofnovel1\n", + "Expiry: true\n", + "------Novel------\n", + "Booktitle: novel2 Id: 6802 Super: REPL.$JShell$12D$Novel@357dea04\n", + "Author: authorofnovel2\n", + "Expiry: true\n" + ] + } + ], + "source": [ + "import java.util.Random;\n", + "import java.lang.Thread;\n", + "public class Book{\n", + "\n", + " private String titlle;\n", + " private int bookId;\n", + " private static int BookCounter = 0;\n", + " private long startTime;\n", + "\n", + " public Book(String title){\n", + " titlle = title;\n", + " BookCounter++;\n", + " uniqueBookId();\n", + " startTime = System.nanoTime();\n", + " }\n", + "\n", + " public String toString(){\n", + " return \"Booktitle: \" + titlle + \" Id: \" + bookId + \" Super: \" + super.toString();\n", + " }\n", + "\n", + " public void testBook(){\n", + " System.out.println(this);\n", + " }\n", + "\n", + " private int uniqueBookId(){\n", + " Random randid = new Random();\n", + " bookId = randid.nextInt(9999);\n", + " return bookId;\n", + " }\n", + "\n", + " public static int getBookCount(){\n", + " return BookCounter;\n", + " }\n", + " \n", + " public long getshelfLife()\n", + " {\n", + " return System.nanoTime() - startTime; // difference from start to current\n", + " }\n", + "\n", + " public static void main(String[] args){\n", + " \n", + " System.out.println(\"Bookcount: \" + Book.getBookCount());\n", + "\n", + " Book book1 = new Book(\"Book1\");\n", + " Book book2 = new Book(\"Book2\");\n", + "\n", + " System.out.println(book1);\n", + " System.out.println(book2);\n", + "\n", + " System.out.println(\"Bookcount: \" + Book.getBookCount());\n", + " \n", + " // testing for book 1\n", + " try{\n", + " Thread.sleep(5000); // milliseconds\n", + " System.out.println(\"Book1 shelflife: \" + book1.getshelfLife());\n", + " }\n", + " catch (Exception e) {\n", + " \n", + " // catching the exception if there is an interruption\n", + " System.out.println(e);\n", + " }\n", + "\n", + " Book[] bookss = { // array iniitialization to add book\n", + " new Book(\"Barron's Computer Science \\\"A\\\"\"), // Set a new Book object as array element.\n", + " new Book(\"Angels and Demons\"),\n", + " new Book(\"Lion, Witch, and a Wardrobe\")\n", + " };\n", + " \n", + " \n", + " for (Book book : bookss) { // for each syntax to iterate over array\n", + " System.out.println(book); // same as book.toString()\n", + " }\n", + "\n", + " System.out.println(\"Libary Book Count: \" + Book.getBookCount());\n", + "\n", + "\n", + " //------------------------------------------------------------------------------\n", + " String [][] books = {\n", + " { \"e=MC^2 a Biography\",\n", + " \"Pan Books (January 1, 2001)\"}, // row 0\n", + "\n", + " { \"The Practice of Programming\",\n", + " \"Addison-Wesley Professional Computing\" } // row 1\n", + " };\n", + "\n", + " TextBook[] txtbooks= new TextBook[books.length];\n", + " \n", + " for (int k =0; k carsInMarket = new ArrayList(); \n", + "\n", + " /**\n", + " * Constructor with 3 arguments\n", + " * @param carBrand\n", + " * @param modelName\n", + " * @param startingYear\n", + " * \n", + " * everytime this method is called, car id is added and a new car is added to the array\n", + " */\n", + " public Car(String carBrand, String modelName, \n", + " String startingYear, \n", + " int carMileage){\n", + " this.carBrand = carBrand;\n", + " this.modelName = modelName;\n", + " this.startingYear = startingYear;\n", + " this.carMileage = carMileage;\n", + " carId = uniqueID();\n", + " Car.carsInMarket.add(this);\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return number of cars\n", + " */\n", + " public static int getCarsCount(){\n", + " return Car.carsInMarket.size();\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return unique id for each car\n", + " */\n", + " private int uniqueID(){\n", + " Random randid = new Random();\n", + " carId = randid.nextInt(9999);\n", + " return carId;\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return calling the car array\n", + " */\n", + " public static List getCarsInMarket(){\n", + " return Car.carsInMarket;\n", + " }\n", + " \n", + " public int getMarketLife(){\n", + " return CURRENTYEAR - startingYear;\n", + " }\n", + "\n", + " public void ageMarketLife() { \n", + "\n", + " this.life -= Book.YEAR; // remove a year\n", + " if (getShelfLife() < 0.1) // small number zero out, this is for double floating point condition\n", + " this.life = this.created;\n", + " }\n", + "\n", + " public void setMarketLife(int years)\n", + "\n", + " /**\n", + " * printing the object\n", + " */\n", + " public String toString(){\n", + " return \"Id: \" + carId + \" Brand: \" + carBrand + \" Model: \" + modelName + \n", + " \" Year: \" + startingYear + \n", + " \" Mileage: \" + carMileage;\n", + " }\n", + "\n", + " public static void main(String[] args){\n", + "\n", + " System.out.println(\"Car available: \" + Car.getCarsCount());\n", + "\n", + " Car BMWX1 = new Car(\"BMW\",\"X1\",30);\n", + "\n", + " Car HondaCRV = new Car(\"Honda\",\"CRV\",40);\n", + "\n", + "\n", + " for(int i = 0; i < Car.getCarsCount(); i++){\n", + " System.out.println((Car.getCarsInMarket().get(i)));\n", + " }\n", + "\n", + " System.out.println(\"Car available: \" + Car.getCarsCount());\n", + " \n", + " } \n", + "}\n", + "\n", + "Car.main(null);" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "public class ElectricCar extends Car{\n", + "\n", + " private int numBatteries;\n", + " private long chargeTime;\n", + " private boolean hasGear;\n", + "\n", + " public ElectricCar(String carBrand, String modelName, String startingYear, int carMileage, int numBatteries, long chargeTime){\n", + " super(carBrand, modelName, startingYear, carMileage);\n", + " this.numBatteries = numBatteries;\n", + " this.chargeTime = chargeTime;\n", + " \n", + " }\n", + "\n", + " public void setHasGear(boolean hasGear){\n", + " this.hasGear = hasGear;\n", + " }\n", + "\n", + " public boolean getHasGear(){\n", + " return hasGear;\n", + " }\n", + "\n", + " \n", + "\n", + "}" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "java", + "file_extension": ".jshell", + "mimetype": "text/x-java-source", + "name": "java", + "pygments_lexer": "java", + "version": "19.0.2+7-44" + }, + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_notebooks/2023-04-26-labhacks.ipynb b/_notebooks/2023-04-26-labhacks.ipynb new file mode 100644 index 0000000..951b050 --- /dev/null +++ b/_notebooks/2023-04-26-labhacks.ipynb @@ -0,0 +1,312 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Hacks Unit 5,9,10 - Rohit, Nathan, Jun\n", + "\n", + "- toc: true \n", + "- comments: true\n", + "- categories: [java]" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Car available: 0\n", + "Id: 3967 Brand: BMW Model: X1 Year: 2002 Mileage: 30\n", + "Id: 667 Brand: Honda Model: CRV Year: 2015 Mileage: 40\n", + "Car available: 2\n" + ] + } + ], + "source": [ + "// UNIT 5\n", + "\n", + "import java.util.*;\n", + "\n", + "public class Car {\n", + " \n", + " private String carBrand;\n", + " private String modelName;\n", + " private String modelYear;\n", + " private int carMileage = 0;\n", + "\n", + " private int carId = 0;\n", + " private static int carsForSale = 0;\n", + " private static ArrayList carsInMarket = new ArrayList(); \n", + "\n", + " /**\n", + " * Constructor with 3 arguments\n", + " * @param carBrand\n", + " * @param modelName\n", + " * @param modelYear\n", + " * \n", + " * everytime this method is called, car id is added and a new car is added to the array\n", + " */\n", + " public Car(String carBrand, String modelName, String modelYear, int carMileage){\n", + " this.carBrand = carBrand;\n", + " this.modelName = modelName;\n", + " this.modelYear = modelYear;\n", + " this.carMileage = carMileage;\n", + " carId = uniqueID();\n", + " Car.carsInMarket.add(this);\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return number of cars\n", + " */\n", + " public static int getCarsCount(){\n", + " return Car.carsInMarket.size();\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return unique id for each car\n", + " */\n", + " private int uniqueID(){\n", + " Random randid = new Random();\n", + " carId = randid.nextInt(9999);\n", + " return carId;\n", + " }\n", + "\n", + " /**\n", + " * \n", + " * @return calling the car array\n", + " */\n", + " public static List getCarsInMarket(){\n", + " return Car.carsInMarket;\n", + " }\n", + " \n", + " /**\n", + " * printing the object\n", + " */\n", + " public String toString(){\n", + " return \"Id: \" + carId + \" Brand: \" + carBrand + \" Model: \" + modelName + \" Year: \" + modelYear + \" Mileage: \" + carMileage;\n", + " }\n", + "\n", + " public static void main(String[] args){\n", + "\n", + " System.out.println(\"Car available: \" + Car.getCarsCount());\n", + "\n", + " Car BMWX1 = new Car(\"BMW\",\"X1\",\"2002\",30);\n", + "\n", + " Car HondaCRV = new Car(\"Honda\",\"CRV\",\"2015\",40);\n", + "\n", + "\n", + " for(int i = 0; i < Car.getCarsCount(); i++){\n", + " System.out.println((Car.getCarsInMarket().get(i)));\n", + " }\n", + "\n", + " System.out.println(\"Car available: \" + Car.getCarsCount());\n", + " \n", + " } \n", + "}\n", + "Car.main(null);" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "HONK MEEP BEEEEEEEP!\n", + "Lexus GS430\n" + ] + } + ], + "source": [ + "// UNIT 9 PART 1\n", + "\n", + "class Vehicle {\n", + "\n", + " public String name; \n", + "\n", + " public Vehicle(String name){\n", + " this.name = name;\n", + " }\n", + "\n", + " public void honk(){\n", + " System.out.println(\"HONK MEEP BEEEEEEEP!\");\n", + " }\n", + "}\n", + "\n", + "class Car extends Vehicle {\n", + " public Car(String name){\n", + " super(name);\n", + " }\n", + " // methods and attributes\n", + "\n", + "}\n", + "\n", + "public class Main {\n", + " public static void main(String[] args) {\n", + " Car car1 = new Car(\"Lexus GS430\");\n", + "\n", + " car1.honk();\n", + " System.out.println(car1.name);\n", + " }\n", + "}\n", + "Main.main(null);" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Turtle Noises Commence\n", + "I nomp lettuce.\n", + "Shellby\n", + "Meow!\n", + "I am scratching the furniture.\n", + "2\n" + ] + } + ], + "source": [ + "// UNIT 9 PART 2\n", + "\n", + "// Parent class\n", + "public class Animal {\n", + " protected String name;\n", + " protected int age;\n", + "\n", + " public Animal(String name, int age) {\n", + " this.name = name;\n", + " this.age = age;\n", + " }\n", + "\n", + " public void speak() {\n", + " System.out.println(\"I AM AN ANIMALIO!!!!!!!!\");\n", + " }\n", + "}\n", + "\n", + "// Subclass 1\n", + "public class Turtle extends Animal {\n", + " private String breed;\n", + "\n", + " public Turtle(String name, int age, String breed) {\n", + " super(name, age);\n", + " this.breed = breed;\n", + " }\n", + "\n", + " @Override\n", + " public void speak() {\n", + " System.out.println(\"Turtle Noises Commence\");\n", + " }\n", + "\n", + " public void eat() {\n", + " System.out.println(\"I nomp lettuce.\");\n", + " }\n", + "}\n", + "\n", + "// Subclass 2\n", + "public class Cat extends Animal {\n", + " private boolean isIndoor;\n", + "\n", + " public Cat(String name, int age, boolean isIndoor) {\n", + " super(name, age);\n", + " this.isIndoor = isIndoor;\n", + " }\n", + "\n", + " @Override\n", + " public void speak() {\n", + " System.out.println(\"Meow!\");\n", + " }\n", + "\n", + " public void scratch() {\n", + " System.out.println(\"I am scratching the furniture.\");\n", + " }\n", + "}\n", + "\n", + "// Tester method\n", + "public class AnimalTester {\n", + " public static void main(String[] args) {\n", + " Animal animal1 = new Turtle(\"Shellby\", 3, \"Russian Tortoise\");\n", + " Animal animal2 = new Cat(\"Whiskers\", 2, true);\n", + "\n", + " animal1.speak();\n", + " ((Turtle) animal1).eat();\n", + " System.out.println(animal1.name);\n", + "\n", + " animal2.speak();\n", + " ((Cat) animal2).scratch();\n", + " System.out.println(animal2.age);\n", + " }\n", + "}\n", + "AnimalTester.main(null);" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The 0th fibonacci number is: 0\n", + "The 7th fibonacci number is: 13\n", + "The 12th fibonacci number is: 144\n" + ] + } + ], + "source": [ + "// UNIT 10\n", + "\n", + "public class Fibonacci {\n", + " public static long fib(long n) {\n", + " if ((n == 0) || (n == 1))\n", + " return n;\n", + " else\n", + " return fib(n - 1) + fib(n - 2);\n", + " }\n", + " public static void main(String[] args) {\n", + " System.out.println(\"The 0th fibonacci number is: \" + fib(0));\n", + " System.out.println(\"The 7th fibonacci number is: \" + fib(7));\n", + " System.out.println(\"The 12th fibonacci number is: \" + fib(12));\n", + " }\n", + " }\n", + "\n", + " Fibonacci.main(null);" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Java", + "language": "java", + "name": "java" + }, + "language_info": { + "codemirror_mode": "java", + "file_extension": ".jshell", + "mimetype": "text/x-java-source", + "name": "java", + "pygments_lexer": "java", + "version": "19.0.2+7-44" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +}