Introduction to Programming (CPSC 124)
—Hobart & William Smith Colleges, Fall 2014
Project #2
Home | Syllabus | Calendar | Class Notes | Labs and Projects | General Notes

Due by the start of class on Thursday, 09/25/2014

Problems

The following five programming problems can all be completed using nested loops. You job is to write five different programs, one for each problem.

  1. Write a program, triangle1.java, which takes a single integer argument, n. The program should print a String of characters, representing a right triangle whose legs (the sides that meet at a 90 degree angle) consist of n * characters. The widest edges should be on the left and bottom. For example:

    John-Lasseter:~ jlasseter$ java  triangle1 5
    *
    * *
    * * *
    * * * *
    * * * * *
    
  2. Write a program, triangle2.java, which takes a single integer argument, as in Problem 1. The program should print a String of characters, representing a right triangle whose legs (the sides that meet at a 90 degree angle) consist of n * characters. The widest edges should be on the left and top. For example:

    John-Lasseter:~ jlasseter$ java  triangle2 5
    * * * * *
    * * * *
    * * *
    * *
    *
    
  3. Write a third program, triangle3.java, which prints a a (2n-1) by n isosceles triangle, with the widest edge on the left. For example:

    John-Lasseter:~ jlasseter$ java  triangle3 5
    *
    * *
    * * *
    * * * *
    * * * * *
    * * * *
    * * *
    * *
    *
    
  4. Your fourth program, triangle4.java, should print out a (2n-1) by n isosceles triangle, with the widest edge on the bottom. For example:

    John-Lasseter:~ jlasseter$ java  triangle4 5
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *
    
  5. Like the four triangle problems, your fifth and final program, diamond.java, takes an integer argument, n. This program should print out a (2n-1) by (2n-1) diamond shape. For example:

    John-Lasseter:~ jlasseter$ java  diamond  5
            *
          * * *
        * * * * *
      * * * * * * *
    * * * * * * * * *
      * * * * * * *
        * * * * *
          * * *
            *
    

Turn in (READ ME):

To summarize, there are five programs you need to write, all saved in a folder named lab2:

You are to submit these source code files electronically and with a printed copy (I need to have paper to mark up and the digital file to run your program). Your five source files should be saved in a folder named hw2 and this folder should be copied copied into your folder in the class directory

/classes/cs124/<your user name>/

NOTE: Make sure you're actually copying it to this folder and not your own home folder at /afs/afs.hws.edu/home/<your user name>! This is an obvious source of confusion, and will lead you to think you've turned in your work to me when you haven't.

As in Homework #12, please respect my file name requests. I ask for precise names because it makes it easier for me to test your work. Thanks.

Standards (READ ME)

Formatting Requirements

General


John H. E. Lasseter