Activities for CS 120 Lab03

NAME(S):

Working with Applications

You will design and implement a program that prints your initials in large letters and then modify the chapter 2 code for Fabric Conversion.
  1. Create the basic structure of the program, including the class and main method headers. Follow the model of the Useless program. Call the class in the new program Initials. Save the program in a file called Initials.java, preferably in a directory of its own.
  2. Add comments to the top of the program file specifying your name and other pertinent information.
  3. Design the format for your initials, similar to the example below. Make each letter five lines high and 7 characters wide. Use the pound symbol ( # ) to make the letter. Leave two empty spaces between each letter. Sketch your initials below. If you work in pairs, your program should print both sets of initials (on separate "lines").

  4. #######
       #
       #
    #  #
     ##
  5. Add five calls to system.out.println to output (each set of) your initials (so that they read left to right and if there are two sets, the two sets of initials are on separate lines) in the format you designed. Compile and execute the program. Modify it as necessary until the initials are printed properly.
  6. Add println statements above and below your initials, printing various information about you, such as your name, age, and major. Compile and execute the program.
  7. Add comments to the program, above the class header and above the main method header, describing the processing. Compile and execute the program to ensure that these modifications did not affect the program.
  8. Using grade (in a Terminal window issue the command grade cs120 Initials.java) submit the final version of Initials.java (only one copy is needed if you worked together).
  9. Using Netscape, grab a copy of the chapter 2 source files ConvertFabric.java and PieceOfFabric.java and save them in your directory. Try to compile PieceOfFabric.java. If you get errors, we'll need to set your CLASSPATH environmental variable. Ask Ming or Tom for help on this. Then compile and run ConvertFabric.java and see how it behaves. Can you resize the history window so you don't need to use the scrollbar to see the entire answer? Describe how you did this.

  10.  
  11. Modify the fabric files as needed to create a program which prompts the user for their hourly wage and then their average number of hours worked per week. Your program should return (in a nicely formatted manner) the equivalent annual salary. Assume the user works for 50.0 weeks each year. Name your classes ConvertWage.java and HourlyWage.java and submit each one with the grade script.
  12. Working with Applets

  13. Enter the following applet, saving it in a file called Sketch.java:

  14.  
     
    import java.applet.Applet;
    import java.awt.*;
     
    // Testing various drawing routines.
     
    public class Sketch extends Applet {
     
    // Draws some simple figures.
     
        public void paint ( Graphics page ) {
            page.drawString ("Testing some shapes", 30, 30);
     
            page.drawLine (30, 60, 50, 60);
            page.drawLine (30, 70, 60, 70);
     
            page.drawOval (90, 50, 20, 20);
            page.drawOval (120, 50, 40, 20);
     
        } // method paint
    } // class Sketch
     
  15. Add comments to the top of the program file specifying your name(s) and other pertinent information.
  16. Compile the applet. Fix any problems that exist until you get a clean compile.
  17. Grab a copy (right click the link and select "Save Link as") of the following (linked) HTML code, saving it in a file called Sketch.html, in the same directory where Sketch.java and Sketch.class reside.
  18. The HTML code refers to the file Sketch.class. What does that file contain? Where does it come from?

  19.  
  20. Execute the program by submitting the HTML file to appletviewer. What is the output?
  21. Explain the parameters to the first call to drawLine.
  22. Modify the program such that the left end point of the first line is the same as the left end point of the second line. Compile and execute the program to test the change. What was the modification?
  23. Modify the program so that the first line is perpendicular to the second, forming a plus sign. Compile and execute the program. What was the modification?
  24. Explain the parameters to the first call to drawOval.
  25. Enlarge and reposition the second oval so that it completely contains the first. Compile and execute the program. Write down the modified call to drawOval.
  26. Change the second oval so that it is the same size as the first, and reposition it so that their edges touch, forming an infinity sign (sideways figure eight). Compile and test your modification.
  27. Using grade, submit the final version of Sketch.java.