2016-2017 Year In Review

Well, here I am – the last day of the 2016-2017 school year. It’s been a great ride this year.

June 2016

I had the experience of attending my first Advanced Placement Summer Institute! This was to prepare us for AP Computer Science Principles (AP Computer Science I).

This particular APSI was different from others in that it was not run by College Board, but by the UTeach Institute at University of Texas through the National Science Foundation.

July 2016

After learning about Computer Science in June, I shifted gears to learn about FIRST Robotics. I got to attend a week-long hands-on workshop with Freid Elliott of Dallas ISD and Dr. Patrick Michaud of University of Texas: Dallas.

This training was invaluable in preparing me for the launch of our new robotics program at Ferris High School. Without this workshop, I couldn’t even guess as to how long it would have taken us to get our robot moving.

August 2016

For the first time since August 2012, I had the opportunity to start a school year in a high school! I was very happy to be returning to high school for a full-year.

In August of 2013 and August 2014, I was teaching at The Art Institute of Dallas and in August 2015, I was teaching 4th grade at Ferris Intermediate School.

This year, I taught 1 section of Computer Science, 1 section of Robotics & Automation, 1 section of Principles of Technology/Physics, and 4 sections of Business Information Management (BIM).

September 2016

Now that the school-year was fully underway, I got started on teaching material.

In Computer Science, we hit the ground running with programming in JAVA. In Principles of Technology, we built pressurized soda-bottle rockets and launched them!

In Robotics & Automation, we had the reveal of the game for the 2016/2017 season – Velocity Vortex! It was exciting to see the gears turning as my students started planning how to address the challenge of the game for this year. They were very excited to start designing and building the robot for the game!

My robotics class had the opportunity to work on the Finch robots that were loaned to us from Carnegie Mellon University.

October 2016

Now that we knew the game for robotics, we started having “Come As You Can” (CAYC) workdays on Saturdays for students to come up to the high school and work on the robot.

Here, students were encouraged to come up to the high school to work on the contest robot. I would have the lab open and it was a self-paced workday. Each CAYC workday was typically 8 to 12 hours.

In addition to the robotics CAYC workdays, I had fun with my Principles of Technology class with an egg drop experiment. Here, they had to create a rig that could cushion the fall of a raw egg dropped from a considerable height.

There were 3 rigs that no matter the height, the egg survived again and again. I was very pleased. In the follow-up, the groups had to calculate the force their rig struck the ground with.

November 2016

The robotics team did the majority of their hardware work during this month. This was the month that we got the robot moving!

This was also when we had our only season scrimmage for robotics.

This was our first experience with one of the guiding principles of FIRST Robotics – “Coopertition”. This is the idea of cooperative competition. While this was a scrimmage in that we were able to see what the robots of others teams were able to do, it was also a workshop for us to be able to refine our skills and the build of our robot.

During this month, Principles of Technology worked on creating mouse trap racers.

They had the chance to demonstrate their ability to mix-and-match parts to maximize their designs.

The parts for this project were donated from Donors Choose over the summer in preparation for the school year.

December 2016

As we began to wind-down the 2016 calendar year, the robotics team arrived at their first of 3 league meets which was hosted at Ferris High School.

The robotics team performed very well in their first outing and assumed 2nd place in the season standings. This was an outstanding way to start our inaugural season of FIRST Tech Challenge robotics!

UIL Computer Science also kicked off this month with its first virtual meet. Back in the 2015/2016 academic year, the UIL Computer Science team advanced on its own to UIL Regional competition as a student-run after-school club!

January 2017

This month saw two robotics league meets. Both of these meets were at Mansfield Ben Barber Innovation Academy.

In addition, between the two league meets, the robotics team presented at Ferris Intermediate School addressing the disproportionate representation of girls in STEM fields.

The various members of the robotics team had an enjoyable time working with the students at FIS!

February 2017

This month was really “hot” in multiple ways. The robotics team hosted the league tournament at Ferris High School.

ERROR 404, the FHS robotics team, entered the tournament in 4th place and by the end of the day was solidly in 3rd place.

