## 2-Dimensional Arrays in Java

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

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.

## Projectile Motion Worksheet #2

My Principles of Technology class is continuing to work on the preparations for the projectile motion project of launching a water balloon at me from 40 yards away.

Today, we analyzed how to calculate the maximum height and maximum range of a projectile.

I first showed them the formulas and we pulled apart the variables:

We then discussed that the mass of the object does NOT appear as any of the variables. We discussed why this is and then watched the following video:

Afterward, we started to work on the problems in the following online worksheet.

Projectile Motion Worksheet

The first 5 questions are short answer and will vary by student. The answers to the last 15 questions are provided at the link below:

Projectile Motion Worksheet Solutions

Up next, we will analyze drag coefficients and the impact of air/wind resistance on the flight path of the balloon.

We’ll then move into designing a launch apparatus that can launch the projectile at the correct angle and velocity.

Finally, we’ll move to testing. Fortunately, for this project, no fires!

## 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.

## Projectile Motion Worksheet #1

In my Principles of Technology class, we are starting to gear-up for a projectile motion project. The students will be working in teams and launching a water balloon at me from exactly 40 yards away.

In the first worksheet in the series, students were given a series of right triangles with sides A and B given. Sometimes the units were the same and other times they would have to convert units.

The students were asked to calculate the length of C in the most appropriate units and then calculate angle X using the trig function (sine, cosine, or tangent) of their choice.

All of my students were able to perform the first calculation using the Pythagorean Theorem. The second calculation, even through it was given step-by-step, was not completed by the majority of the students who are in Algebra I.

The claim was that they had never seen it before. Obviously, I countered with, “Well, you have now.”.

## Getting Hot in Physics

Well, to say that today did not go as expected would be the understatement of the school year!

My Principles of Technology class has been working on building model rockets as part of a unit that was analyzing the physics concepts of impulse, velocity, and acceleration, the chemistry concept of balanced chemical equations/reactions, and the engineering concept of technical drawing/documentation.

Today was the day that we launched. We had 6 small single-stage rockets to launch in addition to 2 small two-stage rockets.

Each single-stage rocket was loaded with a single A-rated motor which would carry it to a total altitude of approximately 250 feet. Each two-stage rocket was loaded with two C-rated motors which would carry it to a total altitude of approximately 1,800 feet!

Before going outside, we verified the weather conditions, which showed winds from the west at 7 MPH with guests to 11 MPH. The humidity was 41% and dropping. We decided to launch from the west side of the property with the idea that the winds would carry the rockets onto the soccer fields which had recently been watered.

Our first launch of the morning performed as expected and came down next to the roadway by the launch site.

Our second launch of the day did not perform as well. The first stage of the rocket fired as designed and carried the rocket to around 900 feet. Unfortunately, the first stage did not properly separate as designed and the rocket began to tumble back to the ground.

After a few seconds, the second stage ignited which sent the rocket flying on the path it was pointing at, which was toward the ground west of our launch location and it ignited the cardboard frame of the first stage which was now in a free-fall into the field to the west of the launch location.

The rocket came down about 100 yards west of the launch pad and the first stage landed about 30 yards to the east of the crash site. Unfortunately, since the first stage was on fire when it landed and it landed in a field of 1 meter tall grass/hay, the field was quickly engulfed in fire.

Ultimately, the crash resulted in the burning of approximately 1 acre of grassland which is fortunately owned by the school.

Because of the quick response of the Ferris Fire Department, the fire was quickly contained and everyone was safe with the only loss being the grassland, the rocket launcher, and the rocket launch stand.

## 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.

## Coding Bat – posNeg

This exercise requires that the program look at two given integers and a boolean. If the Boolean is TRUE AND both integers are negative, then TRUE is returned. If the Boolean is FALSE only 1 integer can be negative for to return TRUE.

Here is the code that you start with:

```public boolean posNeg(int a, int b, boolean negative) {

}```

As you can see, we start with 2 integer variables named “a” and “b” and a boolean named “negative”.

```public boolean posNeg(int a, int b, boolean negative) {
if (negative){
if (a < 0 && b < 0){
return true;
} else {
return false;
}
} else if ((a < 0 && b > 0) || (a > 0 && b < 0)) {
return true;
} else {
return false;
}
}```

This solution utilizes a nested if/then structure. Starting on line 2, we say IF the Boolean negative is TRUE, then proceed to line 3. If it is FALSE, we would jump to line 8.

On line 3, we now check to see if both “a” AND “b” are negative (less than 0). If they are, TRUE is returned (line 4). If they are not, FALSE is returned (lines 5-7).

Line 8 is executed if the Boolean on line 3 is FALSE. Line 8 looks to see if “a” is negative and “b” is positive OR “a” is positive and “b” is negative. If either case is TRUE, then TRUE is returned (line 9). If neither statement on line 8 is TRUE, then FALSE is returned (lines 10-12).

Coding Bat presents the following as their solution:

```public boolean posNeg(int a, int b, boolean negative) {
if (negative) {
return (a < 0 && b < 0);
}
else {
return ((a < 0 && b > 0) || (a > 0 && b < 0));
}
}```

In this solution, line 2 is identical to our line 2. However, their line 3 is shorter version of our lines (3-7). If both “a” AND “b” are not negative, then a FALSE is returned, otherwise a TRUE is returned.

Their lines 5-7 are our lines 8-12 and work the same way.

## Robotic Systems Classifications Exam

We have spent the past 2 weeks covering 5 different classification systems of robotic and automated systems.

We have covered degrees of freedom, drive technology, kinematic structure, motion characteristics, and workspace geometry.

Robotic Classification Systems Notes

At the conclusion of this unit, students were given a review guide and an exam.

Robotics Classifications Exam

Robotics Classifications Exam Key

The results will be posted following the administration of the exam.