From 03c3ff7de781b8b9ee1c84ec5999f6d8cd635e2e Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 10:55:15 -0700 Subject: [PATCH 01/31] added HelloWorld Example and Solution! --- .gitignore | 5 ++++- .../chapter1/practice/HelloWorld.java | 19 +++++++++++++++++++ .../chapter1/solutions/HelloWorld.java | 19 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java create mode 100644 src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java diff --git a/.gitignore b/.gitignore index 1dbb98b..9a0f431 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ # ignore files c4t-java.iml -.DS_Store \ No newline at end of file +.DS_Store + +# ignore prettier files +.prettierrc.json diff --git a/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java new file mode 100644 index 0000000..e2a15fe --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java @@ -0,0 +1,19 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Welcome to Java! + * This may be your first ever java program! + * We'll begin your journey with the infamous Hello World program! + */ + + // a class is an "object" where we will place all our code inside + public class HelloWorld{ + // the main method (below) is the first thing that runs when your program is run + public static void main(String[] args) { + // write code here (replace the "" with "Hello World!") + System.out.println(""); + } + } \ No newline at end of file diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java new file mode 100644 index 0000000..dbce821 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java @@ -0,0 +1,19 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Welcome to Java! + * This may be your first ever java program! + * We'll begin your journey with the infamous Hello World program! + */ + + // a class is an "object" where we will place all our code inside + public class HelloWorld{ + // the main method (below) is the first thing that runs when your program is run + public static void main(String[] args) { + // write code here (replace the "" with "Hello World!") + System.out.println("Hello World!"); + } + } \ No newline at end of file From 2a4843736205c3022ad45feae1b0910a932ad501 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 11:03:08 -0700 Subject: [PATCH 02/31] Added Comments exercise to practice comments (Java Beginners, Chapter 1) --- .../beginner/chapter1/practice/Comments.java | 38 +++++++++++++++++++ .../beginner/chapter1/solutions/Comments.java | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/com/codefortomorrow/beginner/chapter1/practice/Comments.java create mode 100644 src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java diff --git a/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java b/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java new file mode 100644 index 0000000..cebb705 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter1/practice/Comments.java @@ -0,0 +1,38 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * You'll be writing your first ever comment today! + * What we'll go over: + * - single line comments + * - multi line comments + */ + + // a class is an "object" where we will place all our code inside + public class Comments { + // the main method (below) is the first thing that runs when your program is run + public static void main(String[] args) { + // this is a single line comment, I can write anything here + // single line comments aren't run by Java! + // they can be used to annotate your code! + + /** + * this is a multi + * line + * comment + * + * It can span across multiple lines! + */ + + // YOUR ASSIGNMENT: write 1 single-line comment and 1 multi-line comment on the lines below... + + + + + + + + } + } \ No newline at end of file diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java new file mode 100644 index 0000000..a14a123 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java @@ -0,0 +1,38 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * You'll be writing your first ever comment today! + * What we'll go over: + * - single line comments + * - multi line comments + */ + + // a class is an "object" where we will place all our code inside + public class Comments { + // the main method (below) is the first thing that runs when your program is run + public static void main(String[] args) { + // this is a single line comment, I can write anything here + // single line comments aren't run by Java! + // they can be used to annotate your code! + + /** + * this is a multi + * line + * comment + * + * It can span across multiple lines! + */ + + // YOUR ASSIGNMENT: write 1 single-line comment and 1 multi-line comment on the lines below... + + // Hi my name is Armeet! + + /** + * I like teaching Java, and + * good luck on your journey! + */ + } + } \ No newline at end of file From bb68ef08cfdb2d99dba88794b254f703e2a55b8f Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 11:47:45 -0700 Subject: [PATCH 03/31] finished VariableTypes exercise and solution --- .../chapter2/practice/VariableTypes.java | 34 +++++++++++++++++++ .../chapter2/solutions/VariableTypes.java | 34 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java create mode 100644 src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java new file mode 100644 index 0000000..3cb0ed4 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java @@ -0,0 +1,34 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Define different types of variables + */ + + public class VariableTypes { + public static void main(String[] args) { + // write your code here + + // define an integer variable on line 15 + + + // define a float variable on line 18 + + + // define a double variable on line 21 + + + // define a boolean variable on line 24 (Hint: true/false) on line 24 + + + // define a character variable on line 27 + + + // define a string variable on line 30 + + + } + } + \ No newline at end of file diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java new file mode 100644 index 0000000..36a6b48 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -0,0 +1,34 @@ +package com.codefortomorrow.beginner.chapter1.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Define different types of variables + */ + + public class VariableTypes { + public static void main(String[] args) { + // write your code here + + // define an integer variable on line 15 + int age = 23; + + // define a float variable on line 18 + float pi = 3.14f; + + // define a double variable on line 21 + double decimal = 23.2352536d; + + // define a boolean variable on line 24 (Hint: true/false) on line 24 + double dogsOut = true; // the dogs are out :) + + // define a character variable on line 27 + char letter = 'A'; + + // define a string variable on line 30 + char name = "Jeff"; + + } + } + \ No newline at end of file From a2a2eb84a3cd26b9502a8fc9f2420f0667b21f24 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 11:48:10 -0700 Subject: [PATCH 04/31] fixed VariableTypes package names --- .../beginner/chapter2/practice/VariableTypes.java | 2 +- .../beginner/chapter2/solutions/VariableTypes.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java index 3cb0ed4..a051136 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter1.practice; +package com.codefortomorrow.beginner.chapter2.practice; /** * @author ArmeetJatyani diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index 36a6b48..f58142b 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter1.practice; +package com.codefortomorrow.beginner.chapter2.practice; /** * @author ArmeetJatyani From b9f1238a4ddced74abe2b69d56b56ec4f9a84dca Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 11:53:40 -0700 Subject: [PATCH 05/31] ApplesOranges exercise complete --- .../chapter2/practice/ApplesOranges.java | 28 +++++++++++++++++++ .../chapter2/solutions/ApplesOranges.java | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java create mode 100644 src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java new file mode 100644 index 0000000..38be171 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java @@ -0,0 +1,28 @@ +package com.codefortomorrow.beginner.chapter2.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Print out the number of apples and oranges! + */ + + public class ApplesOranges { + public static void main(String[] args) { + // write your code here + + // define an integer variable called numOranges with value 10 (line 15) + + + // define an integer variable called numApples with value 24 (line 18) + + + // print out number of oranges, output: "I have 10 oranges." (line 21) + + + // print out number of apples, output: "I have 24 apples." (line 24) + + + } + } + \ No newline at end of file diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java new file mode 100644 index 0000000..9d35185 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java @@ -0,0 +1,28 @@ +package com.codefortomorrow.beginner.chapter2.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Print out the number of apples and oranges! + */ + + public class ApplesOranges { + public static void main(String[] args) { + // write your code here + + // define an integer variable called numOranges with value 10 (line 15) + int numOranges = 10; + + // define an integer variable called numApples with value 24 (line 18) + int numApples = 24; + + // print out number of oranges, output: "I have 10 oranges." (line 21) + System.out.println("I have " + numOranges + " oranges."); + + // print out number of apples, output: "I have 24 apples." (line 24) + System.out.println("I have " + numApples + " apples."); + + } + } + \ No newline at end of file From 3c4a0932d5db33c45a64ffbba701ba00937a5037 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 11:58:26 -0700 Subject: [PATCH 06/31] finished CarDealership exercise --- .../chapter4/practice/CarDealership.java | 28 +++++++++++++++++++ .../chapter4/solutions/CarDealership.java | 28 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java create mode 100644 src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java diff --git a/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java b/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java new file mode 100644 index 0000000..df2013f --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter4/practice/CarDealership.java @@ -0,0 +1,28 @@ +package com.codefortomorrow.beginner.chapter4.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Manage a car dealership and take inventory of all cars sold! + */ + + public class CarDealership { + public static void main(String[] args) { + // write your code here + + // define 3 integer constants, representing the prices of 3 cars sold in USD (line 15-17) + + + + + // define an integer variable, which represents the sum of the prices of these 3 cars (line 20) + + + // print out the formatted revenue after selling these 3 cars, output: "I sold 3 cars for $XXXXXX." (line 23) + + + + } + } + \ No newline at end of file diff --git a/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java new file mode 100644 index 0000000..fa3b1f4 --- /dev/null +++ b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java @@ -0,0 +1,28 @@ +package com.codefortomorrow.beginner.chapter4.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Manage a car dealership and take inventory of all cars sold! + */ + + public class CarDealership { + public static void main(String[] args) { + // write your code here + + // define 3 integer constants, representing the prices of 3 cars sold in USD (line 15-17) + final int car1 = 30000; + final int car2 = 24650; + final int car3 = 253630; + + // define an integer variable, which represents the sum of the prices of these 3 cars (line 20) + int revenue = car1 + car2 + car3; + + // print out the formatted revenue after selling these 3 cars, output: "I sold 3 cars for $XXXXXX." (line 23) + System.out.println("I sold 3 cars for $" + revenue + "."); + + + } + } + \ No newline at end of file From f1858cbec7a53a3d9c1040eba0925a21e3db0a03 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 12:09:51 -0700 Subject: [PATCH 07/31] completed LinkedList implementation Challenge for Advanced Group --- .../chapter16/practice/LinkedList.java | 26 +++ .../chapter16/solutions/LinkedList.java | 159 ++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java create mode 100644 src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java diff --git a/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java new file mode 100644 index 0000000..6fe8bb7 --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java @@ -0,0 +1,26 @@ +package com.codefortomorrow.advanced.chapter16.practice; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Implement a simple LinkedList + * You will need to create a LinkedListNode class, which represents each item/node in the linked list + * Required functionality... + * - head(): get head of list + * - tail(): get tail of list + * - add(): add to tail of list + * - push(): push to head of list + * - pop(): remove head of list + * - toString(): return a String representation of the list + */ + +public class LinkedList { + public static void main(String[] args) { + // write your code here + + } + +} + +class LinkedListNode \ No newline at end of file diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java new file mode 100644 index 0000000..b9d18ae --- /dev/null +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -0,0 +1,159 @@ +package com.codefortomorrow.advanced.chapter16.solutions; + +// using Lombok for Getters and Setters +import lombok.Setter; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +// UUID to represent each node's unique ID +import java.util.UUID; + +/** + * @author ArmeetJatyani + * March 2021 + * + * Implement a simple LinkedList + * You will need to create a LinkedListNode class, which represents each item/node in the linked list + * Required functionality... + * - head(): get head of list + * - tail(): get tail of list + * - add(): add to tail of list + * - push(): push to head of list + * - pop(): remove head of list + * - toString(): return a String representation of the list + */ + +@Setter +public class LinkedList { + private LinkedListNode head; + + /** + * default constructor + */ + public LinkedList() { + head = null; + } + + /** + * constructor with first value + * @param value + */ + public LinkedList(int value) { + // create first node + head = new LinkedListNode(value, null); + } + + /** + * get head of Linked List + * @return + */ + public LinkedListNode head() { + return this.head; + } + + /** + * traverse and get tail of linked list + * @return + */ + public LinkedListNode tail() { + LinkedListNode current = head; + if(current == null) return null; + + while (current.getNext() != null) { + current = current.getNext(); + } + + return current; + } + + /** + * add new element (node) to linked list + * @param value + */ + public void add(int value) { + LinkedListNode tail = tail(); + if (tail == null) { + head = new LinkedListNode(value, null); + return; + } + + tail.setNext(new LinkedListNode(value, null)); + } + + /** + * push (add to head of linkedlist) + * @return + */ + public void push(int value) { + LinkedListNode newHead = new LinkedListNode(value, head); + head = newHead; + } + + /** + * pop (remove head of linkedlist) + * @return + */ + public LinkedListNode pop() { + LinkedListNode popped = head; + head = head.getNext(); + return popped; + } + + /** + * to String + * @return + */ + @Override + public String toString() { + String list = "["; + LinkedListNode current = head; + if(current == null) return null; + do { + list += Integer.toString(current.getValue()) + ", "; + current = current.getNext(); + } + while (current != null); + + list = list.substring(0, list.length() - 2); + return list + "]"; + } + +} + +@Getter +@Setter +class Node +{ + private UUID ID; + private int value; + + public Node(int value) + { + this.ID = UUID.randomUUID(); + this.value = value; + } + + public int value() + { + return this.value; + } +} + +@Getter +@Setter +class LinkedListNode extends Node +{ + private LinkedListNode next; + + public LinkedListNode(int value, LinkedListNode next) + { + super(value); + this.next = next; + } + + public LinkedListNode next() + { + return this.next; + } +} + From cfc050cf94f96eae351cf447a0b0388f2777a6af Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 12:13:24 -0700 Subject: [PATCH 08/31] fix package name errors for Solutions --- .../codefortomorrow/beginner/chapter1/solutions/Comments.java | 2 +- .../codefortomorrow/beginner/chapter1/solutions/HelloWorld.java | 2 +- .../beginner/chapter2/solutions/ApplesOranges.java | 2 +- .../beginner/chapter2/solutions/VariableTypes.java | 2 +- .../beginner/chapter4/solutions/CarDealership.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java index a14a123..446b385 100644 --- a/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter1.practice; +package com.codefortomorrow.beginner.chapter1.solutions; /** * @author ArmeetJatyani diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java index dbce821..39a0de1 100644 --- a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter1.practice; +package com.codefortomorrow.beginner.chapter1.solutions; /** * @author ArmeetJatyani diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java index 9d35185..28270b4 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter2.practice; +package com.codefortomorrow.beginner.chapter2.solutions; /** * @author ArmeetJatyani diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index f58142b..d85af80 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter2.practice; +package com.codefortomorrow.beginner.chapter2.solutions; /** * @author ArmeetJatyani diff --git a/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java index fa3b1f4..10fdd82 100644 --- a/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java +++ b/src/com/codefortomorrow/beginner/chapter4/solutions/CarDealership.java @@ -1,4 +1,4 @@ -package com.codefortomorrow.beginner.chapter4.practice; +package com.codefortomorrow.beginner.chapter4.solutions; /** * @author ArmeetJatyani From db58c32aee32be614f4029126a839eaac5494d9c Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 12:24:43 -0700 Subject: [PATCH 09/31] formatted --- .../chapter16/solutions/LinkedList.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index b9d18ae..0dbe171 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -122,37 +122,31 @@ public String toString() { @Getter @Setter -class Node -{ +class Node { private UUID ID; private int value; - public Node(int value) - { + public Node(int value) { this.ID = UUID.randomUUID(); this.value = value; } - public int value() - { + public int value() { return this.value; } } @Getter @Setter -class LinkedListNode extends Node -{ +class LinkedListNode extends Node { private LinkedListNode next; - public LinkedListNode(int value, LinkedListNode next) - { + public LinkedListNode(int value, LinkedListNode next) { super(value); this.next = next; } - public LinkedListNode next() - { + public LinkedListNode next() { return this.next; } } From 542423bdc96bedc8cc36ecf75b48a457071f2b8a Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 12:27:20 -0700 Subject: [PATCH 10/31] attempt #2: fixing formatting --- .../chapter16/practice/LinkedList.java | 8 +++---- .../chapter16/solutions/LinkedList.java | 24 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java index 6fe8bb7..834202e 100644 --- a/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java @@ -3,7 +3,7 @@ /** * @author ArmeetJatyani * March 2021 - * + * * Implement a simple LinkedList * You will need to create a LinkedListNode class, which represents each item/node in the linked list * Required functionality... @@ -16,11 +16,11 @@ */ public class LinkedList { + public static void main(String[] args) { // write your code here - - } + } } -class LinkedListNode \ No newline at end of file +class LinkedListNode {} diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 0dbe171..704e67e 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -1,17 +1,17 @@ package com.codefortomorrow.advanced.chapter16.solutions; -// using Lombok for Getters and Setters -import lombok.Setter; +// UUID to represent each node's unique ID +import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Getter; +// using Lombok for Getters and Setters +import lombok.Setter; import lombok.Setter; -// UUID to represent each node's unique ID -import java.util.UUID; /** * @author ArmeetJatyani * March 2021 - * + * * Implement a simple LinkedList * You will need to create a LinkedListNode class, which represents each item/node in the linked list * Required functionality... @@ -25,6 +25,7 @@ @Setter public class LinkedList { + private LinkedListNode head; /** @@ -57,7 +58,7 @@ public LinkedListNode head() { */ public LinkedListNode tail() { LinkedListNode current = head; - if(current == null) return null; + if (current == null) return null; while (current.getNext() != null) { current = current.getNext(); @@ -107,22 +108,21 @@ public LinkedListNode pop() { public String toString() { String list = "["; LinkedListNode current = head; - if(current == null) return null; + if (current == null) return null; do { list += Integer.toString(current.getValue()) + ", "; current = current.getNext(); - } - while (current != null); + } while (current != null); list = list.substring(0, list.length() - 2); return list + "]"; } - } @Getter @Setter class Node { + private UUID ID; private int value; @@ -135,10 +135,11 @@ public int value() { return this.value; } } - + @Getter @Setter class LinkedListNode extends Node { + private LinkedListNode next; public LinkedListNode(int value, LinkedListNode next) { @@ -150,4 +151,3 @@ public LinkedListNode next() { return this.next; } } - From 85bda2c3b1ede2007e69b2c15285b56589ade446 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 14:43:18 -0700 Subject: [PATCH 11/31] adding to comments --- .../advanced/chapter16/solutions/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 704e67e..debfb34 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -4,7 +4,7 @@ import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Getter; -// using Lombok for Getters and Setters +// using Lombok for Getters and Setters (saves lines) import lombok.Setter; import lombok.Setter; From e92fb417735dc9f608a56d26f7a9ebadcd9b5f1f Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:14:33 -0700 Subject: [PATCH 12/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../advanced/chapter16/solutions/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index debfb34..19c6d18 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -61,7 +61,7 @@ public LinkedListNode tail() { if (current == null) return null; while (current.getNext() != null) { - current = current.getNext(); + current = current.next(); } return current; From f6977c7b22c5bd5376bd743c987e99651f68a4a2 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:14:51 -0700 Subject: [PATCH 13/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../codefortomorrow/advanced/chapter16/solutions/LinkedList.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 19c6d18..5da7b83 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -75,7 +75,6 @@ public void add(int value) { LinkedListNode tail = tail(); if (tail == null) { head = new LinkedListNode(value, null); - return; } tail.setNext(new LinkedListNode(value, null)); From cca23c28f9924d178f83d2a1cc687908064ab964 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:15:00 -0700 Subject: [PATCH 14/31] Update src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/practice/VariableTypes.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java index a051136..e5b9678 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java @@ -20,7 +20,7 @@ public static void main(String[] args) { // define a double variable on line 21 - // define a boolean variable on line 24 (Hint: true/false) on line 24 + // define a boolean variable on line 24 (Hint: true/false) // define a character variable on line 27 @@ -31,4 +31,4 @@ public static void main(String[] args) { } } - \ No newline at end of file + From 47b672561dc240673993163f9a9e373f2dbf12bd Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:15:10 -0700 Subject: [PATCH 15/31] Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/solutions/ApplesOranges.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java index 28270b4..ff9e4b3 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java @@ -17,7 +17,7 @@ public static void main(String[] args) { // define an integer variable called numApples with value 24 (line 18) int numApples = 24; - // print out number of oranges, output: "I have 10 oranges." (line 21) + // print out number of oranges using variables, output: "I have 10 oranges." (line 21) System.out.println("I have " + numOranges + " oranges."); // print out number of apples, output: "I have 24 apples." (line 24) @@ -25,4 +25,4 @@ public static void main(String[] args) { } } - \ No newline at end of file + From 199fb87262fca8da79471c86a00d17bd65fa44d4 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:15:15 -0700 Subject: [PATCH 16/31] Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/solutions/ApplesOranges.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java index ff9e4b3..b35c1e9 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOranges.java @@ -20,7 +20,7 @@ public static void main(String[] args) { // print out number of oranges using variables, output: "I have 10 oranges." (line 21) System.out.println("I have " + numOranges + " oranges."); - // print out number of apples, output: "I have 24 apples." (line 24) + // print out number of apples using variables, output: "I have 24 apples." (line 24) System.out.println("I have " + numApples + " apples."); } From 40b86623d2db965d3fc19c26fac7188467ad8971 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:15:56 -0700 Subject: [PATCH 17/31] Update src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/solutions/VariableTypes.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index d85af80..f6850ce 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -20,7 +20,7 @@ public static void main(String[] args) { // define a double variable on line 21 double decimal = 23.2352536d; - // define a boolean variable on line 24 (Hint: true/false) on line 24 + // define a boolean variable on line 24 (Hint: true/false) double dogsOut = true; // the dogs are out :) // define a character variable on line 27 @@ -31,4 +31,4 @@ public static void main(String[] args) { } } - \ No newline at end of file + From 1b3fbfda3036d56c80093e55f0385ab529e7c3b2 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:16:08 -0700 Subject: [PATCH 18/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../advanced/chapter16/solutions/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 5da7b83..cf19cbe 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -75,7 +75,7 @@ public void add(int value) { LinkedListNode tail = tail(); if (tail == null) { head = new LinkedListNode(value, null); - } + } else { tail.setNext(new LinkedListNode(value, null)); } From 66100104f2ee123900633b2512b744ce31a72fb1 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:17:10 -0700 Subject: [PATCH 19/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../advanced/chapter16/solutions/LinkedList.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index cf19cbe..148ff74 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -77,7 +77,8 @@ public void add(int value) { head = new LinkedListNode(value, null); } else { - tail.setNext(new LinkedListNode(value, null)); + tail.setNext(new LinkedListNode(value, null)); + } } /** From 84ad074fe073ee6e82dabc2d13805a66fb255ba4 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:17:21 -0700 Subject: [PATCH 20/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../advanced/chapter16/solutions/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 148ff74..370ca83 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -96,7 +96,7 @@ public void push(int value) { */ public LinkedListNode pop() { LinkedListNode popped = head; - head = head.getNext(); + head = head.next(); return popped; } From 640cb85666225340e855552bc9b32bb1ec0def46 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:18:26 -0700 Subject: [PATCH 21/31] Update src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../codefortomorrow/advanced/chapter16/practice/LinkedList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java index 834202e..04fd4f5 100644 --- a/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java @@ -6,6 +6,7 @@ * * Implement a simple LinkedList * You will need to create a LinkedListNode class, which represents each item/node in the linked list + * Assume that the elements in the linked list are all of type int * Required functionality... * - head(): get head of list * - tail(): get tail of list From 80170097c62be724bcb0e5e7203187b8efcb03a9 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:18:40 -0700 Subject: [PATCH 22/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../advanced/chapter16/solutions/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 370ca83..5b26866 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -110,7 +110,7 @@ public String toString() { LinkedListNode current = head; if (current == null) return null; do { - list += Integer.toString(current.getValue()) + ", "; + list += Integer.toString(current.value()) + ", "; current = current.getNext(); } while (current != null); From e4e6db996f893a1b1093aa0f93f8e260dad90ec6 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:18:51 -0700 Subject: [PATCH 23/31] Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../codefortomorrow/advanced/chapter16/solutions/LinkedList.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 5b26866..245d36b 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -114,6 +114,7 @@ public String toString() { current = current.getNext(); } while (current != null); + // Remove trailing comma and space after last list element list = list.substring(0, list.length() - 2); return list + "]"; } From 9ac5b2d43edc985b5a7268ce94fd95cd036b5338 Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 17:20:45 -0700 Subject: [PATCH 24/31] made requested changes --- .gitignore | 2 -- .../advanced/chapter16/solutions/LinkedList.java | 12 ------------ 2 files changed, 14 deletions(-) diff --git a/.gitignore b/.gitignore index 9a0f431..0ec6afc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,3 @@ c4t-java.iml .DS_Store -# ignore prettier files -.prettierrc.json diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index debfb34..75c3dd1 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -2,11 +2,6 @@ // UUID to represent each node's unique ID import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Getter; -// using Lombok for Getters and Setters (saves lines) -import lombok.Setter; -import lombok.Setter; /** * @author ArmeetJatyani @@ -23,7 +18,6 @@ * - toString(): return a String representation of the list */ -@Setter public class LinkedList { private LinkedListNode head; @@ -37,7 +31,6 @@ public LinkedList() { /** * constructor with first value - * @param value */ public LinkedList(int value) { // create first node @@ -69,7 +62,6 @@ public LinkedListNode tail() { /** * add new element (node) to linked list - * @param value */ public void add(int value) { LinkedListNode tail = tail(); @@ -119,8 +111,6 @@ public String toString() { } } -@Getter -@Setter class Node { private UUID ID; @@ -136,8 +126,6 @@ public int value() { } } -@Getter -@Setter class LinkedListNode extends Node { private LinkedListNode next; From 2d8da5dd3f1d449e1510860d8c79bd83bf3ee29a Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 15 Mar 2021 17:22:56 -0700 Subject: [PATCH 25/31] made all changes 2 --- .../advanced/chapter16/solutions/LinkedList.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 2ba949f..2f77dc2 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -53,7 +53,7 @@ public LinkedListNode tail() { LinkedListNode current = head; if (current == null) return null; - while (current.getNext() != null) { + while (current.next() != null) { current = current.next(); } @@ -68,7 +68,6 @@ public void add(int value) { if (tail == null) { head = new LinkedListNode(value, null); } else { - tail.setNext(new LinkedListNode(value, null)); } } @@ -103,7 +102,7 @@ public String toString() { if (current == null) return null; do { list += Integer.toString(current.value()) + ", "; - current = current.getNext(); + current = current.next(); } while (current != null); // Remove trailing comma and space after last list element @@ -139,4 +138,9 @@ public LinkedListNode(int value, LinkedListNode next) { public LinkedListNode next() { return this.next; } + + public void setNext(LinkedListNode next) { + this.next = next; + return; + } } From 17cb81d6e776cf8ea3edc1c5b7aadf1b75d12628 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:26:41 -0700 Subject: [PATCH 26/31] Update src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter1/practice/HelloWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java index e2a15fe..832742a 100644 --- a/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java +++ b/src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java @@ -10,10 +10,10 @@ */ // a class is an "object" where we will place all our code inside - public class HelloWorld{ + public class HelloWorld { // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // write code here (replace the "" with "Hello World!") System.out.println(""); } - } \ No newline at end of file + } From acd3db80260f2cd82f3008ddae9a68b1353da769 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:26:57 -0700 Subject: [PATCH 27/31] Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/practice/ApplesOranges.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java index 38be171..3a6cb45 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java @@ -17,7 +17,7 @@ public static void main(String[] args) { // define an integer variable called numApples with value 24 (line 18) - // print out number of oranges, output: "I have 10 oranges." (line 21) + // print out number of oranges using variables, output: "I have 10 oranges." (line 21) // print out number of apples, output: "I have 24 apples." (line 24) @@ -25,4 +25,4 @@ public static void main(String[] args) { } } - \ No newline at end of file + From 09959381b5dfd3e524a7db1b30f3cc87478613f3 Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Mon, 15 Mar 2021 17:27:03 -0700 Subject: [PATCH 28/31] Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java Co-authored-by: Rebecca Dang <35876322+phrdang@users.noreply.github.com> --- .../beginner/chapter2/practice/ApplesOranges.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java index 3a6cb45..bb28674 100644 --- a/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java +++ b/src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java @@ -20,7 +20,7 @@ public static void main(String[] args) { // print out number of oranges using variables, output: "I have 10 oranges." (line 21) - // print out number of apples, output: "I have 24 apples." (line 24) + // print out number of apples using variables, output: "I have 24 apples." (line 24) } From 508db44ef4c6d814289390d83caf3bcd220935ee Mon Sep 17 00:00:00 2001 From: Rebecca Dang Date: Tue, 16 Mar 2021 15:24:33 -0700 Subject: [PATCH 29/31] Update/add javadoc comments (for consistency) --- .../chapter16/solutions/LinkedList.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 2f77dc2..848e482 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -9,6 +9,7 @@ * * Implement a simple LinkedList * You will need to create a LinkedListNode class, which represents each item/node in the linked list + * Assume that the elements in the linked list are all of type int * Required functionality... * - head(): get head of list * - tail(): get tail of list @@ -31,6 +32,7 @@ public LinkedList() { /** * constructor with first value + * @param value first element in the linked list */ public LinkedList(int value) { // create first node @@ -39,7 +41,7 @@ public LinkedList(int value) { /** * get head of Linked List - * @return + * @return first element of the linked list */ public LinkedListNode head() { return this.head; @@ -47,7 +49,7 @@ public LinkedListNode head() { /** * traverse and get tail of linked list - * @return + * @return last element of the linked list */ public LinkedListNode tail() { LinkedListNode current = head; @@ -62,6 +64,7 @@ public LinkedListNode tail() { /** * add new element (node) to linked list + * @param value element to add to the end of the linked list */ public void add(int value) { LinkedListNode tail = tail(); @@ -73,8 +76,7 @@ public void add(int value) { } /** - * push (add to head of linkedlist) - * @return + * push (add element to head of linkedlist) */ public void push(int value) { LinkedListNode newHead = new LinkedListNode(value, head); @@ -82,8 +84,8 @@ public void push(int value) { } /** - * pop (remove head of linkedlist) - * @return + * pop (remove and return head of linkedlist) + * @return the node that was removed */ public LinkedListNode pop() { LinkedListNode popped = head; @@ -92,8 +94,8 @@ public LinkedListNode pop() { } /** - * to String - * @return + * Returns a String version of the LinkedList + * @return a String version of the LinkedList */ @Override public String toString() { @@ -116,11 +118,19 @@ class Node { private UUID ID; private int value; + /** + * Constructs a list node with the given value + * @param value the value stored in this Node + */ public Node(int value) { this.ID = UUID.randomUUID(); this.value = value; } + /** + * Returns the value of this Node + * @return the value of this Node + */ public int value() { return this.value; } @@ -130,15 +140,28 @@ class LinkedListNode extends Node { private LinkedListNode next; + /** + * Constructs a LinkedListNode + * @param value the value stored in this node + * @param next the next node + */ public LinkedListNode(int value, LinkedListNode next) { super(value); this.next = next; } + /** + * Returns the next node + * @return the next node + */ public LinkedListNode next() { return this.next; } + /** + * Sets the next node + * @param next the next node + */ public void setNext(LinkedListNode next) { this.next = next; return; From 44713c450ca0f4208d10f17637b825716637e04a Mon Sep 17 00:00:00 2001 From: ArmeetJatyani Date: Mon, 22 Mar 2021 11:09:16 -0700 Subject: [PATCH 30/31] revision 3 --- .../advanced/chapter16/solutions/LinkedList.java | 5 ----- .../beginner/chapter2/solutions/VariableTypes.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java index 2f77dc2..1d69417 100644 --- a/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java +++ b/src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java @@ -1,8 +1,5 @@ package com.codefortomorrow.advanced.chapter16.solutions; -// UUID to represent each node's unique ID -import java.util.UUID; - /** * @author ArmeetJatyani * March 2021 @@ -113,11 +110,9 @@ public String toString() { class Node { - private UUID ID; private int value; public Node(int value) { - this.ID = UUID.randomUUID(); this.value = value; } diff --git a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java index f6850ce..0a3a64e 100644 --- a/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java +++ b/src/com/codefortomorrow/beginner/chapter2/solutions/VariableTypes.java @@ -15,7 +15,7 @@ public static void main(String[] args) { int age = 23; // define a float variable on line 18 - float pi = 3.14f; + float decimal = 23.32544f; // define a double variable on line 21 double decimal = 23.2352536d; From 48dc66b16bf09c52caf6c13e078a8906f9c130ca Mon Sep 17 00:00:00 2001 From: Armeet Jatyani Date: Tue, 23 Mar 2021 10:14:01 -0700 Subject: [PATCH 31/31] Update src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java Co-authored-by: JJ27 <66833672+JJ27@users.noreply.github.com> --- .../beginner/chapter1/solutions/HelloWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java index 39a0de1..a1152d2 100644 --- a/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java +++ b/src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java @@ -10,10 +10,10 @@ */ // a class is an "object" where we will place all our code inside - public class HelloWorld{ + public class HelloWorld { // the main method (below) is the first thing that runs when your program is run public static void main(String[] args) { // write code here (replace the "" with "Hello World!") System.out.println("Hello World!"); } - } \ No newline at end of file + }