The team performed very well and had a strong alliance partner as they advanced into the elimination round of the tournament. Unfortunately, we saw the season come to an end in the blink of an eye when a spectator turned on a WiFi hotspot on their phone, which caused our robot to stop.

The Tuesday following the league meet, the month got even hotter when an experiment in my Principles of Technology class went very wrong!

Just 4 days after that fire, the Computer Science team performed in its only face-to-face invitational meet in Mabank. The team from Ferris High School finished in 1st place at the invite!

March 2017

As robotics shifted into off-season mode, and I was looking to regain footing by retooling some experiments in Principles of Technology, March was all about Computer Science.

In late-March, the UIL Computer Science team competed in the UIL District Tournament where they finished in 1st place and advanced to the UIL Regional Tournament!

I was extremely proud of how our team captain performed at this tournament and his decision to hand over the reins to his successor so she could gain some experience in the role she has shadowed for the past two seasons.

April 2017

As we had “played with fire” in February in Principles of Technology, I elected that water would be much safer for us to play with.

So, in mid-April, Principles of Technology built water balloon launchers and launched to strike targets at 20, 40, and 50 yards. To make this more fun, the targets were Mr. Mack McClesky (FHS Assistant Principal), myself, and Dr. Kevin Dixon (FHS Principal) respectively.

Students had to calculate maximum range, height, and launch angles in this experiment!

In addition to getting soaked, this month was also the UIL Computer Science team appearance at the UIL Regional Tournament at Texas A&M University: Commerce.

The UIL Computer Science team had a bit of a rough performance at the UIL Regional Tournament. I believe this was in-part due to over-preparing.

I appreciated with enthusiasm of the team members, but I think they over-worked themselves and succumbed to “brain drain” and fatigue ultimately did them in and they were just overwhelmed with information as they went into the test.

While we did not perform as well on the written test, the team demonstrated outstanding growth on the hands-on test. In 2015/2016, the team solved no hands-on problems at the UIL Regional Tournament. In contrast, the team solved 3 hands-on problems at the UIL Regional Tournament in 2016/2017!

On a personal note, April was when I said “Goodbye” to my home of 9 years in Forney.

For two of my children, this is the only house they really remember. Over the past several years, we have seen Forney grow from a semi-rural community to a suburban community where possessions and materialism have taken over and you are solely based upon what you have and how much you have.

We elected to move to the community where I teach in and where my oldest daughter elected to attend junior high at – Ferris.

It was a bit of a shift to go from a home that we built and was only 10 years old to a home that is over 100 years old. Our new home was built in 1894 and is now 123 years old! The pace of life in this community is wonderful and I would not go back to the suburban rush ever again, if I can have any say in it!

May 2017

Now, we have come full-circle. It has been a year! Both Robotics and Computer Science are in off-season mode and preparing for next year.

Principles of Technology finished the year with a project similar to the one we started the year with, using the 2-liter soda bottles. Unlike the project at the start of the year, students had to create an air foil to achieve non-projectile motion flight with the thrust provided by the pressurized 2-liter soda bottle.

I am looking forward to seeing my graduates walk across that stage and close one chapter in their lives and open the next new chapter! I am excited to hear how they continue to mature, grow, and develop.

I am very excited to see the programs and teams that were launched this year continue to develop next year.

In 2017/2018, we will be launching 2 new engineering courses:

  • Principles of Applied Engineering
  • Engineering Design & Problem Solving

In addition to those two new courses, we will be streamlining the robotics courses:

  • Robotics I
  • Robotics II

We will also be expanding our Computer Science program:

  • Computer Science I (based on AP Computer Science Principles)
  • Computer Science II (based on AP Computer Science – A)

I am extremely blessed to work for a school district and on a campus that supports my out-of-the-box teaching style and methods. I look forward to continuing to work in Ferris and with the children of this community.

A Real Final Exam: Computer Science

Well, since entering K-12 education in the 2004/2005 school year, I have now written and administered my first “real” semester exams!

While I have always given exams at the conclusion of the semesters, I have never really given a genuine exam “experience”. There would be a test. That test usually consisted of 50 questions. 25 of the questions were True/False and 25 were Multiple Choice. The students were given a single sentence review guide of “Always Be True to Yourself”.

