Skip to content

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 33 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
03c3ff7
added HelloWorld Example and Solution!
armeetj Mar 15, 2021
2a48437
Added Comments exercise to practice comments (Java Beginners, Chapter 1)
armeetj Mar 15, 2021
bb68ef0
finished VariableTypes exercise and solution
armeetj Mar 15, 2021
a2a2eb8
fixed VariableTypes package names
armeetj Mar 15, 2021
b9f1238
ApplesOranges exercise complete
armeetj Mar 15, 2021
3c4a093
finished CarDealership exercise
armeetj Mar 15, 2021
f1858cb
completed LinkedList implementation Challenge for Advanced Group
armeetj Mar 15, 2021
cfc050c
fix package name errors for Solutions
armeetj Mar 15, 2021
db58c32
formatted
armeetj Mar 15, 2021
542423b
attempt #2: fixing formatting
armeetj Mar 15, 2021
85bda2c
adding to comments
armeetj Mar 15, 2021
e92fb41
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
f6977c7
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
cca23c2
Update src/com/codefortomorrow/beginner/chapter2/practice/VariableTyp…
armeetj Mar 16, 2021
47b6725
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj Mar 16, 2021
199fb87
Update src/com/codefortomorrow/beginner/chapter2/solutions/ApplesOran…
armeetj Mar 16, 2021
40b8662
Update src/com/codefortomorrow/beginner/chapter2/solutions/VariableTy…
armeetj Mar 16, 2021
1b3fbfd
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
6610010
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
84ad074
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
640cb85
Update src/com/codefortomorrow/advanced/chapter16/practice/LinkedList…
armeetj Mar 16, 2021
8017009
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
e4e6db9
Update src/com/codefortomorrow/advanced/chapter16/solutions/LinkedLis…
armeetj Mar 16, 2021
9ac5b2d
made requested changes
armeetj Mar 16, 2021
2b5e02d
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj Mar 16, 2021
2d8da5d
made all changes 2
armeetj Mar 16, 2021
17cb81d
Update src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.…
armeetj Mar 16, 2021
acd3db8
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj Mar 16, 2021
0995938
Update src/com/codefortomorrow/beginner/chapter2/practice/ApplesOrang…
armeetj Mar 16, 2021
508db44
Update/add javadoc comments (for consistency)
phrdang Mar 16, 2021
44713c4
revision 3
armeetj Mar 22, 2021
9413324
Merge branch 'master' of https://github.com/ArmeetJatyani/java
armeetj Mar 22, 2021
48dc66b
Update src/com/codefortomorrow/beginner/chapter1/solutions/HelloWorld…
armeetj Mar 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

# ignore files
c4t-java.iml
.DS_Store
.DS_Store

# ignore prettier files
.prettierrc.json
Original file line number Diff line number Diff line change
@@ -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 {}
153 changes: 153 additions & 0 deletions src/com/codefortomorrow/advanced/chapter16/solutions/LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package com.codefortomorrow.advanced.chapter16.solutions;

// 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
* 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;
}
}
38 changes: 38 additions & 0 deletions src/com/codefortomorrow/beginner/chapter1/practice/Comments.java
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 src/com/codefortomorrow/beginner/chapter1/practice/HelloWorld.java
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 src/com/codefortomorrow/beginner/chapter1/solutions/Comments.java
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!
*/
}
}
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{
// 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!");
}
}
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, output: "I have 10 oranges." (line 21)


// print out number of apples, output: "I have 24 apples." (line 24)


}
}

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) on line 24


// define a character variable on line 27


// define a string variable on line 30


}
}

Loading