Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
0c8dec8
Merge pull request #1 from CMPSC1500-Spring17/master
jackhinze Jan 18, 2018
431ff16
Update chapter_2.md
SkylarGalloway Jan 18, 2018
709fb95
Update chapter_2.md
SkylarGalloway Jan 18, 2018
7719e71
Update chapter_2.md
SkylarGalloway Jan 18, 2018
ee853ca
Update chapter_2.md
SkylarGalloway Jan 18, 2018
0a9d86e
Update chapter_2.md
jackhinze Jan 18, 2018
232b096
Update chapter_2.md
jackhinze Jan 18, 2018
83e114b
Update chapter_2.md
jackhinze Jan 18, 2018
992f2bf
Update chapter_2.md
SkylarGalloway Jan 18, 2018
9fb4569
Merge pull request #2 from CMPSC1500-Spring17/master
jackhinze Jan 18, 2018
7b8d21f
Merge pull request #1 from CMPSC1500-Spring17/master
dburrigh Jan 18, 2018
b6555d9
Merge pull request #2 from CMPSC1500-Spring17/master
elijahbeed Jan 18, 2018
2ba42ec
Merge pull request #1 from CMPSC1500-Spring17/master
jakemarshall16 Jan 18, 2018
b17a25a
Merge pull request #3 from jakemarshall16/master
jakemarshall16 Jan 18, 2018
238fb54
Update chapter_2.md
SkylarGalloway Jan 25, 2018
f8b34d3
Update chapter_2.md
SkylarGalloway Jan 25, 2018
e5db0b3
Update chapter_2.md
jackhinze Jan 25, 2018
49f54a7
Update chapter_2.md
jackhinze Jan 25, 2018
4a16564
Create Chapter_3.md
jifland Jan 31, 2018
5c228e8
Rename chapter_2.md to Chapter_2.md
jifland Jan 31, 2018
b8e6cd0
Update Chapter_3.md
jifland Jan 31, 2018
2ebb0a8
Update Chapter_3.md
jifland Jan 31, 2018
f64c35a
Update Chapter_3.md
jifland Jan 31, 2018
86ca381
Update Chapter_3.md
jifland Jan 31, 2018
bea180e
Update Chapter_3.md
jifland Jan 31, 2018
d6aafc0
Update Chapter_3.md
jifland Jan 31, 2018
6d5afd7
Update Chapter_3.md
jifland Jan 31, 2018
c9a387d
Update Chapter_3.md
jifland Feb 1, 2018
d5038ac
Update Chapter_3.md
jifland Feb 1, 2018
63e78aa
Update Chapter_3.md
jifland Feb 1, 2018
c456af7
Merge pull request #4 from elijahbeed/master
elijahbeed Feb 6, 2018
5785d22
Merge pull request #3 from CMPSC1500-Spring17/master
elijahbeed Feb 6, 2018
6ee2386
Rename chapter_2.md to Chapter_2.md
jifland Feb 6, 2018
63558c5
Merge pull request #2 from jifland/patch-1
SkylarGalloway Feb 6, 2018
f8c9455
Merge branch 'master' into master
SkylarGalloway Feb 6, 2018
bd7ee22
Merge pull request #1 from CMPSC1500-Spring17/master
SkylarGalloway Feb 6, 2018
3deed34
Merge pull request #5 from elijahbeed/master
elijahbeed Feb 8, 2018
f87b20a
Merge pull request #4 from CMPSC1500-Spring17/master
elijahbeed Feb 8, 2018
5029f1b
Update Chapter_3.md
SkylarGalloway Feb 8, 2018
3cdb2df
Update Chapter_3.md
SkylarGalloway Feb 8, 2018
ddf7ddb
Rename Chapter_3.md to Chapter_3 Updated.md
SkylarGalloway Feb 8, 2018
5b4ffe9
Update Chapter_3 Updated.md
SkylarGalloway Feb 8, 2018
e8d3160
Update Chapter_3 Updated.md
SkylarGalloway Feb 8, 2018
225a2c9
Update Chapter_3 Updated.md
SkylarGalloway Feb 8, 2018
31d7274
adding notes for using intelliJ and a sample program
jifland Feb 8, 2018
fcb81c6
Merge pull request #6 from elijahbeed/master
elijahbeed Feb 8, 2018
8c3a070
Merge pull request #5 from CMPSC1500-Spring17/master
elijahbeed Feb 8, 2018
a0bb3c9
Merge pull request #7 from dburrigh/master
dburrigh Feb 8, 2018
607eed3
Merge pull request #3 from CMPSC1500-Spring17/master
SkylarGalloway Feb 8, 2018
83c09e9
Rename chapter_2.md to Chapter_2.md
jackhinze Feb 8, 2018
5e0221e
Merge branch 'master' into master
jackhinze Feb 8, 2018
607d146
work
SkylarGalloway Feb 8, 2018
a699e10
Update Chapter_2.md
SkylarGalloway Feb 13, 2018
b70455e
Update and rename Chapter_2.md to Chapter_2 updated.md
SkylarGalloway Feb 13, 2018
8654291
Update Chapter_2 updated.md
SkylarGalloway Feb 13, 2018
8fb9cc7
Update Chapter_2 updated.md
SkylarGalloway Feb 13, 2018
a8596a6
Update Chapter_2.md
SkylarGalloway Feb 15, 2018
506bd7e
Update Chapter_3 Updated.md
SkylarGalloway Feb 15, 2018
40521ad
Created new files with updated solution
SkylarGalloway Feb 15, 2018
2a5f9a1
updated
SkylarGalloway Feb 15, 2018
ff0016c
Rename classroom.md to GitHub classroom.md
jifland Feb 20, 2018
cf6658e
Create Using-GitHub.md
jifland Feb 20, 2018
49ca398
Update Using-GitHub.md
jifland Feb 20, 2018
926d70b
Update Using-GitHub.md
jifland Feb 20, 2018
d8ea6b8
Add files via upload
jifland Feb 21, 2018
d1ded9c
Add files via upload
jifland Feb 28, 2018
41cba94
Rename Chapter_2 updated.md to Chapter_2.md
SkylarGalloway Mar 1, 2018
1028c33
Merge branch 'master' into master
SkylarGalloway Mar 1, 2018
6ac80e5
method examples
jifland Mar 1, 2018
c76940c
Merge pull request #8 from elijahbeed/master
elijahbeed Mar 1, 2018
b0be943
Add files via upload
jifland Mar 12, 2018
b19a11a
Create Covered Sections.md
jifland Mar 12, 2018
10fec1c
Create Calculator.java
jifland Mar 20, 2018
9b194c2
Create Calculator2.java
jifland Mar 20, 2018
4777a6e
Create tictactoe.java
jifland Mar 20, 2018
4ceab11
Create fibo.java
jifland Mar 22, 2018
3cd8c67
Create tictactoeComplete.java
jifland Mar 22, 2018
44b37d9
Create fiboRecursive.java
jifland Mar 22, 2018
311bccf
Create ToBinary.java
jifland Mar 22, 2018
95f1363
Adding the fib example with memoization from class today.
jifland Mar 29, 2018
dff2429
Adding in the point Object class and the main running class.
jifland Apr 5, 2018
8506067
Adding in the array example
jifland Apr 5, 2018
ed4f809
adding in array fix
jifland Apr 5, 2018
9676330
Create Array
jackhinze Apr 5, 2018
78aa646
Create Point
jackhinze Apr 5, 2018
4d25ff9
Adding in the calculator example from class
jifland Apr 10, 2018
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
61 changes: 40 additions & 21 deletions chapter_2.md → Chapter_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,52 @@ Problem:
Start this with pseudocode

