1. (Posted 8/27) Compile and run HelloWorld.java (and do assigned CodeLab exercises: 20501, 20502, 20515, 20503, 20504, 20505, 20506)
  2. (Posted 8/29, due by 9/12) Hand in when complete. For the final version of each program, hand in 1) your source code (the .java file) with comments that include your name and purpose of program, and 2) the output.
  3. 9/5: Design and implement a class named Computation that declares 3 integer variables, assigns values to them, then computes and prints the sum and average. (You need not hand in this program yet, as we will be modifying it in upcoming labs; you may just raise your hand when complete to show me your source code with documentation and output.)

  4. 9/10: Compile and run TempConverter.java. Is it correct? If not, identify the error, what kind of error it is, and fix it. Test your program by checking manually that you got the right answer, e.g. if the temperature in celsius is 0, the equivalent temperature in fahrenheit is 32; if the temperature in celsius is 5, the equivalent temperature in fahrenheit is 41. Finally, make the program more readable by replacing literals with constants, e.g.: fahrenheitTemp = celsiusTemp * CONVERSION_FACTOR + BASE;
  5. 9/10: Modify your solution to the previous exercise so that the temperature in celsius is read from the user. Test your program by entering inputs for which you know what the answer should be. You may refer to LbsToKgs, a program which converts from pounds to kilograms.

  6. 9/12: Modify your Computation program so that it reads the 3 integer values from the keyboard. It should still compute the sum and average, and print these. Label the output, and document your source code. You may refer to the examples such as: LbsToKgs and GasMileage.java.
  7. 9/12: Design and implement a class named ChangeCounter that reads from the user the number of quarters, dimes, nickels and pennies, then computes and prints the value of the money. Document first, in English, the steps of your algorithm! Use constants where appropriate, and follow the style guidelines we discussed.

  8. 9/17: We learned that the NASA Mars Climate Orbiter and Polar Lander project failed (costing over 300 million dollars) because the software that guided the navigation of the spacecraft used imperial units of measure (pound-force), while the spacecraft itself expected the data in metric units (newtons). NASA hires you to correct the problem. Design and implement a class named ForceConverter that converts pound-force (read from the user) to newtons. There are 4.44822162 newtons per pound-force. Use stepwise refinement. Document first, in English, the steps of your algorithm! Use CONSTANTS where appropriate, and follow the style guidelines we discussed. Refer to the LbsToKg program we discussed in class (also on the examples link).

  9. 9/24: Practice using the debugger: set a breakpoint at the first statement of a program, then run the program, click "Step" one statement at a time as you watch any variables and the output, until the program terminates. You may choose any program to step through such as your own or one I gave.
  10. 9/24: Design and implement a program that draws a picture of your choice, using shapes such as lines, rectangles, circles and ellipses. Draw it first on graph paper; raise your hand if you would like extra graph paper. Refer to Chapter 3 example Snowman.java. Hand in when complete (documented source code and output).

  11. 9/26: Using the String class:

  12. 9/26: Formatting output

  13. 10/1: Read the code, documentation and output of Chapter 3 example RandomNumbers.java which uses the Random class (online documentation). Write a Java program that simulates the rolling of a pair of dice. For each die in the pair, the program should generate a random number between 1 and 6 (inclusive). It should print out the result of the roll for each die and the total roll (the sum of the two dice), all appropriately labeled.

  14. 10/1: This exercise builds upon your application that prompts for and reads the user's first and last names as "First Last". You may assume that the last name has at least 5 letters. Create and print a String variable userName, composed of the first letter of the user's first name, followed by the first five characters of the user's last name, followed by a random number in the range 10 to 99. Similar algorithms are sometimes used to generate usernames for new computer accounts. (For examples of programs that work with Strings and random numbers (respectively), you may refer to Chapter 3 examples StringMutation.java and RandomNumbers.java .)

  15. 10/1 (time permitting): Read the current time from the user, as a String (e.g. "2:30"). Also ask the user to enter a number of minutes to advance the clock. You may assume that the user enters valid data. For example, if the current time is 2:30 and the user enters 15 when asked how many minutes to advance the clock, the program should compute and print the new time, which in this case is 2:45 (i.e. 15 minutes after 2:30). If the user entered 60, then the new time would have been 3:30 (i.e. 60 minutes after 2:30). Assume a 24 hour format (0:0 through 23:59) and don't worry about AM vs. PM; also, it's ok (for now) to print the time as 10:5 if the time is 10:05. Note: in order to convert a String (representing a number, like "12") to an int (for the purpose of doing arithmetic), there is a predefined method parseInt (in predefined class Integer) that takes one parameter of type String and returns the corresponding integer - see the online Java API documentation, e.g. Integer.parseInt("12") evaluates to the primitive integer 12; in this example, "12" can be substituted by a variable storing the String that you want to treat as an int.

  16. 10/3: Write a program that inputs from the user an angle (measured in degrees) then computes and prints:
    (the trigonometric sine of the angle in radians) squared + (the trigonometric cosine of the angle in radians) squared.

    Test your program on different degrees; if your program is working correctly, the result should be 1 each time (pythagorean trigonometric identity). Refer to the Java API for the Math class, i.e. Math methods sin, cos, pow, toRadians, round. If there is a logical error (i.e. the result is not correct), use the debugger to step through your program; it will be easier if you decompose the problem into subproblems rather than computing the entire formula in one statement.

  17. 10/3: Write a program that reads a name from an input file (in a format you choose e.g. Last, First or First Last) and extracts and prints the first name and last name separately. (See example NameReader.java which reads from a text file names.txt)

  18. 10/10: Defining methods

  19. 10/15: Practice calling and defining methods with the following Codelab exercises. Refer to the syntax diagrams we discussed in lecture today.

  20. 10/15: Program consisting of 2 classes: 1) a class with static methods (also known as class methods) invoked by 2) a driver/main class (i.e. the class with the main method).

    Modify your solution to exercise 18 part a, so that there are 2 classes: 1) PrimitiveFiguresLibrary.java, a class with methods that draw primitive shapes such as a cone and a box, and 2) a class named House, whose main method draws two houses, by calling twice a method drawHouse (defined in the same class), which calls methods drawCone() and drawBox() of PrimtiveFiguresLibrary.

  21. 10/17: Program consisting of 2 classes: 1) a blueprint/data class with non-static methods invoked by 2) a driver/main class (i.e. the class with the main method).

    Working with an object of our own blueprint class (Circle, in this example). Read and understand a solution to quiz problem 6 (CircleStats.java). Redo this program in an object-based way, i.e. using a blueprint or data class (Circle.java) to create a Circle object, and invoke methods on this object to compute the area and circumference. You may solve this by modifying driver class CircleStats1.java and blueprint class Circle.java, by inserting code in the lines indicated by asterisks.

  22. 10/17: Write the program from today (in 2 separate classes/files: StarTrek and Spaceship, where StarTrek is the Driver or main class (with the main method) and Spaceship is the Blueprint or data class), and update it so that it creates an additional instance of Spaceship, e.g. an object klingonShip. You may do this by modifying StarTrek.java which uses Spaceship.java. To do this, you need not modify the Blueprint class Spaceship; you are just invoking the constructor again in the main method of the Driver class StarTrek.

  23. 10/17: Try writing a Blueprint or data class of your own that groups together related information of interest to you (e.g. a Movie has a title, director, lead actor/actress, year, etc. or a BaseballHitter has the following attributes: atBats, hits, runs, homeruns... and methods computeBattingAverage and printStats; the batting average would be computed as hits divided by atBats) and a Driver or main class that uses it (i.e. creates objects and calls methods on these objects).

  24. 10/22: Defining Blueprint classes (user-defined data types), and creating objects (aka object reference variables aka instances of those data classes)

  25. 10/31: Codelab Exercises on Making Decisions and Conditions
  26. 10/31: Read and understand the Chapter 5 examples CoinFlip.java (which demonstrates that a boolean expression can be a call to a method that returns a boolean value, i.e. the isHeads method of the Coin class returns true or false) and Coin.java. Write a class named Game that contains instance data for two team names. Define the Game constructor to accept and initialize this data. Include a method named computeWinner that instantiates a Coin object, "flips" the coin by invoking the flip method of Coin, and returns the winning team name based on the coin flip. Create a driver class named Tournament that simulates the following games: 1) Astros vs. Red Sox, 2) Brewers vs. Dodgers, and 3) winner of Astros - Red Sox vs. winner of Brewers - Dodgers:
    In the main method of driver class Tournament:
    Fill in the missing code, where you see ...
    // Set up games 1 and 2.
    Game game1 = new Game ("Astros", "Red Sox");
    Game game2 = new Game ("Brewers", "Dodgers");
    
    // Determine the winner of game1.
    String winner = game1.computeWinner();
    
    // Determine the winner of game2.
    ...
    
    // Set up the championship game (winner of game1 vs. winner of game2).
    ...
    
    // Determine the winner of the championship game. 
    ...
    
    // Print the winners of each game.
    ...
    
    

  27. 11/5: Modify your Computation program that reads 3 grades from the user and computes the average, so that it also computes the letter grade based on the average (see table below). Store the letter grade in a variable of type char. Print the average and letter grade (AFTER your nested if statement). Note: the range [x,y) means: between x and y, including x, excluding y.
    averageletter grade
    [90,100]A
    [80,90)B
    [70,80)C
    [60,70)D
    [0,60)F

  28. 11/7: Decisions for Finch / Jeroo.

  29. 11/12: Not on quiz, but useful for future programs: the switch statement:

  30. 11/19:

  31. 11/26: Repetition statements

  32. 11/26: Loops for Finch / Jeroo. You may choose the Finch or Jeroo exercise:

  33. 11/26 (time permitting): Modify your program that reads grades from the user (and computes the average and letter grade) so that it uses a sentinel to indicate the end of input; e.g. it asks the user to enter a grade of 0 to 100, or -1 to quit; in this example, the sentinel is -1; keep reading grades until the user enters -1. Use a constant to represent the SENTINEL.

  34. 11/26 (time permitting): Modify your program that reads grades from the user, so that it has a method that checks if a particular input is valid (between 0 and 100, inclusive, or the sentinel value), called within a do-loop, i.e. as long as the user types invalid input, the user should be given another chance to enter input (it would also be good to let the user know that their input is invalid). Moreover, only a valid grade should be used in computing the sum and average. At the appropriate point in your code, put a comment that asserts that the grade entered by the user has been determined to be valid. You may refer to this program that uses methods to read and validate input.

  35. 11/28: Tracing programs containing loops (by drawing tables and showing output; you need not write any code):

  36. Here are practice exercises for HW 5 (posted on the assignments link) and HW 6 (to be posted; implementation of design in HW 5).

  37. 12/4:

  • Optional (not required): Have Finch play Simon Says, with the color sequence stored in an array.