-
-
Notifications
You must be signed in to change notification settings - Fork 5
New Beginner and Advanced Practice and Solutions #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
03c3ff7
added HelloWorld Example and Solution!
armeetj 2a48437
Added Comments exercise to practice comments (Java Beginners, Chapter 1)
armeetj bb68ef0
finished VariableTypes exercise and solution
armeetj a2a2eb8
fixed VariableTypes package names
armeetj b9f1238
ApplesOranges exercise complete
armeetj 3c4a093
finished CarDealership exercise
armeetj f1858cb
completed LinkedList implementation Challenge for Advanced Group
armeetj cfc050c
fix package name errors for Solutions
armeetj db58c32
formatted
armeetj 542423b
attempt #2: fixing formatting
armeetj 85bda2c
adding to comments
armeetj e92fb41
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj f6977c7
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj cca23c2
Update src/com/codefortomorrow/beginner/chapter2/practice/VariableTyp…
armeetj 47b6725
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj 199fb87
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj 40b8662
Update src/com/codefortomorrow/beginner/chapter2/solutions/VariableTy…
armeetj 1b3fbfd
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 6610010
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 84ad074
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 640cb85
Update src/com/codefortomorrow/advanced/chapter16/practice/LinkedList…
armeetj 8017009
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj e4e6db9
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj 9ac5b2d
made requested changes
armeetj 2b5e02d
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj 2d8da5d
made all changes 2
armeetj 17cb81d
Update src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.…
armeetj acd3db8
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj 0995938
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj 508db44
Update/add javadoc comments (for consistency)
phrdang 44713c4
revision 3
armeetj 9413324
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj 48dc66b
Update src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld…
armeetj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
|
||
# ignore files | ||
c4t-java.iml | ||
.DS_Store | ||
.DS_Store | ||
|
27 changes: 27 additions & 0 deletions
27
src/com/codefortomorrow/advanced/chapter16/practice/LinkedList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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 | ||
* 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 | ||
* - 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 {} |
164 changes: 164 additions & 0 deletions
164
src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package com.codefortomorrow.advanced.chapter16.solutions; | ||
|
||
/** | ||
* @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 | ||
* 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 | ||
* - 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 { | ||
|
||
private LinkedListNode head; | ||
|
||
/** | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* default constructor | ||
*/ | ||
public LinkedList() { | ||
head = null; | ||
} | ||
|
||
/** | ||
* constructor with first value | ||
* @param value first element in the linked list | ||
*/ | ||
public LinkedList(int value) { | ||
// create first node | ||
head = new LinkedListNode(value, null); | ||
} | ||
|
||
/** | ||
* get head of Linked List | ||
* @return first element of the linked list | ||
*/ | ||
public LinkedListNode head() { | ||
return this.head; | ||
} | ||
|
||
/** | ||
* traverse and get tail of linked list | ||
* @return last element of the linked list | ||
*/ | ||
public LinkedListNode tail() { | ||
LinkedListNode current = head; | ||
if (current == null) return null; | ||
|
||
while (current.next() != null) { | ||
current = current.next(); | ||
} | ||
|
||
return current; | ||
} | ||
|
||
/** | ||
* 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(); | ||
if (tail == null) { | ||
head = new LinkedListNode(value, null); | ||
} else { | ||
tail.setNext(new LinkedListNode(value, null)); | ||
} | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* push (add element to head of linkedlist) | ||
*/ | ||
public void push(int value) { | ||
LinkedListNode newHead = new LinkedListNode(value, head); | ||
head = newHead; | ||
} | ||
|
||
/** | ||
* pop (remove and return head of linkedlist) | ||
* @return the node that was removed | ||
*/ | ||
public LinkedListNode pop() { | ||
LinkedListNode popped = head; | ||
head = head.next(); | ||
return popped; | ||
} | ||
|
||
/** | ||
* Returns a String version of the LinkedList | ||
* @return a String version of the LinkedList | ||
*/ | ||
@Override | ||
public String toString() { | ||
String list = "["; | ||
LinkedListNode current = head; | ||
if (current == null) return null; | ||
do { | ||
list += Integer.toString(current.value()) + ", "; | ||
current = current.next(); | ||
} while (current != null); | ||
|
||
// Remove trailing comma and space after last list element | ||
list = list.substring(0, list.length() - 2); | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return list + "]"; | ||
} | ||
} | ||
|
||
class Node { | ||
|
||
private int value; | ||
|
||
/** | ||
* Constructs a list node with the given value | ||
* @param value the value stored in this Node | ||
*/ | ||
public Node(int value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Returns the value of this Node | ||
* @return the value of this Node | ||
*/ | ||
public int value() { | ||
return this.value; | ||
} | ||
} | ||
|
||
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; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/com/codefortomorrow/beginner/chapter1/practice/Comments.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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... | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(""); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.codefortomorrow.beginner.chapter1.solutions; | ||
|
||
/** | ||
* @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! | ||
*/ | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.codefortomorrow.beginner.chapter1.solutions; | ||
|
||
/** | ||
* @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{ | ||
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
armeetj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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!"); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/com/codefortomorrow/beginner/chapter2/practice/ApplesOranges.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 using variables, output: "I have 10 oranges." (line 21) | ||
|
||
|
||
// print out number of apples using variables, output: "I have 24 apples." (line 24) | ||
|
||
|
||
} | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
src/com/codefortomorrow/beginner/chapter2/practice/VariableTypes.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.codefortomorrow.beginner.chapter2.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) | ||
|
||
|
||
// define a character variable on line 27 | ||
|
||
|
||
// define a string variable on line 30 | ||
|
||
|
||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.