2010-2011 ICS3U SOFTWARE ENGINEERING TASKS

TASK 'CHALLENGE' RATING (offered to assist you with project management strategies)
Routine
Typically some deep thinking required, but not necessarily a lot of coding.
Hard
Likely involves either a multiplicity of new concepts and/or new mathematical concepts or algorithms.
Really Hard
Start immediately, think hard, employ a stepwise refinement strategy and post concerns as required.

The Game of Life. John Conway introduced the world to one of the most studied algorithms within the Cellular Automata family in the October 1970 issue of Scientific American. Read Wikipedia's explanation of the simple rules for propagation. In the applet to the right, I've colour-coded the cells as Birth, Survival and Death. Explore the game through either or both of the Explore links on the course page. Give yourself time to enjoy how such an elegantly simple set of rules can produce such fascinating outcomes.

Task.

  1. Read over the author's description of his version of the project on pp. 332-334.
  2. Add a third column to your Fractal Framework applet entitled Life.
  3. Design and implement a Drawable class called Life, modeled after this UML diagram (just kidding).
  4. Add a menu item under the Life menu that launches a random configuration of cells and propagates generations indefinitely. Glider Guns, Puffer Trains, and Tire Tracks are my favorites.


Insertion Sort. In a process similar to our development of an animated presentation of the Selection Sort, work out an implementation for the Insertion Sort. Update your website wth the Framework applet that includes the two search algorithms (Sequential and Binary) as well as the two sort algorithms (Selection and Insertion).

 

 

 

 

 

 

 


Selection Sort. Together, we will integrate an animated presentation of the Selection Sort into our Framework Applet. As with the searching algorithms, our Sort classes will implement the Drawable interface. Examine the animated gif (below right) assembled from saved frames. I'll show you the technique for saving bufferedImage objects to disk into either .gif. jpg, or .bmp formats.

Framework UML v2.0 Animated Selection Sort

Task.

  1. To your Framework project and a new menu entitled, Sorts, and add the two menu items, Selection Sort and Insertion Sort
  2. Add two new Drawable classes, SelectionSort and InsertionSort whose constructor accepts only the resolution (similar to your searching classes).
  3. Within Framework's actionPerformed(ActionEvent ev) method, accommodate menu selections for these two activities.
  4. Provide an implementation of the Selection Sort as described in our text on pp. 628-636.

Binary Search Animation. With the Sequential Search animation in place, you are to asked to adapt your animation skills to an implementation of the binary search algorithm depicting a similar rendering.

Task.

  1. To your Framework project, provide an implementation of the Binary Search algorithm.
  2. Add an explanation in your own words of the binary search algorithm to your Framework web page.

 

 

 

 

 


Project Framework. Anywhere, anytime access to your coding achievements will be useful to you. Therefore, the remaining projects for this year will be embedded within your Project Framework applet and mounted on your home page.

Task.

  1. Create project called Framework and drop in this driver.
  2. Edit your name into the two places that require it.
  3. Create web page to house the applet (HTML <applet> tag)and mount it on your Web Publishing site. Here's a sample.

 

 

 

 

 


BINGO! This three-part assignment is designed to solidify your array and Arraylist<E> skills. Students can submit either Bingo Card as defined below or Exercise P7.8, AlternatingSeries. In the case of the latter, a 30% discount will be applied to the earned mark.

PART 1: Bingo Card. Create a project called Bingo1 and add this driver. As you can see, the driver simply instantiates and displays an instance of a BingoCard class. Provide an implementation of the BingoCard class that follows this basic UML design. You output should look similar to the capture below.

 

PART 2: Bingo Player. In this stage you will simulate a single-player Bingo Game. A player has a name and can have as many cards as he chooses. The driver loads the 75 possible calls (B1 to O75) into an array and then randomizes the array. The driver loops through the calls and the player marks an X on each card that matches the call. Before returning for the next call, the driver calls the player's isWinner() method that, in turn, calls each of his/her card's isWinner() method to determine whether any of the player's cards is a winner (12 ways per card). If there is a winner, play stops and the total number of calls is displayed, together with the state of EACH of the player's cards for visual verification.

