943,703 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 542
  • Java RSS
Nov 10th, 2008
-1

methods

Expand Post »
Hello, I need help!!! Very new to programming.
I need a program that will display a menu with the letters C,E,F,L and X for exit and allow the user to select a letter from the menu. If the user selects X,print an appropriate message and end the program. If the user selects one of the other letters, display letter in a large block CCCCCCCCC
CCCCCCCCC
CC
CC
CC
CC
CCCCCCCCC
CCCCCCCCC and then display the menu again. The program should conatin at least 7 methods. The following is what I have so far, but I am stumped how to get the large block output to the user's choice. I am thankful for any help!
import java.util.Scanner;
public class Letters
{

public static void main(String[] args)
{
displayMenu();
displayMessage();
printBlockC('C',3,10);
printBlockC('C',3,3);
printBlockC('C',3,10);
}
public static void displayMenu()
{
char letter;
String input;
Scanner keyboard=new Scanner (System.in);
System.out.println("Please enter a letter:\n C, E, F, or L, \n"+
" Enter X to exit");
input=keyboard.nextLine();
letter=input.charAt(0);



while(input.equalsIgnoreCase("C,E,F,L,"))
{
System.out.println("Please enter a letter:\n C, E, F,or L, \n"+
" Enter X to exit");
input=keyboard.nextLine();
letter=input.charAt(0);

}


}

public static void displayMessage()
{
System.out.print("Thank you for playing!");
}
public static void printBlockC(char symbol, int rows,int columns)
{
int i;
int j;
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
System.out.print(symbol);
}
System.out.println();
}
}
public static void printBlockE(char symbol, int rows,int columns)
{
int i;
int j;
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
System.out.print(symbol);
}
System.out.println();
}
}
public static void printBlockF(char symbol, int rows,int columns)
{
int i;
int j;
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
System.out.print(symbol);
}
System.out.println();
}
}
public static void printBlockL(char symbol, int rows,int columns)
{
int i;
int j;
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
System.out.print(symbol);
}
System.out.println();
}
}
}
}
Similar Threads
Reputation Points: 8
Solved Threads: 0
Newbie Poster
jayjaysam0441 is offline Offline
3 posts
since Nov 2008
Nov 10th, 2008
0

Re: methods

It looks like you don't save the input anywhere other than in displayMenu(). None of the other methods can see that input variable.
You could have displayMenu() return the character that the user input and then pass that to a printing method.

It'll look like:
Java Syntax (Toggle Plain Text)
  1. public static String displayMenu(){
  2. //do stuff
  3. return input;
  4. }

Then in your main method you can say:
String input = displayMenu();
Last edited by bionicseraph; Nov 10th, 2008 at 10:13 pm. Reason: Added code example
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008
Nov 11th, 2008
0

Re: methods

Hello, I need help!!! Very new to programming.
I need a program that will display...
You already have a thread dedicated to this same exact question here, with quite a few responses.
Last edited by jasimp; Nov 11th, 2008 at 8:29 am.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007
Nov 11th, 2008
0

Re: methods

Thank you for all of your help!!!!
Reputation Points: 8
Solved Threads: 0
Newbie Poster
jayjaysam0441 is offline Offline
3 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: beginner mousepressed homework
Next Thread in Java Forum Timeline: Java Swing Problem - won't repaint





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC