![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 3
Rep Power: 0
![]() |
A little help needed.....?
Ok trying a bit of programming, first in ages...
Trying to make 2 classes, Player and GameTest. Ok, what i want to do is for a prompt to ask the user for firstname, secondname, nickname etc...you will see in the code. This is player: import java.io.* ;
class Player
{
String line, firstName, secondName, nickName;
int age;
char sex;
// constructor
Player( String first, String last, String nick, int age, char sex )
{
firstName = first ;
secondName = last ;
nickName = nick ;
}
BufferedReader userIn =
new BufferedReader(
new InputStreamReader( System.in ) );
System.out.println("Please enter your first name:" );
firstName = userIn.readLine();
System.out.println("Please enter your second name:" );
secondName = userIn.readLine();
System.out.println("Please enter your nickName:" );
nickName = userIn.readLine();
System.out.println("Please enter your age:" );
line = userIn.readLine();
age = Integer.parseInt( line );
System.out.println("Are you male or female?:" );
sex = userIn.readLine();
//put in if m=male or f=female otherwise error
void details()
{
System.out.println( "Your details: " + firstName + secondName);//and all the rest....
}
}
}This is gameTest: class GameTest
{
public static void main( String[] args )
{
Player player1 = new Player(
Andrew, Schofield, Sco, 22, M);
System.out.println( "Your details: "
+ player1.details() );
}
}Now instead of me typing in my details, i would like to be prompted on it, so do I need all the lines of code prompting in the player class, or the game test? My overall idea is to have like a text based story game, you know with loads of decisions which effect the way the book turns out. I want those decisions to effect characteristics which the user enters at the start, so age will increase, nickname may change etc etc, all depending on decisions in the story. I may also need to add more than 1 player, so thats why i have the player class... Any help? Sco |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
GameTest is almost certainly a better place to put text parsing code, although i'd probably build a seperate class used by your driver to parse input for keywords, etc. It's a much less brittle way to handle things.
'Course my projects usually end up spanning like twice as many files as i think they probably should, but breaking things down too much is almost always better then not breaking them down enough. Last edited by ZenMasterJG; May 4th, 2005 at 12:40 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|