Task. Create a new project entitled, Bingo2 and drop in this driver. Configure the project's Build Path by adding the Project Bingo1. In this way, you will only have one BingoCard class on your computer. Create a BingoPlayer class that matches this UML diagram to the letter! Sample output appears to the right.

PART 3. Bingo Game. The final stage of the Bingo trilogy should be obvious. You are to simulate a multi-player Bingo Game. In the past few lessons you have been introduced to Java's ArrayList<E> class that offers users a suite of methods for the convenient manipulation of arrays. So, just as the Integer and Double classes are wrapper classes for ints and doubles respectively, the ArrayList<E> class can be thought of as a wrapper for arrays.

Task. Create a project called Bingo3. Add the Bingo2 and Bingo1 Projects to Bingo3's Build Path. Add the text file Players1011.txt to the Project's root. Examine the contents of the file. The data file has a number of records that contain two fields each (the player's name and number of cards), separated by a tab. Using much of Bingo2's driver code, create the driver for Bingo3 that uses the data from Players1011.txt to house the list of players. Then, undertake a Bingo game in which all players are involved until a winner is identified. For verification, print out only the winning player(s) and all of his cards. Note, I will use a different Players1011.txt file (with the same field structure) when I evaluate your project.


The Sieve of Eratosthenes. There is no known efficient procedure for finding prime numbers. A classical, but tedious, method attributed to Eratosthenes (276 - 196 BC), can be described as follows. First, write down a list of integers, paired with true values,

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
T T T T T T T T  T  T  T  T  T  T  T  T  T  T  T

Then mark all multiples of 2 by switching its true to false,

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

T T F T F T F T F T F T F T F T T T F

Move to the next unmarked number, which in this case is 3, then mark all its multiples:

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
T T F T F T F F  F  T  F  T  F  F  F  T  F  T  F 

Continue in this fashion, marking all multiples of the next unmarked number until there are no new unmarked numbers. The numbers which survive this marking process (the Sieve of Eratosthenses) are primes.

Task. Write the class, Sieve, that will implement the Sieve of Eratosthenes and determine the prime numbers from 2 to n-1, where the integer n is determined by the user. 

Your program will create an array of length n, initializing all cells to true. Starting with array index 2, (ignore index 0 and index 1), every time an array element is found to be true, loop through the remainder of the array and set to false every element whose index is a multiple of the starting index.

At the end of the implementation, array elements that remain true have an index which is a prime number. Display the prime numbers to the console.


We'll try something new this week. Students can submit either Trigonometric Functions as defined below or Exercise P6.1, CurrencyConverter. In the case of the latter, a 30% discount will be applied to the earned mark.

Trigonometric Functions. The Math class offers a wide variety of mathematical tools for use by clients. (the trigonometric functions are members of a class of functions known as transcendentals in that the exact value can't be computed precisely, but rather is approximated, typically through the addition of successive terms in a well-defined series)

Degrees (d) to Radians (r). The Math class offers two built-in conversion methods, toDegrees(double angrad) and toRadians(double angdeg) for your convenience that implement the following definitions,

Infinite Series Approximations of the trigonometric functions sin(x) and cos(x), x in R (radians)

Task.

  1. Create a new project called Trigonometry and drop in this driver.
  2. To your NumericalMethods class, add implementations for the following two methods,
    		public static double sin( double angle)

    and

    		public static double cos( double angle)

    based on the two series above that can be used to confirm the accuracy of the built-in methods of the Math class. If your NumericalMethods class works properly, the project will yield the output below (up to 360°).

  3. Enhance the driver by adding two columns for tan(x). The first of the two columns combines the results previously obtained and the second calls the tan function from the Math class.
Submit your enhanced Trigonometry.java driver and NumericalMethods.java classes by the deadline.


Line. Consider Exercise P5.15 on page 224, henceforth known as, LineTest. Review this sample output to guide your development of this project.

Task.

  1. Based on the information provided by the author and our discussions in class, develop the UML diagram for the Line class as Line.uxf. In addition, include a toString() method in the UML. The implementation of this method will enable the driver to display the equation of each Line in the appropropriate form as suggested by the sample output.
  2. Create the project LineTest and add an implementation of the Line class based on your UML design from Step 1. You are encouraged to employ a stepwise refinement strategy whereby the bodies of the intersects, equals, and isParallel methods are not necessarily fully formed, but will compile without errors until they are. Also, don't underestimate the efficiency gains that a private helper method offers in support of the four (slightly) different constructors.
  3. Add the driver class LineTest to the Project. Ease into the development. Start by constructing two or more Line objects for each of the four constructors the Line class offers.
  4. Once a number of Line objects are in place within the LineTest driver, gradually add calls to Line's boolean (predicate) methods to engineer the correct outcomes for each call.
  5. Attach Line.java and Line.uxf to an email with the requested Subject Line to handin by the deadline.

iTunes1. To gain familiarity with boolean operators and expressions, we'll query a database (text file) for data that match specific criteria.

Task.

  1. Create a project entitled iTunes1, a driver by the same name, and add the text file Music1.txt to the root folder of the project. This file (database table) contains over 500 records for which 8 fields are offered (Title, Artist, Composer, Album, Genre, Size, Time & Year). Fields are separated by a tab character.
  2. Read access to a text file can be established as follows (see pp. 498-500 if you're interested),

    Add the above code to the main method of your iTunes1 driver.
  3. Using your Scanner object, read in the first line of text in the file and display it to the Console Window.
  4. Write a conditional loop around a call to your Scanner object's nextLine() method to read in each record of the database and a System.out.print statement to display the each record to the Console Window.
  5. Inside the loop, split each record of the database into an array defined by String fields[] to enable you to identify records that match various criteria.

Now, construct boolean queries to determine the number of matches for each of the stated criteria below. (Note: You many wish to open Music1.txt in Excel to confirm the data sets your queries produce)

  1. Display the number of tracks whose Title field starts with the word, You.
  2. Display the number of tracks whose Title field includes the word You or you in any position.
  3. Display the number of tracks from 1967.
  4. Display the entire record for any track from the 60s. Display the number of tracks at the end.
  5. Display all tracks by the The Beatles not composed by George Harrison or Ringo Starr that are less than two minutes. Display the number of tracks at the end.
  6. Display all Pop or Rock tracks that are over 5 MB. Display the number of tracks at the end.

Table 1. Each Guess
Table 2. Honour
Guess
Result
Number of Guesses
Level
exactly
Bingo!!
1
Jedi
within 1
Hot!
2
L337
within 2
Warm
3
Peasant
otherwise
Cold
otherwise
n00b
Oracle. We examined a strategy that could be used to test for the virtual equality of doubles to avoid problems associated with roundoff error. Although we'll be using ints in this assignment, you'll construct a similar test to evaluate your users' powers of deductive reasoning. Your Oracle object (see UML diagram) will randomly (Random or Math class) generate an integer over the closed interval [0, 9] and keep it secret. In your driver, OracleTest, you will instantiate an Oracle object and subsequently ask the user to submit up to three guesses. Using strategic Oracle method calls within if...else ladders (no loops!) take the user through the guessing game and label him according to Table 2.

Task. You are to give the user no more than three attempts to discover the secret digit. Summarize each game by labeling the player's outcome according to Table 2. In addition to printing the label, also display the secret number for confirmation purposes (not before as in the two examples). Use as many elements of good coding conventions and style that we have discussed and submit OracleTest.java and Oracle.java to handin by the deadline.

 

 


Comparing Objects: Prioritizer. (In class) You are aware that the equality operator (==) is not used to compare the values of two objects. The preferred technique is to add the method, public int compareTo(Object other)to any class that requires a signed integer ranking between the implicit parameter (this) and the explicit parameter (other) instances of the class.

Part A. Comparing Assignment Objects.

  1. Create project called AssignmentTester.
  2. Implement the class Assignment defined by the UML below, right.
  3. Add a driver that instantiates three Assignment objects, assignment1, assignment2, and assignment3.
  4. In a manner similar to the decision tree developed in our DecisionOps project last week, determine and display the 'greatest' Assignment. (Hint: using either the time, worth, or difficulty, develop the body of Assignment's compareTo() method)

Part B. Automated Prioritizer. To automate the prioritization of assignments that require completion, you are to develop software to tell you what your highest priority task is.

  1. Create a project called Prioritizer, drop in the driver Prioritizer.java, and review the code. The WorkLoad class maintains an array of Assignment objects. The Assignment class encapsulates information about an individual assignment that includes its name, completion time, worth, and diamond rating (difficulty).
  2. Implement the code for the WorkLoad and Assignment classes using the UMLs below as a template.
  3. For now, Assignment's compareTo method should return the integer value based on the worth instance field.
  4. Use the String.format() method in Assignment's toString() method to assemble a formatted String similar to the output shown below.


Drow2. In the second instalment of the Drow trilogy you are to demonstrate the ability to read the contents of a user-selected text file and display it in a graphic context.

Task.

  1. Create the project Drow2 and drop in this source code. Test it so that it runs either as an application or as an applet.
  2. Develop the Content class further to enable users to select a text file through the use of a JFileChooser object.
  3. Enhance the class by adding statement's to Content's paintComponent method to display the contents of the text file in its window. For now you can assume that the file does not contain so many lines that it requires horizontal and vertical scroll bars to see it in its entirety (we may address that capability in a later assignment).
  4. Document the code you add and mount the applet version on your website.
  5. Submit Drow2.java to handin by the deadline.

IP Address. (This assignment will give you practice manipulating numerical and String data in the analysis of an Internet Protocol (IP) address) The purpose of this assignment is to allow the user to enter an IPv4 address in dotted-decimal form and the software will convert it to it's binary equivalent (if it is valid). You can restrict the reasons for an invalid address to either an incorrect number of octets (there should be exactly 4) or the value of any given octet is out of range (it must be between 0 and 255, inclusive). Take a test drive of the final project. In addition, you are encouraged to look carefully and the driver's use of JOptionPane's input and output dialog boxes. Use these dialogs where appropriate in the assignments ahead.

Task.

  1. Read Wikipedia's article on the structure of the IP address. We'll restrict ourselves to the IPv4 protocol for this assignment. Click here for your IP address.
  2. Create a project called IPAddressTest and drop in this driver. Review the driver thoroughly for both the javadoc and the handling of the Dialogs. For those that are interested more information on Dialogs can be found here.
  3. Create the class IPv4 that models the UML diagram to the right.
  4. Develop the code necessary to have your project function similarly to the example.
  5. Once completed, mount an executable jar version of your project on your web site.
  6. Finally, submit the fully javadoced IPv4 source file to handin by the deadline.

Newtons' Method for (Square) Root Finding. There is no (easy) direct computation of the square root of a non-negative real number. However, numerous algorithms exist for determining an approximation to it. One useful algorithm, sometimes referred to as Newton's Method, can be described as follows.

Suppose the goal is to determine the square root of 20, call it x. Since 16<20<25, we know the answers lies somewhere between 4 and 5, likely closer to 4. In some situations, we could stop here, offering 4 as the square root of 20. But, like any good competition, a better approximation would be impressive. Try this. If we let x=4, Newton suggested,

would result in an improved approximation. A quick calculation yields a result of 4.5. Squaring 4.5 produces 20.25. Not bad. Newton's prediction appears to be correct. Ok, from 4 we calculated 4.5. Is this the end of it? Is this the best approximation we can come up with?

Task. Create a project called NewtonTest and drop in this driver. Next, create a static NumericalMethods class and implement (at least) the following two methods,

/**
* sqrt returns an approximation to the square root of the number a,
* given an initial guess of x, using n iterations of Newton's Method
* @param a the radicand
* @param x the initial approximation to the square root of a
* @param n the number of iterations of Newton's Method
*/
public static double sqrt(double a, double x, int n)

and

/**
* sqrt returns THE BEST approximation to the square root of the number a,
* given an initial guess of x, using Newton's Method
* @param a the radicand
* @param x the initial approximation to the square root of a
*/
public static double sqrt(double a, double x)

Your code should yield the output below. Submit your NumericalMethods class by the deadline.


Drow. (This is the first of a 3-part assignment) Read Exercise P3.8 on page 127. Review the How To 3.1 Implementing a Class Section on pp.99-101. Recall Stepwise Refinement from last year.

Task.

  1. Create a project called Drow and add a minimal driver class by the same name.
  2. From the description of the Exercise, identify the methods and instance fields that are required.
  3. Using your UMLet utility, design the public and private resources of the Letter class and save it as Letter.uxf to your ICS3U folder. Also, save your UML diagram as a gif image and import it into your images folder in F/C Web Publishing.
  4. Add the Letter class to your Drow project and document the public interface defined in your UML diagram. In addition to the text-based class javadoc of Letter, provide a link to your Letter.gif image in F/C.
  5. Implement the constructor(s) and methods of the Letter class.
  6. Add statements to your Drow driver class to test your Letter class. Document your Drow class.

Toyota Logo Revisited. In preparation for next week's larger graphics application, you are asked to make a few improvements to your previous Toyota application.

Positioning and Proportion Improvements.

  1. Ellipses. When the window is resized, your logo should adjust accordingly, maintaining its proportionality and its centered position with the frame. Recalling that every JComponent's paintComponent(Graphics g) method is called by the Java Virtual Machine (JVM) when itis ready to have the panel updated, you must include code to obtain the new dimensions of the panel every time. JComponent's getSize() method returns a Dimension object that can be mined for the active width and height of the drawing area, as in,
    Dimension dim = getSize();
    
    Determining the coordinates of the center of the panel is simply a matter of averaging the two measures, while accounting for the height of the title bar. With the center known, constructing the rectangular bounding areas of the three ellipses is straightforward. The only concern you have is allowing enough room at the bottom for the TOYOTA name.
  2. Text. Again, when the window is resized, the TOYOTA text must be dead center underneath the ellipses. In your previous attempt, most students simply used trial and error to guess what the position of the text should be. As you will see, once you have the ellipses dynamically repositioning and resizing themselves, a static position and font size for the text is inadequate. The good news is that every chunk of graphics text has a bounding rectangle. The key, then, to properly positioning graphics text is not unlike manipulating any rectangle.

    The FontMetrics class of java.awt encapsulates information about the measure (metric) of a given font. Coincidentally, the Graphics2D class has method called getFontMetrics() that returns a FontMetric object that can be manipulated to reveal the bounds of a given String object within the current graphics environment in the form of a Rectangle2D object.

Task. By the deadline, remount your (improved) Toyota.jar application on your website and submit your source code to handin.

Toyota Logo. For your first Java2D graphics assignment you are asked to recreate the familiar logo. Create a graphical application called Toyota that renders the logo to the right as closely as you can. Some of the areas you will need to investigate include,

Note. An important consideration is the scalability of your rendering. As can be seen from this example, as the frame is resized, the image remains proportional, centered horizontally and scaled to ensure it remains entirely within the panel.


Mod of Exercise P2.4. Create a project called, ExP2_4 and complete the exercise as specified. In addition, compute and display the area of the union of the two original rectangles (Hint. if the two rectangles overlap, the total area is less than the sum of the two). Here's a graphic interpretation of the exercise.

Exercise P2.3. Create a project called, ExP2_3 and complete the exercise as specified at the bottom pf Page 75 with the additional requirement that the four parameters required by the Rectangle constructor of the original rectangle are randomly generated over the following intervals: the coordinates of the top left corner are between 10 and 50 inclusive, and the width and height are between 20 and 100, inclusive.

Finally, for the motivated, a range of bonus points will be awarded for those submissions that render the rectangles graphically. A straightfoward discussion of Graphical Applications and Frame Windows can be found on pp. 58-63.


Project Euler: Register. You are asked to create an account with Project Euler and send me an email to handin that contains your Username and Password (I will use this information over the course of the year to monitor your progress). Optional: Try to complete one problem (any problem) by Saturday deadline.