Sunday, June 16, 2013

AP Computer Science: The Summer After

AP Computer Science: The Summer After

AP Computer Science: The Summer After

Introduction

It is now almost summer (2013) and for those of you who have completed the AP Computer Science course you may be wondering: How do you maintain (and/or improve) your computer skills? At least this was the question from one student I know in a similar situation and I thought it was a good question to address.

Program For Yourself

The first thing you must do is program for yourself. The Blackjack series of programs from this blog was my attempt to show new students that the subject matter of your programs need not be seemingly useless programs. You should be able to dream up any program that may interest you. If your not sure what interests you then I suggest start with some simple things from your math classes. Programming is an excellent way to reinforce your mathematic abilities.

A Summer After Sylabus

Numerical Integration - Trapezoidal Rule

In calculus you learned to differentiate and integrate various functions. You should have learned that some functions (eg. 1/(ln x)) do not have an integral that can be expressed as a formula. That's where the Trapezoidal Rule comes in to play. By just knowing the original function you can estimate the area under its curve (ie. find an estimate of the definite integral) by dividing the area up into tiny trapezoids and summing up their area. The smaller the width of the trapezoids the more accurate the estimate.

  1. Find the definition of the Trapezoidal Rule in your calculus book or Wikipedia
  2. Create a program that implements the trapezoidal rule.
  3. test the program on the function f(x) = x2 and compare trapezoidal answer to the actual integral (1/3)x3.
  4. If you book has an example of a function that does not have a solvable integral test your program on that function and see that it provides the same answers
  5. Investigate the use of System.out.format to make the output line up nicely
  6. Try implementing Simpson's Rule after you have the Trapezoidal rule working

Big Project

You have this nice integrator function working let's get it ready to share with other people. You could package it as a desktop application but these days everyone wants to access things on the web. There are 2 ways to do this but both need a web server to deliver the program.

  • Applet a java program that is downloaded via the web and run by the web browser
  • Servlet a java program that runs in a Web Server and serves web pages to a browser

Servlet first

To create a servlet you are going to need a web server program. For Java servlets there are a couple available I prefer Apache Tomcat just because I learned that first. Some people like Jetty. The servlet program will be written the same way no matter which you choose. The installation of that servlet will vary depending on which one you use.

For this project the following steps should be taken:

  1. Google the Servlet servers and pick one of your liking
  2. Download and install the server (tomcat project page: http://tomcat.apache.org/)
  3. Get it up and running. Under Tomcat if it's running properly then you should be able to see the admin page when you put http://localhost:8080 in your browser.
  4. Both Eclipse and Netbeans IDE will set up a Servlet project. Google a HelloWorld example under each and get it to compile in your IDE.
  5. Figure out how to get the project to create a .war file so the app can be deployed
  6. Look at the Tomcat User documents and find out where to place the .war file
  7. Once the .war file has been placed you should see it appear in the tomcat admin page.
  8. Go to the servlet in your browser at http://localhost:8080/<app-dir-name>
  9. Create a new project for a servlet and adapt your integration code to run as a servlet
  10. Install the project under tomcat and verify that the code comes up properly

Improving the Integration Servlet

  • create another Servlet that will accept the following user input
    • a - the starting point for the definite integral
    • b - the end point
    • step - the step size
  • Make sure to add a submit button the submit button should call the integration servlet and provide the parameters
  • modify your Servlet to look for the parameters from the new input servlet
  • To make this really amazing can you figure out a way to allow the user to input a function and the servlet compiles it into java code and integrates it. I believe this is possible but I have never done it.

Final Big Project for the Summer

I have 2 suggestions for a final project for the summer.

  • Learn a new language
    • The key to being a good Software Developer is to learn new computer languages quickly. The best way to learn quickly is to dive in and just start learning a new progrmamming language. Then repeat the process, add another and another language to your repertoire. Each successive language learned will be assimilated faster.
    • LISP/Scheme
    • PERL
    • Ruby
    • C/C++
    • J
    • Javascript
    • Prolog
  • Find the Harvard CS50 lecture videos and watch them. The course goes over C, Javascript, and some other languages while teaching introductory principles of Computer Science

Conclusion

That's it! No code at this point. It's time for those that have taken AP Computer Science to start learning to read online documentation and getting things up and running. If you have any problems you should be able to post a comment to the blog I would be glad to give some pointers.

What I will do in the next article will be to create an interface for the function class. Then use that interface to create an Applet that integrates the function. The Applet should then be a specification for how the Servlet project should work from a functional perspective.

Author: Nasty Old Dog

Validate XHTML 1.0