Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bhoffman0/CSAwesome
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 6, 2024
2 parents aa07b01 + 8640449 commit abb6f4c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 22 deletions.
16 changes: 8 additions & 8 deletions _sources/Unit10-Recursion/rEasyMC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ These problems are easier than most of those that you will usually see on the AP
:practice: T
:answer_a: 1
:answer_b: 3
:answer_c: 4
:answer_d: 5
:answer_c: 5
:answer_d: 9
:correct: d
:feedback_a: This is the method declaration. Look for a call to the same method in the body of the method.
:feedback_b: This is a conditional, not a method call.
Expand Down Expand Up @@ -41,9 +41,9 @@ These problems are easier than most of those that you will usually see on the AP
:practice: T
:answer_a: 1
:answer_b: 3
:answer_c: 4
:answer_d: 5
:answer_e: 6
:answer_c: 5
:answer_d: 7
:answer_e: 9
:correct: e
:feedback_a: This is the method declaration. Look for a call to the same method in the body of the method.
:feedback_b: This is a conditional, not a method call.
Expand Down Expand Up @@ -75,9 +75,9 @@ These problems are easier than most of those that you will usually see on the AP
:answer_c: 2
:answer_d: 3
:correct: c
:feedback_a: Look at line 7 more closely.
:feedback_a: Look at line 13 more closely.
:feedback_b: Many recursive methods only have one recursive call. But, this one has two.
:feedback_c: Line 7 has two calls to <code>fibonacci</code>.
:feedback_c: Line 13 has two calls to <code>fibonacci</code>.
:feedback_d: There are not 3 calls to <code>fibonacci</code>.

How many recursive calls does the following method contain?
Expand Down Expand Up @@ -109,7 +109,7 @@ These problems are easier than most of those that you will usually see on the AP
:answer_d: 3
:correct: b
:feedback_a: Look for a call to the same method in the body of the method.
:feedback_b: Line 6 has one call to <code>multiplyEvens</code>.
:feedback_b: Line 9 has one call to <code>multiplyEvens</code>.
:feedback_c: Where do you see 2 calls to <code>multiplyEvens</code>?
:feedback_d: Where do you see 3 calls to <code>multiplyEvens</code>?

Expand Down
6 changes: 3 additions & 3 deletions _sources/Unit10-Recursion/topic-10-1-recursion-day1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ Every recursive method must have at least one **base case** which halts the recu
:answer_b: 1
:answer_c: Both 0 and 1
:correct: c
:feedback_a: This method also stops for another value of n.
:feedback_b: This method also stops for another value of n.
:feedback_c: This method stops calling itself when n is either 0 or 1.
:feedback_a: This method also stops for another value of bunnies.
:feedback_b: This method also stops for another value of bunnies.
:feedback_c: This method stops calling itself when bunnies is either 0 or 1.

What is/are the values of the variable bunnies when this method stops calling itself (when it reaches the base case)?

Expand Down
4 changes: 2 additions & 2 deletions _sources/Unit10-Recursion/topic-10-1-recursion-day2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Let's trace the execution of the factorial method defined below.
}
}
What happens when we call ``factorial(0)``? It will return 1 (line 4) since n is equal to 0. How about ``factorial(1)``? It will return ``1 * factorial(0)``. We already know that ``factorial(0)`` returns 1, but the computer won't *remember* that. It will execute ``factorial(0)`` and return the result (1). So ``factorial(1)`` returns ``1 * 1 which is 1``.
What happens when we call ``factorial(0)``? It will return 1 (line 5) since n is equal to 0. How about ``factorial(1)``? It will return ``1 * factorial(0)``. We already know that ``factorial(0)`` returns 1, but the computer won't *remember* that. It will execute ``factorial(0)`` and return the result (1). So ``factorial(1)`` returns ``1 * 1 which is 1``.

How can you show what is happening in a recursive call? Here is one way to do it. The lines below show the call stack upside down (with the bottom of the stack, or the beginning at the top and the most recent call at the bottom) for a call to ``factorial(5)``. This is a handy way to trace a recursive method on the exam and you will do much better on recursive problems if you practice doing it this way.

Expand Down Expand Up @@ -216,7 +216,7 @@ Let's trace the execution of the bunny ears method defined below.
}
}
What happens when we call ``bunnyEars(0)``? It will return 0 since n is equal to 0 (line 3). How about ``bunnyEars(1)``? It will return 2 since n is equal to 1 (line 4). What about ``bunnyEars(5)``?
What happens when we call ``bunnyEars(0)``? It will return 0 since n is equal to 0 (line 3). How about ``bunnyEars(1)``? It will return 2 since n is equal to 1 (line 5). What about ``bunnyEars(5)``?

.. code-block:: java
:linenos:
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit2-Using-Objects/topic-2-6-strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ In both cases an object of the ``String`` class will be created in memory and th
single: java.lang
pair: package; java.lang

The code above will first print ``class java.lang.String`` since ``greeting`` was created by the ``String`` class. The full name for the ``String`` class is ``java.lang.String``. The ``java.lang`` part is the **package** name. Every class in the Java language is in a package and the standard classes like ``String`` are in the ``java.lang`` package. Every object in Java knows the class that created it. Also, every class knows its **parent** class. Yes, a class can have a parent class, just as people have parents. But, in Java a class can only have one parent. A class can ``inherit`` object fields and methods from a parent class, just like you might inherit musical ability from a parent. The fourth line will print ``class java.lang.Object`` because the parent class (**superclass**) of the String class is the Object class. All classes in Java inherit from the Object class at some point in their ancestry.
The code above will first print ``class java.lang.String`` since ``greeting`` was created by the ``String`` class. The full name for the ``String`` class is ``java.lang.String``. The ``java.lang`` part is the **package** name. Every class in the Java language is in a package and the standard classes like ``String`` are in the ``java.lang`` package. Every object in Java knows the class that created it. Also, every class knows its **parent** class. Yes, a class can have a parent class, just as people have parents. But, in Java a class can only have one parent. A class can ``inherit`` object fields and methods from a parent class, just like you might inherit musical ability from a parent. The last print statement will print ``class java.lang.Object`` because the parent class (**superclass**) of the String class is the Object class. All classes in Java inherit from the Object class at some point in their ancestry.

.. figure:: Figures/stringObject.png
:width: 500px
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Review {
}


//read in the positive adjectives in postiveAdjectives.txt
//read in the positive adjectives in positiveAdjectives.txt
try {
Scanner input = new Scanner(new File("positiveAdjectives.txt"));
while(input.hasNextLine()){
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit6-Arrays/topic-6-1-array-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ In this challenge, you will create a guide to different countries using arrays.

boolean passed =
getResults(
"5 x String[]", arrays + " x String[]", "Did you declare 4 String arrays?");
"5 x String[]", arrays + " x String[]", "Did you declare 4 String arrays? (the 5th one is main's arg)");
assertTrue(passed);
}
}
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit9-Inheritance/TrioScore2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Apply the grading rubric shown above as you answer the following questions.
:feedback_a: This solution contains correct declarations for <code>public String getName()</code> and <code>public double getPrice()</code>.
:feedback_b: To implement an interface the class must have a getName and getPrice method as defined by the MenuItem interface.

Should the student earn 1 point for correctly delcaring the methods in the ``MenuItem`` interface (getName and getPrice)?
Should the student earn 1 point for correctly declaring the methods in the ``MenuItem`` interface (getName and getPrice)?

.. mchoice:: qtrio2_6
:answer_a: Yes
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit9-Inheritance/ooCodePractice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ Code Practice with Object Oriented Concepts
:language: java
:autograde: unittest

Override the compareTo method so that it returns a postive number if the current Person is older than the passed other and a negative number if they are younger. If their age is the same then return the compareTo result on the names.
Override the compareTo method so that it returns a positive number if the current Person is older than the passed other and a negative number if they are younger. If their age is the same then return the compareTo result on the names.
~~~~
public class Person implements Comparable<Person>
{
Expand Down
9 changes: 7 additions & 2 deletions _sources/Unit9-Inheritance/topic-9-2-constructors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,17 @@ constructors.
2. Add a ``Square`` constructor with 1 argument for a side that calls ``Rectangle``\ ‘s constructor with 2 arguments using ``super``.
3. Uncomment the objects in the ``main`` method to test drawing the squares.
4. Add an ``area`` method to ``Rectangle`` that computes the area of the rectangle. Does it work for ``Square``\ s too? Test it.
5. Add another subclass called ``LongRectangle`` which inherits from ``Rectangle`` but has the additional condition that the length is always 2 x the width. Write constructors for it and test it out.
5. Add another subclass called ``LongRectangle`` which inherits from ``Rectangle`` but has the additional condition that the length is always 2 x the width. Write constructors for it and test it out. Do not make it public (because only 1 class per file can be public).

.. activecode:: challenge-9-2-Square-Rectangle
:language: java
:autograde: unittest

Create a Square class that inherits from Rectangle.
1. Make the class ``Square`` below inherit from ``Rectangle``.
2. Add a ``Square`` constructor with 1 argument for a side that calls ``Rectangle``\ ‘s constructor with 2 arguments using ``super``.
3. Uncomment the objects in the ``main`` method to test drawing the squares.
4. Add an ``area`` method to ``Rectangle`` that computes the area of the rectangle. Does it work for ``Square``\ s too? Test it.
5. Add another subclass called ``LongRectangle`` which inherits from ``Rectangle`` but has the additional condition that the length is always 2 x the width. Write constructors for it and test it out. Do not make it public (because only 1 class per file can be public).
~~~~
class Rectangle
{
Expand Down Expand Up @@ -335,6 +339,7 @@ constructors.
}

// 5. Define the LongRectangle class here
// Do not make it public because only 1 class with main can be public in 1 file.

====
import static org.junit.Assert.*;
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit9-Inheritance/topic-9-6-polymorphism.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If you were simulating this toy in software you could create an ``Animal`` class

In Java an object variable has both a **declared (compile-time) type** and an **actual (run-time) type**. The *declared (compile-time) type* of a variable is the type that is used in the declaration. The *actual (run-time) type* is the class that actually creates the object using new.

The variable ``nameList`` declared below has a **declared type** of ``List`` and an **actual** or **run-time type** of ``ArrayList``. The complier will check if the declared type has the methods or inherits the methods being used in the code and give an error if it doesn't find the method(s). The List interface does have an ``add`` method so this code will compile. At run-time the execution environment will first look for the ``add`` method in the ``ArrayList`` class since that is the actual or run-time type. If it doesn't find it there it will look in the parent class and keep looking up the inheritance tree until it finds the method. It may go up all the way to the Object class. The method will be found, since otherwise the code would not have compiled.
The variable ``nameList`` declared below has a **declared type** of ``List`` and an **actual** or **run-time type** of ``ArrayList``. The compiler will check if the declared type has the methods or inherits the methods being used in the code and give an error if it doesn't find the method(s). The List interface does have an ``add`` method so this code will compile. At run-time the execution environment will first look for the ``add`` method in the ``ArrayList`` class since that is the actual or run-time type. If it doesn't find it there it will look in the parent class and keep looking up the inheritance tree until it finds the method. It may go up all the way to the Object class. The method will be found, since otherwise the code would not have compiled.

.. code-block:: java
Expand Down
2 changes: 1 addition & 1 deletion _sources/Unit9-Inheritance/topic-9-7-Object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ look at what’s involved.

We'll write a class ``Word`` which represents a word in a particular language.
We want two ``Word`` objects to be considered ``equals`` if and only if they are
spelled the same `and` come from the same languag. The latter requirement is
spelled the same `and` come from the same language. The latter requirement is
because sometimes different languages have words that are spelled the same but
with different meanings such as “pie” which in English is a tasty baked treat
and in Spanish is what we call a “foot” in English.
Expand Down

0 comments on commit abb6f4c

Please sign in to comment.