CMPT 126 - Harbour Centre - Fall 2006
Home  
Assigned Readings  
Examples  
Labs  
Assignments  
References  
Gradebook  
 
  On this lab (and all future work in this course), the name of the files you submit and the name of the classes they contain must match. That is, the file Foo.java must contain (only) the class Foo.

  1. Create a Java class named Circle (in a file Circle.java) that calculates the area of a circle for the user. Here are two examples of what the program should look like when you run it:

    Enter the radius of the circle: 10
    The area of the circle is 314.16.
    Enter the radius of the circle: 39.43
    The area of the circle is 4884.32374584.
    Enter the radius of the circle: -10
    Sorry, I can't do a negative radius.

    Use the formula 3.1416r2 to calculate the area.

  2. We want to write a program that counts for the user. It should ask them where to start, end, and what it should count by:

    Start at: 3
    End at: 10
    Count by: 2
    3 5 7 9

    Start at: 100
    End at: 120
    Count by: 5
    100 105 110 115 120

    1. Create a class Count1, and write this program using a for loop.
    2. Create a class Count2, and write this program using a while loop.
  3. Create a class AlphaChars that contains these functions:
    • isAlpha, that takes a single character as its argument, and returns true if the character is a letter (a-z or A-Z), or false otherwise. The function declaration should be:
      public static boolean isAlpha(char c) {...}
    • isAllAlpha, that takes a string as its argument, and returns true if all of the the characters in the string are letters (a-z or A-Z), or false otherwise. The function declaration should be:
      public static boolean isAllAlpha(String s) {...}

    The class should contain no main function; you'll have to create another class to test it.

  4. Create a text file named time.txt. In it, indicate how long it took you to complete this lab exercise.

When you're done, create a ZIP file containing all of the files you created for this lab into a single file for submission. Submit your work using the submission server.