Now, with that as the review guide, I think you could safely guess that the answers were “B” and “True”. Your guess would be correct. Sadly, I did have students fail that test.

The test was not a “give-me grade” since there was usually a major end-of-year project that the majority of their semester grade was based upon. This final was created so we could simply check a box that said we gave a paper final.

This year, I opted to write and administer a genuine rigorous exam as I was not using any major end-of-year projects.

Computer Science (EOY) Final Exam – Test

Computer Science (EOY) Final Exam – Answer Key

As you can see, this is a bit more rigorous of a test. In fact, all of the questions require a calculated answer.

Once the tests are completed, I will analyze student performance in another post.

Spring Exam Exemptions

It is that time of the year again. It’s time for spring semester exams and ’tis exemption season! This is the season when students start seeking if they qualify to be exempt from having to take the semester exam in a given class.

Each school I have had the opportunity to work at does this process differently and each school has used different criteria to determine eligibility for exemptions.

Exemptions (Spring 2017 Finals)
Exemptions (Spring 2017 Finals)

Here, you can see that I have a total of 146 students. There are 88 students enrolled in Business Information Management (BIM) across 4 sections. There are 15 students in my single section of Computer Science I. There are 25 students in my single section of Principles of Technology. There are 18 students in my single section of Robotics & Automation.

As you can see in the chart, 51 of the 88 BIM students are eligible to be exempt from their spring semester exam. This means that 57.9% of my BIM students are eligible to be exempt from their exam!

In Computer Science, that percentage rises to 66.7% are exempt and in Robotics and Automation is continued to climb us to 72.2%!

Unfortunately, in my Principles of Technology, the percentage plummets to 48%. This has been due to poor grade performance because many teams elected to not submit required documentation with their projects throughout the semester.

As Computer Science, Robotics & Automation, and Principles of Technology are stand-alone single-section courses, let’s take a quick look at how each of the BIM sections performed individually.

BIM Exemptions (Spring 2017 Finals)
BIM Exemptions (Spring 2017 Finals)

Here is the break-out of the 4 sections of BIM that I teach.

While the average for all 4 sections of BIM was 57.9%, 1 section performed well above that average, 1 section section performed well below that average, and the other 2 held pretty close to that average.

  • 2(B) has 10 of 23 students qualifying for exemptions, which is 43.4%.
  • 3(B) has 14 of 23 students qualifying for exemptions, which is 60.8%.
  • 4(B) has 14 of 19 students qualifying for exemptions, which is 73.6%.
  • 4(A) has 13 of 23 students qualifying for exemptions, which is 56.5%.

Compared to past years, this is close to what I have experienced as far as exam exemption qualification is concerned.

Python Recursion and Factorial

As the final Computer Science lesson of the 2016/2017 academic year, I reviewed the somewhat concept of recursion in the Python programming language. In this review, I used the mathematical concept of factorial to discuss recursion.

#Program Name: Recursion Sample
#Programmer Name: Eric Evans, M.Ed.
#Program Description: Provide a functional example of a recursion problem in Computer Science using the mathematical concept of factorial.
#
#Define function named factorial which will have an input value of n.
def factorial(n):
    print("Factorial has been called with n = " + str(n))
    if n == 1:
        return 1
    else:
        result = n * factorial(n-1)
        print(n,"! = ",result)
        return result
#Output the function factorial with an input value of 4.
print(factorial(4))

Let’s pull this concept apart line-by-line.

Lines 1 through 5 and line 14 are comment lines and have no real bearing on the program. They simply exist for documentation purposes.

At line 6, we declare a new function named “factorial” that will receive an input of “n”. This is done using the def or define call in Python. The “factorial” function occupies lines 6 through 13.

On line 7, we output the text “Factorial has been called with n = ” concatenated with the value of “n” cast as a string.

On lines 8 and 9, we enter the first part of a conditional statement. At line 8, we use a Boolean equals to see if “n” is equal to 1. If “n” is equal to 1, then line 8 executes and returns the value “1”.

Line 10 begins the process of addressing what to do if “n” does not equal 1.

On line 11, we declare a variable named “result”, which is defined as the value of “n” multiplied by the value of the “factorial” function with an input value that is one less than the current value of “n”.

Line 12 is simply allowing us to see the factorial value of the current “n” value each time through the loop.

Line 13 returns the value of the variable named “result”.

Line 15 calls the “factorial” function and provides it the necessary input to process. In this case, it is a 4.

Now, let’s see what happens when we run this code:

Factorial has been called with n = 4
Factorial has been called with n = 3
Factorial has been called with n = 2
Factorial has been called with n = 1
2 ! =  2
3 ! =  6
4 ! =  24
24

So, let’s see what’s going on with this output.

Lines 1 through 4 of the output are generated by line 7 of the code. That code displays the static words with the dynamic output of the value of “n”. Notice that each time through the loop, it decremented by 1.

Looking at lines 5 through 7 of the output, we see that the calculations actually start with the lowest factorial number of 2 and increment by 1.

Now, if you notice, the way the calculation was coded on line 11, we are performing the following:

  • (Step 1)  4! = 4 X 3!
    • This is the original problem. Solve for 4!, but it is defined needing to know the value of 3!, which is defined in step 2.
  • (Step 2)  3! = 3 X 2!
    • To solve step 1, we need to know the value of 3!. However, it is defined needing to know the value of 2!, which is defined in step 3.
  • (Step 3)  2! = 2 X 1!
    • To solve step 2, we need to know the value of 2!. However, it is defined needing to know the value of 1!, which is defined in step 4.
  • (Step 4)  1! = 1
    • To solve 3, we need to know the value of 1!. It has a given value of 1.
  • (Step 5)  2! = 2 X 1 = 2
    • Now, that we know the value of 1!, we can calculate the value of 2!.
  • (Step 6)  3! = 3 X 2 = 6
    • Now that we know the value of 2!, we can calculate the value of 3!.
  • (Step 7)  4! = 4 X 6 = 24
    • Now that we know the value of 3!, we can calculate the value of 4!, which was the original problem.

As you can see, the final solution is dependent upon the solution of a previous step, which was dependent upon the solution of a previous step, which was dependent upon the solution of a previous step, which – well you get the idea. This is the basic concept of recursion.

Basic Variables in Python

Today, we have been playing with basic variables in Python. The plan is to output something similar to the following:

Hello World
1 + 1 = 2
2 + 2 = 4
4 + 4 = 8

This output is to be generated entirely from calling variables.

#Programmer Name: Eric Evans, M.Ed.
#Program Name: 02 - Hello Variable
#Program Description: Outputs assigned information using only variables.
#
#DECLARATION OF VARIABLES
firstWord = "Hello"
secondWord = "World"
space = ' '
#OUTPUT
print(firstWord + space + secondWord)

Now, as you can see, the first line of the output is somewhat easy to code. We declared the variables firstWord, secondWord, and space and then called them to print concatenated together.

#Programmer Name: Eric Evans, M.Ed.
#Program Name: 02 - Hello Variable
#Program Description: Outputs assigned information using only variables.
#
#DECLARATION OF VARIABLES
firstWord = "Hello"
secondWord = "World"
space = ' '
firstAddend = 1
firstProblemSum = firstAddend + firstAddend
secondAddend = firstProblemSum
secondProblemSum = secondAddend + secondAddend
thirdAddend = secondProblemSum
thirdProblemSum = thirdAddend + thirdAddend
#OUTPUT
print(firstWord + space + secondWord)
print(firstAddend + " + " + firstAddend + " = " + firstProblemSum)
print(secondAddend + " + " + secondAddend + " = " + secondProblemSum)
print(thirdAddend + " + " + thirdAddend + " = " + thirdProblemSum)

Things start to act problematically when we try to produce the last 3 lines of output. When we run the application, we receive an error because we are attempting to mix string and integer variables on a combined output line.

To resolve this issue, we must typecast the integers as strings.

#Programmer Name: Eric Evans, M.Ed.
#Program Name: 02 - Hello Variable
#Program Description: Outputs assigned information using only variables.
#
#DECLARATION OF VARIABLES
firstWord = "Hello"
secondWord = "World"
space = ' '
firstAddend = 1
firstProblemSum = firstAddend + firstAddend
secondAddend = firstProblemSum
secondProblemSum = secondAddend + secondAddend
thirdAddend = secondProblemSum
thirdProblemSum = thirdAddend + thirdAddend
#CASTING OF VARIABLES
firstProblemSum = str(firstProblemSum)
firstAddend = str(firstAddend)
secondProblemSum = str(secondProblemSum)
secondAddend = str(secondAddend)
thirdProblemSum = str(thirdProblemSum)
thirdAddend = str(thirdAddend)
#OUTPUT
print(firstWord + space + secondWord)
print(firstAddend + " + " + firstAddend + " = " + firstProblemSum)
print(secondAddend + " + " + secondAddend + " = " + secondProblemSum)
print(thirdAddend + " + " + thirdAddend + " = " + thirdProblemSum)

As you can see, on lines 15 – 21 we cast each of the integer variables as a string variable. At this point, lines 24 – 26 will execute as expected.

The compilable code can be viewed at https://repl.it/HesM/3

Boolean Truth Tables

In my Computer Science class, we are revisiting Boolean operators and are looking more in-depth at Boolean Truth Tables.

In this post, I will look at the Boolean operators of AND, OR, NAND, NOR, and XOR.

For clarification, the following are considered equal and will be used in the post:

a AND b > c is equal to a . b > c

a NAND b > c is equal to a . b > c

a OR b > c is equal to a + b > c

a NOR b > c is equal to a + b > c

a XOR b > c is equal to a ⊕ b > c

For additional clarification, here are the logic gate representations of each of the objects that are presented:

Boolean AND & NAND Logic Gates
Boolean AND & NAND Logic Gates
Boolean OR & NOR Logic Gates
Boolean OR & NOR Logic Gates
Boolean XOR & NOT Logic Gates
Boolean XOR & NOT Logic Gates

So, let’s build our truth tables for each of the above named scenarios:

a . b > c
A B Result
TRUE TRUE TRUE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE FALSE

In this scenario, let’s say that a = 10, b = 5, and c = 7. In this case, the statement A > C is TRUE. However, the statement B > C is FALSE. If we look at the truth table above, the result is that the entire statement is now FALSE.

For an AND statement to be TRUE, all parts of the statement must be TRUE.

a + b > c
A B Result
TRUE TRUE TRUE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE

In this scenario, let’s say that a = 10, b = 5, and c = 7. In this case, the statement A > C is TRUE. However, the statement B > C is FALSE. If we look at the truth table above, the result is that the entire statement is now TRUE.

For an OR statement to be TRUE, at least one part up to all parts of the statement must be TRUE.

a . b > c
A B Result
TRUE TRUE FALSE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE TRUE

In this scenario, let’s say that a = 10, b = 5, and c = 7. In this case, the statement A > C is TRUE. However, the statement B > C is FALSE. If we look at the truth table above, the result is that the entire statement is now TRUE.

For a NAND statement to be TRUE, at least one part up to all parts of the statement must be FALSE.

a + b > c
A B Result
TRUE TRUE FALSE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE TRUE

In this scenario, let’s say that a = 10, b = 5, and c = 7. In this case, the statement A > C is TRUE. However, the statement B > C is FALSE. If we look at the truth table above, the result is that the entire statement is now FALSE.

For a NOR statement to be TRUE, all parts of the statement must be FALSE.

a ⊕ b > c
A B Result
TRUE TRUE FALSE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE

In this scenario, let’s say that a = 10, b = 5, and c = 7. In this case, the statement A > C is TRUE. However, the statement B > C is FALSE. If we look at the truth table above, the result is that the entire statement is now TRUE.

For a XOR statement to be TRUE, at least one condition in the statement must be TRUE. However, if all conditions in the statement are TRUE, then the result is FALSE.

2-Dimensional Arrays in Java

Today, we started to cover 2-dimensional arrays in Java. I decided to start with something very easy:

2-D Array Visual
2-D Array Visual

We have an array with 2 rows and 3 columns. Like all things in Java, we start counting our indices at 0.

As such, the value of [0][0] is Vanilla and [1][0] is Ice Cream. Note that the first number in the reference points to the row and the second number in the reference points to the column.