#### Variables
These are named places to hold information in your program. The informaiton can be of different types: a char, a sequenc of characters (String), an integer, a number with a decimal (Float), a list, a dictionary, a grid of one of these types.
These are named places to hold information in your program. The informaiton can be of different types: a char, a sequence of characters (String), an integer, a number with a decimal (Float), a list, a dictionary(include array and etc) , a grid of one of these types.

Each variable is like a pad of sticky notes. You can write on the front sheet, and when you want, you can rip that sheet off, and write something (possibly different) on the newly exposed sheet. The variable name holds the information on the currently showing sticky note.

#### Operators
You are familar with multiple binary operators (meaingin they work on two items at once). Multiplication * , Division / , Addition + , Subtraction - .
You are familar with multiple binary operators (meaning in they work on two items at once). Multiplication * , Division / , Addition + , Subtraction - . Modulo(%) is used instead of division (/) when dealing with int because if there is a decimal it is trunkated(cutout)

Does order mater with the operands of an operator? (the order of the items that are passed to the operator?)
Does order matter with the operands of an operator? (the order of the items that are passed to the operator?)

If we are only able to use integers for the above operations, what piece of information are we loosing when we store the answer back to an integer? The operator to get this info with one step is the % operator.

We have a special operator, it is the assignment operator. This is the operator that removes the top sheet of the stickynote pad and writes a value on the next sheet. In Java we will use a single equals sign to indicate this. In your book they use a left pointing arrow in pseudocode to represent this. You can probably guess that a variable must be on the left side (the sticky note pad we are going to place a value on for later use), and a value of the appropriate type on the right hand side.

if all letters in the next lines are integers, is the folowing valid, why:

if all letters in the next lines are integers, is the following valid, why:
* a = b + c
* g = h / i
* r + s = t * u
when evaluating the statement above the addition is done first (all of the rules of operand is done) and assignment done last
as it process it does the following a=(b+c)
**g = h / i
Same as first *

*** r + s = t * u
INVAILD- does not work


There are other operators that we will talk about as the class progresses.

##### testing operators
There are operators that return true or false instead of a numeric value. Many of these you are already familar with, and most are binary (take two operands):
* < less than
* > greater than
* <= less than or equal to
* >= greater than or equal to
* == equal to
* != not equal to

There are operators that return true or false instead of a numeric value. Many of these you are already familar with, and most are BINARY (take two operands):
(1) < less than
(2) > greater than
(3) <= less than or equal to
(4) >= greater than or equal to
(5) == equal to
(6) != not equal to

You can also combine logic tests together with the operators:
* && 'and' returns true if the items on either side are both true
* || 'or' returns true if at least one of the items on it's sides is true.

Finally our first unary operator (meaning it only takes one operand)
* ! 'not' returns false if the operand following it is ture, and returns true if that operand is false
(7) && 'and' returns true if the items on either side are both true
(8) || 'or' returns true if at least one of the items on it's sides is true.

Finally our first UNARY operator (meaning it only takes one operand)
* ! 'not' returns false if the operand following it is true, and returns true if that operand is false
** Can be used to negate statements
ie: !(a==5) reads as return true for a not equal to 5

#### Tracing a program
This is a skill that helps you track down what is happening during a program to find why it is not giving you the result you expected it to.

Expand All @@ -71,7 +81,9 @@ We will start by doing this on paper, and as we get towards coding, we will lear
#### Input and Output
A computer is a great tool, and it can do a lot. However if we can't communicate with it, it does us little good.

This is just trying to make you aware that we need tha ability to provide informaiton to our programs, and for our programs to provide inforamiotn back to us if we want the programs to truely be useful.

This is just trying to make you aware that we need tha ability to provide informaiton to our programs, and for our programs to provide information back to us if we want the programs to truely be useful.


For the sake of flowcharts, you can use the words input and output (print) for these steps. The book also uses these terms in it's fomalized pseudocode examples.

Expand All @@ -80,10 +92,12 @@ We can string these above steps together, but we need ways to only do the steps

##### If structure:
* if do this poriton of code only if the test is true
* if - else same as the if, but has a second porion of code that is followed only if the test is not true.
* if - else same as the if, but has a second portion of code that is followed only if the test is not true.
* if - else if Same as if-else, however only runs the second poriton if the first test if false and a second is true.

How to determin which to use? Partially practice, and being *lazy*.
How to determine which to use? Partially practice, and being *lazy*.



Write out an example of a program that gives an indication of a kid of what they should wear based upon the tempature.

Expand All @@ -104,3 +118,8 @@ The book describes this and two other methods of using a loops test to stop the

##### Combining these control structures:






191 changes: 191 additions & 0 deletions Chapter_3 Updated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
## Chapter 3

In this chapter we will start coding and talking about how the various portions of the Java language work.

### How do we convert our flow charts to code?

We have been using three things in our flowcharts:

#### Statements:
~~~
+---------------------------+
| Decrease the counter by 1 |
+---------------------------+
~~~
~~~
+---------------+
| Print "Hello" |
+---------------+
~~~
If they are simple, these will generally translate into a sngle line of code:
~~~
counter = counter -1;

system.out.print("Hello");
~~~
If they are complex, then we need to break them down further. As an example think of the statements in my algorithm where I asked does everyone know about the meeting.

#### Conditionals:
~~~
|
|
v
/ \
/ \ Yes
if our counter \-----------+
equals 5 / |
\ / v
\ / +---------------+
| | Statement 1 |
No | +---------------+
v |
+-----------------+ v
| Statement 3 | +---------------+
+-----------------+ | Statement 2 |
| +---------------+
| |
+-------------------+
|
v
~~~

This translates into the code:
~~~
if( counter == 5 )
{
Statement 1
Statement 2
}
else
{
Statement 3
}
~~~

#### loops

Any time we have an edge going back to a previous step, we have a loop. Thi is an indication that we want to do some steps multiple times.

When we have a loop either it has a conditional in it somewhere that has oneoption tht leaves the loop, or we have a never ending, infinate loop. We don't want infinate loops, so I'm going to assume that you have such a conditional in the sequence of steps that is repeated, similar to below:
~~~
|
v
+---------------+
| Statement 5 |
+---------------+
|
+-------->|
| |
| v
| +---------------+
| | Statement 6 |
| +---------------+
| |
| v
| / \
| / \ Yes +---------------+
| if temp is less \ --------->| Statement 9 |
| than 50 / +---------------+
| \ / |
| \ / |
| | No |
| v |
| +---------------+ |
| | Statement 7 | |
| +---------------+ |
| | |
| v |
| +---------------+ |
+-| Statement 8 | |
+---------------+ |
v
~~~

For this we will wait to start the loop until we get to the conditional, then we will create a loop with the exit condition:

~~~
Statement 5
Statement 6
while( temp >= 50 )
{
Statement 7
Statement 8
Statement 6
}
Statement 9
~~~

Note that with this condition we had to invert it, as the written test in the flowchart tested to exit the loop, not stay in it.

#### Tests
How can we test things in conditionals and loops?
~~~
When we test something we want the result to be true or false. We know of some of these and use them regularly:
* < less than
* > greater than
* == is equal to
* <= less than or equal to
* >= greater than or equal to
~~~
What if we need something to not be one of these things? For that we have a not opperator:
* !

it can be used with the is equal to opperator to modifyit:
* != is not equal to

or it can be used with any test:
* !( 5 > 8 )

note the parenthesis here to indicate what we want the oppisite truth value of (parenthesis still evaluate before the not opperator.)

How could you write the above "temp is less than 50" test other than changing the less than opperator?


So you may be asking "What do I do if things get more complicated?" For example what if you needed to test if a value was less than 10 or greater than 90?

There are multiple ways to do this, but to introduce you to one more tool for tests, I'm going to choose the method that is closest to what was written:
* (value < 10) || (value > 90)

There are two of these opperators:
* || logical OR. If the item on either side is true, then return true, otherwise return false.
* && logical AND. Only when the item on both sides is true, return true, otherwise return false.


This allows us to build up some wild sentances and translate them into logic:
If it is not the case that either the sky is blue or the water is red.

becomes:
if( !( (sky == blue) || (water == red) ) )

### Comments in Java
~~~
Use // to indicate that everything after is a comment *works for one row*
Use /*_____*/ to indicate that everything in between is to be seen as a comment
Use comments for assistance too many can be very messy and unneccessary
~~~

### Initial Set Up
~~~
- public class (NAME of File)
{
public static void main(String[]args) (*** These two things are needed to have java run/ This MAIN is a function**)
{
}
}
~~~
### Switch Statements
~~~
int i
switch(i%5)
{
case 0:
-insert commands if condition met for this case -
case 1
case 2
case 3
case 4
default:
print 'i is a multiple of 5"
}

~~~
62 changes: 62 additions & 0 deletions CodeExamples/Calculator/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.util.Scanner;

public class Calculator {

public static void main(String[] args) {

Stack numbers = new Stack();

// "5 3 + 7 *"
Scanner sysIn = new Scanner("5 3 % ");

while( sysIn.hasNextLine() ) {
String input = sysIn.nextLine();

Scanner process = new Scanner(input);

while( process.hasNext() ) {
String symbol = process.next();

switch(symbol) {
case "+":
case "-":
case "*":
case "/":
case "%":
calculate(symbol, numbers);
break;
default:
numbers.push( Float.valueOf(symbol) );
}
}
}

System.out.println(numbers.stackSize());

System.out.println(numbers.pop());


}

public static void calculate(String op, Stack stack) {
Float y = stack.pop();
Float x = stack.pop();
switch( op ) {
case "+":
stack.push(x + y);
break;
case "-":
stack.push(x - y);
break;
case "*":
stack.push(x * y);
break;
case "/":
stack.push(x / y);
break;
case "%":
stack.push(x % y);
}

}
}
Loading