Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

New java programmer needs help

Hi so far I have taken a semester of java at my highschool during my freshman year. I think its great. (This is my first posting so i don't know if i am in the right place). Anyway, for my semester final i thought to design a game like halo 2, but very very very much simpler.
I was thinking that my code runs like this
(note that this is just inside jcreator no applets or stuff like that)
Hi you are playing halo 1.9.
Would you like to start or look at the rules(press 1 for rules etc...)?
Would you like to start on ivory tower or ascenion(press 1 for...)
...
My game would be very simple. First i have draw a 2d map with stick figures(\ | / - _) and every box would be numbered. So one would respond in area 1 and you would have choices to move to another area and then you might see and enemy. Note: Most of this game would be text based, very few pix(just of some weapons you pick) and those would still be simple system.out.println statements.
note: Our teacher requires we have 5 classes, two related by inheritance.
SO for my problem: in the place i have put * , i do not know how to go back to the method startGame, since the user input invalid info. In the places I have put ^^, I need to run another method from another class BUT i cannot inherit the method because there is no IS A relationship between my other class. And according to my teacher, inheritance cannot be used without a IS-A relationship. Basically where the ^ are, the program would start the game.
import java.util.Scanner;

public class Greeting {
public String introduction
{
return "Good day, you are playing";
return"H) hh l)L 1)! 9)((( ";
return"H) hh l) 1)!! 9) (( ";
return"H)hhhhhh a)AAAA l) o)OOO 1) 9)(((( ";
return"H) hh a)AAA l) o) OO 1) 9) ";
return"H) hh a) A l) o) OO 1) ** 9) (( ";
return"H) hh a)AAAA l)LL o)OOO 1)!!!!! ## 9)((( ";
return"T)tttttt h) N)n nn t) ";
return" T) h) N)nn nn t)tTTT ";
return" T) h)HHHH e)EEEEE N) nn nn e)EEEEE x) XX t) ";
return" T) h) HH e)EEEE N) nnnn e)EEEE x)X t) ";
return" T) h) HH e) N) nnn e) x)X t) ";
return" T) h) HH e)EEEE N) nn e)EEEE x) XX t)T ";
return" G)gggg ";
return" G) ";
return"G) ggg e)EEEEE n)NNNN ";
return"G) gg e)EEEE n) NN ";
return" G) gg e) n) NN ";
return " G)ggg e)EEEE n) NN ";
}

public String startGame
{
return "Would you like to go over the rules or start playing{enter play to play or rules to examine the rules}";
String playOrRules = in.next;

public void rulesOrgame
{
f (playOrRules.equals "rules")
{
return "you cannont ... ";
}
if (playOrRules.equals "play")
{
^^^^^^^^^^^^
}
else
{
return "That is not a vaild entry. Please try again.";
*******
}
}
}

Sorry this is so long, if anyone read this, i greatly appreciate the effort and time.
If you have any other ideas for my program plz say so, I appreciate any lvl of help.
[3695 byte] By [SamK] at [2007-11-11 7:33:36]
# 1 Re: New java programmer needs help
Your code is confusing, however, here are a few things you should know about methods ...

1. They can only return one object (String, int, double, etc.)
2. Once it makes a return, nothing else in the method will be executed, including other return statements
3. void methods cannot return anything, you will get compile errors

To call a void method, simply enter the method name in the code. Example:

// previous code

methodName();

// remaining code
Hope that helps :)
srekcus at 2007-11-11 22:37:55 >
# 2 Re: New java programmer needs help
Oh ok, i'll change the return statements to system.out.println's. But that still doesn't answer my first question :confused:
SamK at 2007-11-11 22:38:55 >
# 3 Re: New java programmer needs help
You could use an if where the user enters the string..
public String startGame
{
System.out.println "Would you like to go over the rules or start playing{enter play to play or rules to examine the rules}";
String playOrRules = in.next;
if((!playOrRules.equals "rules") || (!playOrRules.equals "play"))
{
System.out.println "Incorrect entry please enter play or rules.. ";
String playOrRules = in.next;
}
return playOrRules;
}

This way there will be no need for you to test playOrRules inside your next class..
Code_Nerd at 2007-11-11 22:39:59 >