there are 3 classes letterd, letteru, letterh. each class uses loops to print asterisks in the form of letter d, u, h. each letter has two charateristics width and height. the constructor of each class accepts two integer parameters that correspond to height and width. each class also has a method called toString which returns a string that contains all the characters needed to properly form the corresponding letter. the tester program testerduh which is available.. produces the following output where the height and width of each letter are seven characters. create a duhconsole class that asks the user to enter the width and height then prints duh using those dimensions. the dimensions must be odd numbers and must be a minimum of five characters.

Recommended Answers

All 6 Replies

I think you need to do/show a little work first before you ask for help

class LetterD {
// Override toString() for Letter class.
private int width;
private int height;
LetterD(int w, int h){
width = w;
height = h;
}
    @Override
public String toString(){
        String r = "";

        for(int i=1;i<=height;i++){
        if(i==1||i==height){
        for(int j=1;j<=(width-1);j++){
        r=r+"*";}
        r=r+"\n";}
        else{r=r+"*";
        for(int j=1;j<=(width-2);j++){
        r=r+" ";}
        r=r+"*\n";}}
        return r;}}

so far i'm done with D but i can think how to make the U and H

public class TesterDUH {

public static void main(String args[]) {

    LetterD a = new LetterD(7,7);

       System.out.println(a.toString());


    }

}

and the runner code

and also if you use eclipse you auto formatter please

i can't make the U and H that's my problem...

my ide is netbeans

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.