import java.util.*;
public class TwoDArrays {
    public static void main(String[] args){
        String[][] myBigArray = new String [][] {
            {"Vanilla ", "Chocolate ", "Strawberry "},
            {"Ice Cream", "Cookie", "Candy"}
        };
        System.out.println(myBigArray[0][0] + myBigArray[1][0]);
        System.out.println(myBigArray[0][1] + myBigArray[1][0]);
        System.out.println(myBigArray[0][2] + myBigArray[1][0]);
        
        System.out.println(myBigArray[0][0] + myBigArray[1][1]);
        System.out.println(myBigArray[0][1] + myBigArray[1][1]);
        System.out.println(myBigArray[0][2] + myBigArray[1][1]);
        
        System.out.println(myBigArray[0][0] + myBigArray[1][2]);
        System.out.println(myBigArray[0][1] + myBigArray[1][2]);
        System.out.println(myBigArray[0][2] + myBigArray[1][2]);
    }
}

Line 4 is where we created the 2-dimensional array named “myBigArray”.

Lines 5 and 6 are where we populated the array. Note that line 5 is the first row and line 6 is the second row.

Lines 8 through 18 are where we are outputting text that is “fed” by the 2-D array.

Line 8 concatenates [0][0] with [1][0] which is Vanilla and Ice Cream.

Line 9 concatenates [0][1] with [1][0] which is Chocolate and Ice Cream.

Line 10 concatenates [0][2] with [1][0] which is Strawberry and Ice Cream.

Line 12 concatenates [0][0] with [1][1] which is Vanilla and Cookie.

Line 13 concatenates [0][1] with [1][1] which is Chocolate and Cookie.

Line 14 concatenates [0][2] with [1][1] which is Strawberry and Cookie.

Line 16 concatenates [0][0] with [1][2] which is Vanilla and Candy.

Line 17 concatenates [0][1] with [1][2] which is Chocolate and Candy.

Line 18 concatenates [0][2] with [1][2] which is Strawberry and Candy.

Flipping Stacks

We are now going to look at how to flip a stack. As was discussed previously, a stack is an ideal method for holding items in a queue such as an incoming call center.

Let’s say the following calls come into a call center. They are time-stamped for reference.

Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 1 – (972)828-1847 – 2017-02-13 / 08:01:13

In this case, the call that has been placed on hold the longest is “Call 1”, which came in at 8:01:13. However, recall that in a stack I can only interact with the item on the TOP of the stack. In this case, that is “Call 5”.

So, we are going to create a system that “flips” this stack over, pulls the new top item off and then returns to stack to its original order so additional calls can go in the place they should.

So, assuming that we have a stack already created for the numbers, we will need to create an empty temporary stack to hold the items. As we move the items over, the temporary stack will look like the following:

Call 1 – (972)828-1847 – 2017-02-13 / 08:01:13
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57

As you can now see, “Call 1” is at the top of the stack and could be routed to the next available individual. However, if another new call were to come in, the stack would look like the following:

Call 6 – (512)231-1933 – 2017-02-13 / 08:03:19
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57

To avoid our call queue getting mixed-up, immediately following the retrieval of the top item on the stack, we need to move the items from the temporary stack back to the original stack as follows:

Call 5 – (469)382-1285 – 2017-02-13 / 08:02:57
Call 4 – (682)552-3948 – 2017-02-13 / 08:02:45
Call 3 – (214)233-0495 – 2017-02-13 / 08:01:55
Call 2 – (817)927-3849 – 2017-02-13 / 08:01:22

Now, when “Call 6” comes in, it will go where it is supposed to go (following “Call 5”).

Let’s analyze the code for this problem.

//Program Name: Flipped Stacks
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017
import java.util.*;
public class flippedstacks {
    public static void main(String args[]){
        int count, myStackSize, myTempStackSize;
        Stack myStack = new Stack();
        for (count = 1; count <=10; count++){
            myStack.push(count);
        }
        myStackSize = myStack.size();
        Stack myTempStack = new Stack();
        for (count = 1; count <=myStackSize; count++){
            myTempStack.push(myStack.pop());
        }
        System.out.println("Current Caller is " + myTempStack.pop());
        myTempStackSize = myTempStack.size();
        for (count = 1; count <=myTempStackSize; count++){
            myStack.push(myTempStack.pop());
        }
    }
}

