Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 3rd, 2005, 5:08 PM   #1
Sco
Newbie
 
Join Date: Nov 2004
Posts: 3
Rep Power: 0 Sco is on a distinguished road
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
Sco is offline   Reply With Quote
Old May 4th, 2005, 12:37 AM   #2
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
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.
ZenMasterJG is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC