Chris Pollett>Old Classes>PIC 20, Winter 2000>Hw2

Winter 2000 PIC 20 HW #2

Programs are due in your \submit folder by 5:30p.m. Jan 31

  1. For this problem you write an application named Pattern.java. Besides giving you more practice with control structures the point of this exercise is to learn how to do simple pattern matching using finite state automata. This program analyzes its command line arguments to see if the numbers 7, 7, and 9 appear as three successive arguments and then prints an acknowledging response of your choice (go wild) if they do, and a differing response if they don't. Make it clear to enough which response means what so that the grader can grade your homework. Here are some example input response pairs:
    >java Pattern 7 55 7 9 2
    Sorry, doesn't contain the pattern.
    
    >java Pattern 5 4 -79 8 7 7 7 9 0 3
    Yes, that has the pattern.
    
    >java Pattern 0 7 7 9 0 0 0
    Yes, that has the pattern.
    
    You can assume like above that all arguments will be integers. The grader will test on these as well as two other sets of inputs. You should use a break to get out of your loop once you have accepted an input. You should also use a switch/case structure somewhere in your program. To do this assignment it helps to come up with a finite state diagram (will mention in class) which accepts the above kinds of strings and then implement that in java.
  2. For this problem you will write an applet named Triangles.java and an html file Triangles.php for appletviewer to view it. The point of this exercise is to get you more familiar with arrays, recursive methods, simple use of the Java event model, and to see a simple example of self-similarity ( a fractal). Your goal is to write a program which does the same thing as the applet below.
An applet that generates a Sierpinski gasket.

Homework 2 FAQ.

Solution set.