CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Basic Java Class Help (http://www.codingforums.com/showthread.php?t=284064)

bballrmx 12-13-2012 02:52 AM

Basic Java Class Help
 
Java hangman GuessPrase HELP!?
Create a GuessPhrasePanel class and implement the following (NOTE: Make sure your methods work the same for upper and lower case letters):

a. Has a constructor taking a String guess phrase

b. Shows all the letters in the phrase, initially just showing the underline for all alphabet letters (not the letter as it needs to be guessed). Spaces and other punctuation should be shown with no underline.

c. setPhrase – sets a new phrase to this GuessPhrase object, gets rid of old phrase parts and creates new ones

d. hasLetter – a method that returns whether or not a specified letter is in the phrase

e. revealLetter – a method that reveals or shows a specified letter (if there are more than one of that letter, all should be revealed)

f. isFullPhraseRevealed – returns whether or not the full phrase has been revealed

g. revealFullPhrase – reveals the full phrase

PLEASE HELP IM SO LOST I HAVE NO IDEA WHAT TO PUT IN THE METHOD BODIES AND IN MAIN. im just a beginner and my teacher refuses to offer help.
I was given these instructions and i need to write my own code. this is what i was able to come up with.
i got like 30-40% i think. but i dont know how to finish.

if you can tell me how. to do these parts. what they are supposed to look like. if it needs an if statement or not or something like that. just some guidance im soo lost. please if you can suggest anything at all!

if possible if you can write up the code id really appreciate it, im going to fail the class if i cant get this perfect. IM BEGGING YOU

my code
------------------------------
Code:

import java.io.IOException;

import javax.swing.JPanel;


public class GuessPhrasePanel extends JPanel {

String phrase;

public GuessPhrasePanel (String phrase){


}

public void setPhrase(String p) {
phrase = p;       


}

public boolean hasLetter(char c){
return hasLetter(c);

}
public boolean isFullPhraseRevealed(){
return isFullPhraseRevealed();
}

public void revealLetter(char c){

}

public void revealFullPhrase(){

}
public static void main(String[] args) {

GuessPhrasePanel myGuessPhrasePanel = new GuessPhrasePanel;

//(supposed to initialize letters here)
}

}


Fou-Lu 12-13-2012 02:30 PM

Quote:

Originally Posted by bballrmx (Post 1299528)
PLEASE HELP IM SO LOST I HAVE NO IDEA WHAT TO PUT IN THE METHOD BODIES AND IN MAIN. im just a beginner and my teacher refuses to offer help.
I was given these instructions and i need to write my own code. this is what i was able to come up with.

In which case its likely time to contact a department head or dean. Instructors are paid to assist you in the learning process. If you are a beginner, you shouldn't be using GUI's in the first place.

Since you are using a gui though, the answer is simple: you don't put that in your main methods at all. You attach the event handlers for the keydowns or add a submit button and a ActionListener and chain the events to the method provided by the GuessPhrasePanel. So the main (which I wouldn't put in a panel class) is responsible for instantiating the frame, adding this panel, and attaching the listeners it requires.


All times are GMT +1. The time now is 10:18 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.