CS 200 - Lab 28

LetterH class

Write a Java class that represents a letter H of a specified height and width, and has a draw() method which draws a letter H of the specified size in the console window.

Getting started

Start Eclipse.

Create a new Java project called letterh.

Create a package called edu.ycp.cs200.letterh.

Within the package, create a class called LetterH.

Add a main method to the class that looks like this:

public static void main(String[] args) {
int h, w;
Scanner keyboard = new Scanner(System.in);

System.out.print("Enter height and width: ");
h = keyboard.nextInt();
w = keyboard.nextInt();

LetterH letter = new LetterH(h, w);
letter.draw();
}

Your task

You will need to add to the class:

fields representing the height and width of the letter H

a constructor taking height and width as parameters, and initializing the fields of a new instance of LetterH

a draw() method that draws a letter H in the console window, based on the height and width of the letter H being drawn

Example run (user input in bold red):

Enter height and width: 11 7
* *
* *
* *
* *
* *
*******
* *
* *
* *
* *
* *