Lines 1 – 4 are the general header information. Lines 5 – 7 are the imports and creation of the class and main object.

Line 8 creates 3 uninitialized integer variables: count, myStackSize, and myTempStackSize.

Line 9 creates a new empty stack named “myStack”.

Lines 10 – 12 push content into the “myStack” stack. It pushes numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, & 10 into the stack.

Line 13 initializes the value of the myStackSize variable as the size of “myStack” using the size function of stacks.

Line 14 is like line 9, but it creates an empty stack named “myTempStack”. This will be the stack that temporarily holds our stack of information so we can get the first record.

Lines 15 – 17 push the content into the “myTempStack” stack by popping each record in the “myStack” stack. The for loop know how many times to do this by using the myStackSize variable that was declared on line 8 and initialized on line 13.

Line 18 displays which caller is the current caller by popping it from the top of the “myTempStack” stack.

Line 19 is like line 13 in that it initializes the value of the myTempStackSize variable as the size of “myTempStack” using the size function of stacks.

Line 19 is also the beginning of the process of reverting the stack back to its original order with the first (oldest) entry removed.

Lines 20 – 22 are similar to lines 15 – 17 but the reverse process. They push content into the “myStack” stack by popping each record in the “myTempStack” stack. The for loop knows how many times to do this by using the myTempStackSize variable that was declared on line 8 and initialized on line 19.

Line 24 & 25 close out lines 7 & 6 respectively.

Arrays with Keyboard Interactivity

Today, we discussed how to create an array with keyboard interactivity. The user will be asked to enter how many numbers they will be entering and then they will be asked to enter numbers separated by a space.

//Program Name: Arrays with Keyboard Input
//Programmer Name: Eric Evans, M.Ed.
//Programmer Organization: Ferris High School
//Program Date: Spring 2017

import java.util.*;
import java.lang.*;
import java.io.*;

public class arrayKeys {
  public static void main(String args[]){
    Scanner count = new Scanner(System.in);
    System.out.print("How Many Numbers Do You Want to Enter?: ");
    int arraySize = count.nextInt();
    int myArray[] = new int[arraySize];
    Scanner nums = new Scanner(System.in);
    System.out.println("Enter Your " + arraySize + " numbers each separated by a space and press enter when done.");
    for(int counter = 0; counter < arraySize; counter++){
      myArray[counter] = nums.nextInt();
    }
  System.out.println(Arrays.toString(myArray));
  }
}

Following the header information (lines 1 through 4) and the imports (lines 6 through 8), we get to the actual application code.

On line 12, we declare a scanner object named “count” which will receive input from the keyboard.

On line 13, we ask the user to enter the number of items they will be entering. Lines 14 assigns the value that is entered as an integer variable named “arraySize”.

Line 15 creates an empty array named “myArray” which is initialized as the size of the “arraySize” variable declared on line 14.

Line 16 declares a second scanner object named “nums” which will receive the integers to the recorded from the keyboard.

On line 17, we ask the user to enter the integers they want recorded separated by a space.

Line 18 opens a for loop. The loop initialization creates an integer variable named “counter” with the value of 0. The loop condition is to run while the variable “counter” is less than the variable “arraySize”, which was declared on line 14. Each pass through the loop increments the value of the variable “counter” by 1.

Each pass through the loop executes line 19, which assigns the next integer in the sequence of numbers from the “nums” scanner to “myArray” in the index (position) declared by the “counter” variable.

Finally, on line 21, we output the contents of “myArray” as a string.

Coding Bat – rotateLeft3

This exercise requires that the program look at an array with 3 integers and shift their positions one index to the left (down) and place first integer (index 0) at the end.

Here is the code that you start with:

public int[] rotateLeft3(int[] nums) {

}

As you can see, we start with an empty integer array named “nums”.

public int[] rotateLeft3(int[] nums) {
  int[] rotatedArray = new int[]{nums[1],nums[2],nums[0]};
  return rotatedArray;
}

 

This solution creates a new integer array named “rotatedArray” and assigns it the values of each index from the original array. (Line 2)

We return the new array on line 3 to solve the problem.