Skip to content

Commit

Permalink
small bug fixes; Unit 7 timing added and all timing finished
Browse files Browse the repository at this point in the history
  • Loading branch information
bhoffman0 committed Aug 22, 2020
1 parent b9834c5 commit f558051
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 92 deletions.
5 changes: 3 additions & 2 deletions _sources/Unit1-Getting-Started/topic-1-3-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,16 @@ When you are printing out variables, you can use the **string concatenation** op
:click-incorrect:}:endclick:
The equal sign here ``=`` doesn't mean the same as it does in a mathematical equation where it implies that the two sides are equal. Here it means set the value in the memory location (box) associated with the name on the left to a *copy* of the value on the right. The first line above sets the value in the box called score to 4. Also note that the variable has to be on the left side of the ``=`` and the value on the right. Switching the two is called **assignment dyslexia**.
The equal sign here ``=`` doesn't mean the same as it does in a mathematical equation where it implies that the two sides are equal. Here it means set the value in the memory location associated with the variable name on the left to a *copy* of the value on the right. The first line above sets the value in the box called score to 4. A variable always has to be on the left side of the ``=`` and a value or expression on the right.


|CodingEx| **Coding Exercise:**

.. activecode:: lcdv3
:language: java
:autograde: unittest

This is an example of *assignment dyslexia*, when the coder has put the value on the left and the declaration on the right side. Try to fix the following code to compile and run.
This assignment statement below is in the wrong order. Try to fix it to compile and run.
~~~~
public class Test3
{
Expand Down
6 changes: 3 additions & 3 deletions _sources/Unit1-Getting-Started/topic-1-4-assignment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Java uses the operator **==** to test if the value on the left is equal to the v

.. note::

When Java sees you doing integer division (or any operation with integers) it assumes you want an integer result so it throws away anything after the decimal point in the answer, essentially rounding down the answer to a whole number. If you need a double answer, you should make at least one of the values in the expression a double like 2.0.
When Java sees you doing integer division (or any operation with integers) it assumes you want an integer result so it throws away anything after the decimal point in the answer. If you need a double answer, you should make at least one of the values in the expression a double like 2.0.


With division, another thing to watch out for is dividing by 0. An attempt to divide an integer by zero will result in an **ArithmeticException** error message. Try it in one of the active code windows above.
Expand Down Expand Up @@ -515,7 +515,7 @@ Summary

- The arithmetic operators consist of +, -, \* , /, and % (modulo for the remainder in division).

- An arithmetic operation that uses two int values will evaluate to an int value. With integer division, any decimal part in the result will be thrown away, essentially rounding down the answer to a whole number.
- An arithmetic operation that uses two int values will evaluate to an int value. With integer division, any decimal part in the result will be thrown away.

- An arithmetic operation that uses at least one double value will evaluate to a double value.

Expand Down Expand Up @@ -547,7 +547,7 @@ The following is a 2019 AP CSA sample question.
:feedback_a: Don't forget that division and multiplication will be done first due to operator precedence.
:feedback_b: Don't forget that division and multiplication will be done first due to operator precedence.
:feedback_c: Yes, this is equivalent to (5 + ((a/b)*c) - 1).
:feedback_d: Don't forget that division and multiplication will be done first due to operator precedence, and that an int/int gives an int result where it is rounded down to the nearest int.
:feedback_d: Don't forget that division and multiplication will be done first due to operator precedence, and that an int/int gives an int truncated result where everything to the right of the decimal point is dropped.
:feedback_e: Don't forget that division and multiplication will be done first due to operator precedence.

Consider the following code segment.
Expand Down
30 changes: 17 additions & 13 deletions _sources/Unit7-ArrayList/topic-7-1-arraylist-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
:width: 35
:align: middle
:alt: groupwork

.. image:: ../../_static/time45.png
:width: 250
:align: right

Intro to ArrayLists
=======================
Expand Down Expand Up @@ -321,19 +325,19 @@ You can add values to an ArrayList by using its **add** method, described in det
{
public static void main(String[] args)
{
ArrayList<String> shoppingList = new ArrayList<String>();
System.out.println("Size: " + shoppingList.size());
shoppingList.add("carrots");
System.out.println(shoppingList);
shoppingList.add("bread");
System.out.println(shoppingList);
shoppingList.add("chocolate");
System.out.println(shoppingList);
System.out.println("Size: " + shoppingList.size());
ArrayList<Integer> quantities = new ArrayList<Integer>();
quantities.add(2);
quantities.add(4);
System.out.println(quantities);
ArrayList<String> shoppingList = new ArrayList<String>();
System.out.println("Size: " + shoppingList.size());
shoppingList.add("carrots");
System.out.println(shoppingList);
shoppingList.add("bread");
System.out.println(shoppingList);
shoppingList.add("chocolate");
System.out.println(shoppingList);
System.out.println("Size: " + shoppingList.size());
ArrayList<Integer> quantities = new ArrayList<Integer>();
quantities.add(2);
quantities.add(4);
System.out.println(quantities);
}
}
====
Expand Down
86 changes: 45 additions & 41 deletions _sources/Unit7-ArrayList/topic-7-2-arraylist-methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
:width: 35
:align: middle
:alt: groupwork

.. image:: ../../_static/time45.png
:width: 250
:align: right

.. raw:: html

Expand All @@ -37,7 +41,7 @@ ArrayList Methods

<a href="https://apcentral.collegeboard.org/pdf/ap-computer-science-a-java-quick-reference-0.pdf?course=ap-computer-science-a" target="_blank">AP CS A Java Quick Reference Sheet</a>

The following are the ``ArrayList`` methods that you need to know for the AP CS A exam. These are included on the |AP CS A Reference Sheet| that you will receive during the exam so you do not need to memorize them. We will look at how these methods work below.
The following are the ``ArrayList`` methods that you need to know for the AP CS A exam. These are included on the |AP CS A Reference Sheet| that you will receive during the exam so you do not need to memorize them. The E in the method headers below stands for the type of the element in the ArrayList; this type E can be any Object type. We will look at how these methods work below.

- **int size()** returns the number of elements in the list

Expand Down Expand Up @@ -96,14 +100,14 @@ You can add values to an ArrayList by using the method ``add(obj)`` which will a
{
public static void main(String[] args)
{
ArrayList<String> nameList = new ArrayList<String>();
nameList.add("Diego");
System.out.println(nameList);
nameList.add("Grace");
System.out.println(nameList);
nameList.add("Diego");
System.out.println(nameList);
System.out.println(nameList.size());
ArrayList<String> nameList = new ArrayList<String>();
nameList.add("Diego");
System.out.println(nameList);
nameList.add("Grace");
System.out.println(nameList);
nameList.add("Diego");
System.out.println(nameList);
System.out.println(nameList.size());
}
}
====
Expand Down Expand Up @@ -165,11 +169,11 @@ You can put any kind of Objects into an ArrayList. Even objects for a class that
// main method for testing
public static void main(String[] args)
{
ArrayList<Student> roster = new ArrayList<Student>();
roster.add(new Student("Skyler", "skyler@sky.com", 123456));
roster.add(new Student("Ayanna", "ayanna@gmail.com", 789012));
ArrayList<Student> roster = new ArrayList<Student>();
roster.add(new Student("Skyler", "skyler@sky.com", 123456));
roster.add(new Student("Ayanna", "ayanna@gmail.com", 789012));

System.out.println(roster);
System.out.println(roster);
}
}

Expand Down Expand Up @@ -512,15 +516,15 @@ Notice that ArrayLists use set/get methods instead of using the square brackets
{
public static void main(String[] args)
{
ArrayList<String> nameList = new ArrayList<String>();
nameList.add("Diego");
nameList.add("Grace");
nameList.add("Deja");
System.out.println(nameList);
System.out.println(nameList.get(0));
System.out.println(nameList.get(1));
nameList.set(1, "John");
System.out.println(nameList);
ArrayList<String> nameList = new ArrayList<String>();
nameList.add("Diego");
nameList.add("Grace");
nameList.add("Deja");
System.out.println(nameList);
System.out.println(nameList.get(0));
System.out.println(nameList.get(1));
nameList.set(1, "John");
System.out.println(nameList);
}
}
====
Expand Down Expand Up @@ -661,30 +665,30 @@ Note that the ArrayList methods add and remove do not have a simple equivalent i
{
public static void main(String[] args)
{
// Rewrite this code to use an ArrayList instead of an array
String[] toDoList = new String[3];
toDoList[0] = "Do homework";
toDoList[1] = "Help make dinner";
toDoList[2] = "Call grandma";

// changing element 1
toDoList[1] = "Order pizza";
// Rewrite this code to use an ArrayList instead of an array
String[] toDoList = new String[3];
toDoList[0] = "Do homework";
toDoList[1] = "Help make dinner";
toDoList[2] = "Call grandma";
// changing element 1
toDoList[1] = "Order pizza";

System.out.println(toDoList.length + " things to do!");
System.out.println("Here's the first thing to do: "
System.out.println(toDoList.length + " things to do!");
System.out.println("Here's the first thing to do: "
+ toDoList[0] );

// remove item 0 and move everything down
// (this can be done in 1 command with ArrayList)
toDoList[0] = toDoList[1];
toDoList[1] = toDoList[2];
toDoList[2] = "";

System.out.println("Here's the next thing to do: "
// remove item 0 and move everything down
// (this can be done in 1 command with ArrayList)
toDoList[0] = toDoList[1];
toDoList[1] = toDoList[2];
toDoList[2] = "";
System.out.println("Here's the next thing to do: "
+ toDoList[0] );

// Why is an ArrayList better than an array for a toDoList?
// Answer:
// Why is an ArrayList better than an array for a toDoList?
// Answer:
}
}
====
Expand Down
26 changes: 15 additions & 11 deletions _sources/Unit7-ArrayList/topic-7-3-arraylist-loops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
:width: 35
:align: middle
:alt: groupwork


.. image:: ../../_static/time90.png
:width: 225
:align: right

Traversing ArrayLists with Loops
================================

Expand Down Expand Up @@ -359,11 +363,11 @@ You can put any kind of Objects into an ArrayList. For example, here is an Array
// main method for testing
public static void main(String[] args)
{
ArrayList<Student> roster = new ArrayList<Student>();
roster.add(new Student("Skyler", "skyler@sky.com", 123456));
roster.add(new Student("Ayanna", "ayanna@gmail.com", 789012));
// Replace this with a for each loop that prints out each student on a separate line
System.out.println(roster);
ArrayList<Student> roster = new ArrayList<Student>();
roster.add(new Student("Skyler", "skyler@sky.com", 123456));
roster.add(new Student("Ayanna", "ayanna@gmail.com", 789012));
// Replace this with a for each loop that prints out each student on a separate line
System.out.println(roster);
}
}

Expand Down Expand Up @@ -542,18 +546,18 @@ In the class WordPairsList below, you will write the constructor which takes the

public WordPairsList(String[] words)
{
// WRITE YOUR CODE HERE
// initialize allPairs to an empty ArrayList of WordPair objects
// WRITE YOUR CODE HERE
// initialize allPairs to an empty ArrayList of WordPair objects

// nested loops through the words array to add each pair to allPairs
// nested loops through the words array to add each pair to allPairs


}

public int numMatches()
{
//Write the code for the second part described below
return 0;
//Write the code for the second part described below
return 0;
}

public String toString() {
Expand Down
4 changes: 4 additions & 0 deletions _sources/Unit7-ArrayList/topic-7-4-arraylist-algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
:align: middle
:alt: groupwork

.. image:: ../../_static/time90.png
:width: 225
:align: right

ArrayList Algorithms
=====================

Expand Down
4 changes: 4 additions & 0 deletions _sources/Unit7-ArrayList/topic-7-5-searching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

<style> td { text-align: left; } </style>

.. image:: ../../_static/time90.png
:width: 225
:align: right

Searching Algorithms
======================

Expand Down
4 changes: 4 additions & 0 deletions _sources/Unit7-ArrayList/topic-7-6-sorting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
:align: middle
:alt: groupwork

.. image:: ../../_static/time45.png
:width: 250
:align: right

Sorting Algorithms
==================

Expand Down
3 changes: 3 additions & 0 deletions _sources/Unit7-ArrayList/topic-7-7-data-ethics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
:align: middle
:alt: groupwork

.. image:: ../../_static/time45.png
:width: 250
:align: right

Ethics of Data Collection and Data Privacy
==========================================
Expand Down
12 changes: 8 additions & 4 deletions _sources/Unit8-2DArray/routeCipherB.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ Click on the buttons to reveal the questions.

Could you solve this problem with a different kind of loop?



Alternate Recursive Solution
-----------------------------

This problem can be very succinctly solved using recursion. If you are unfamiliar with recursion do not worry if the recursive solution does not make immediate sense.
It is not necessary that you understand recursion at this point however, once you have completed unit 10 which covers the basics of recursion, feel free to return to this
question to practice working through the recursive solution.

The Algorithm
-------------------
.. reveal:: routecipherB_recursive
:showtitle: Reveal Recursion Exercises
:hidetitle: Hide Recursion Exercises
Expand Down Expand Up @@ -177,9 +180,10 @@ The Algorithm

What is your tail recursive call?


If you still feel unsure of the recursive solution, it is recommended that you return to the recursion unit to do some more practice as this problem is quite challenging to solve recursively.

.. reveal:: routecipherB_rec??
.. reveal:: routecipherB_rec??
:showtitle: Reveal Recursion Solution Exercise
:hidetitle: Hide Recursion Solution Exercise

Expand Down Expand Up @@ -259,7 +263,7 @@ If you still feel unsure of the recursive solution, it is recommended that you r

Below is a mixed up version of the correct solution hinted at by the previous questions.

.. reveal:: routecipherB_pars_sol
.. reveal:: routecipherB_pars_sol
:showtitle: Reveal Possible Solution Exercise
:hidetitle: Hide Possible Solution Problem

Expand Down
4 changes: 4 additions & 0 deletions _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
:align: middle
:alt: groupwork

.. image:: ../../_static/time45.png
:width: 250
:align: right

2D Arrays (Day 1)
-----------------

Expand Down
9 changes: 5 additions & 4 deletions _sources/Unit8-2DArray/topic-8-1-2D-arrays-Day2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
:align: middle
:alt: groupwork



.. image:: ../../_static/time45.png
:width: 250
:align: right

Set Value(s) in a 2D Array (Day 2)
----------------------------------------
Expand All @@ -43,13 +44,13 @@ When arrays are created their contents are automatically initialized to 0 for nu

|CodingEx| **Coding Exercise**

Try the code below. Did it print what you expected? When you print a two dimensional array you just get the reference to the object. In the next lesson, we'll learn how to use nested loops to print out the whole 2D Array. Right now, use the |Java visualizer| with the Code Lens button to see what the values are after this code runs. Edit the code to add in an extra row to the seatingChart and add your name and a friend's name in the columns of this extra row using assignment statements.
Try the code below. Did it print what you expected? When you print a two dimensional array you just get the reference to the object. In the next lesson, we'll learn how to use nested loops to print out the whole 2D Array. Right now, use the |Java visualizer| to see what the values are after this code runs. Edit the code to add in an extra row to the seatingChart and add your name and a friend's name in the columns of this extra row using assignment statements.

.. activecode:: 2DArraySet
:language: java
:autograde: unittest

Add another row of data to the arrays by changing the size of the arrays and adding in the assignment statements for the cells in those rows. Use the CodeLens button to see the contents of the array.
Add another row of data to the arrays by changing the size of the arrays and adding in the assignment statements for the cells in those rows.
~~~~
public class TwoDArraySet
{
Expand Down
Loading

0 comments on commit f558051

Please sign in to comment.