AP CS Assignments
Assignments by week:
Fall Term: 1 2 3
Winter Term:
Spring Term:
Monday, September 17
Description
Scanners and Formatters
Homework
  • Read all of chapter 4 (pages 49-63) in Think Java.
  • Download the ScannerCalc.java starter file and the sample solution. The program reads lines of input containing simple numeric expressions (like "4 + 3") and calculates the result. You must use a Scanner to parse the input, and printf() to display the results. The program only needs to understand 2 operands and one operator (longer chains of input are errors). To run the solution, open the Terminal and type "java -jar " and then drag the solution JAR into your Terminal window. There should be a space between the "-jar" and the filename. Due Thursday at the beginning of class.
  • Reminder, to zip up your project, execute a command like the following:

    (cd /path/to/project/folder && zip -r ~/Desktop/name_of_zip .)
Wednesday, September 19
Description
Discourse on the Method
Homework
  • Read the Java tutorial lesson on Exceptions. We'll cover this in our next class, but you may find certain items helpful on your ScannerCalc lab!
  • Finish ScannerCalc lab, due at the start of next class. It should be beautifully commented with your name and ready to turn in. I'll go over how to submit it at the start of class.
Thursday, September 20
Description
Exceptions
Homework
  • Read the all of chapter 5 (pages 67-78) in Think Java. Most of this should be review, but pay attention to the sections on recursion.
  • Write a class that contains the following method:

    public static void recursive(int i) { System.out.println("Iteration " + i); recursive(i+1); }

    Describe (in general terms) the output of the program. Why does this result?

Friday, September 21
Description
Homework
  • Write a recursive method String reverse(String s) that returns the reverse of the given String (you may assume it is non-null). Extra credit: modify your code to require at most n/2 recursive calls for a string of length n.
  • Write a recursive method int pow(int b, int e) that takes a given base b and raises it to the power e (you may assume both are non-negative). How efficient is your solution? Can you make it more efficient?