207k views
5 votes
Write a program that can print a banner with rotated letters, such that they can be read from top to bottom. Specifically, each letter in the message should be printed using multiple lines composed of * symbols. The code to print each letter should go into a separate method just for that letter (no parameters, no return value). Don’t worry, you don’t need to make 26 different methods, just 8: the seven letters in the message "Hello World" (D, E, H, L, O, R, and W) and a space. In your main method, you should ask the user to type a message. Then, loop through each character in the message and, for each character, if you have a corresponding method, call the method to print out the letter to the screen, ignoring any other characters. To help get you started, here is an example method for the letter D:

1 Answer

3 votes

Answer:

package Lab6Problema;

import java.util.Scanner;

public class Lab6Problema{

public static void H() // prints H

{

System.out.println();

System.out.println("** **");

System.out.println("** **");

System.out.println("******");

System.out.println("** **");

System.out.println("** **");

}

public static void E()//prints E

{

System.out.println();

System.out.println("******");

System.out.println("** ");

System.out.println("******");

System.out.println("** ");

System.out.println("******");

}

public static void L()//prints L

{

System.out.println();

System.out.println("* ");

System.out.println("* ");

System.out.println("* ");

System.out.println("* ");

System.out.println("******");

}

public static void O()//prints O

{

System.out.println();

System.out.println("******");

System.out.println("* *");

System.out.println("* *");

System.out.println("* *");

System.out.println("******");

}

public static void W()//prints W

{

System.out.println();

System.out.println("* *");

System.out.println("* *");

System.out.println("* ** *");

System.out.println("* ** *");

System.out.println("** **");

}

public static void R()//prints R

{

System.out.println();

System.out.println("***** ");

System.out.println("** **");

System.out.println("***** ");

System.out.println("** **");

System.out.println("** **");

}

public static void D()//prints D

{

System.out.println();

System.out.println("**** ");

System.out.println("* * ");

System.out.println("* *");

System.out.println("** * ");

System.out.println("**** ");

}

public static void blank() //prints blank space

{

System.out.println();

System.out.println();

System.out.println();

}

public static void main(String[] args) {

//just enter "Hello World" as input as specified

System.out.println("Enter a Message");

Scanner scan=new Scanner(System.in);

String myMessage=scan.nextLine(); // read msg using scanner

int numOfCharacters=myMessage.length();// calculate message lenth

for(int i=0;i<numOfCharacters;i++) // loop through each chracter in msg

{

// gets character at position i, and switch accordingly

switch(myMessage.charAt(i))

{

// if character is 'H' or 'h', call method H(). Similarly for other

// Hecharacters in message.

case 'H':

case 'h':H();break;

case 'E':

case 'e':E();break;

case 'L':

case 'l':L();break;

case 'O':

case 'o':O();break;

case 'W':

case 'w':W();break;

case 'R':

case 'r':R();break;

case 'D':

case 'd':D();break;

case ' ':blank();break;

}

}

}

}

Step-by-step explanation:

User Monfresh
by
5.5k points