Ask Experts Questions for FREE Help !
Ask
    avenger9000's Avatar
    avenger9000 Posts: 99, Reputation: 2
    Junior Member
     
    #1

    Oct 26, 2008, 08:18 PM
    calling a constructor outside of the class
    Ok here I am writing a game... when I got to the constructor which is called to create a character, it doesn't work. It keeps saying symbol not found when I in fact did have the same file name and parameter parsed when I called it... so what's the deal?

    public class SCRpg{

    public static void main(String [] args){
    System.out.println("Please enter a player name between 4 and 10 characters");
    String playerName = getPlayerName();
    String welcomeMessage = "Welcome to SCRpg " + playerName;
    printWelcome(welcomeMessage);
    showMenu();
    int userChoice = getUserChoice();

    if (userChoice == 1){
    createChar();
    }
    if (userChoice == 4){
    printCredits();
    }
    else{
    System.exit(0);
    }
    }

    public static String getPlayerName(){
    String myString = Keyboard.readInput();
    boolean lengthIsOk = checkLength(myString);
    do{
    if (!lengthIsOk){
    System.out.println("The player name you have entered is invalid, please reenter.");
    myString = Keyboard.readInput();
    }
    }
    while (lengthIsOk == false);
    return myString;
    }

    public static boolean checkLength(String myString2){

    boolean myBoolean = true;
    if (myString2.length() > 10 || myString2.length() < 4){
    myBoolean = false;
    }
    return myBoolean;
    }

    public static void printWelcome(String myString3){
    System.out.println(myString3);
    }

    public static void showMenu(){
    System.out.println("1. New Game");
    System.out.println("2. Load Game");
    System.out.println("3. Options");
    System.out.println("4. Credits");
    }

    public static int getUserChoice(){
    int uc = Integer.parseInt(Keyboard.readInput());
    boolean choiceIsValid = true;
    do{

    if (uc == 0 || uc > 4){
    choiceIsValid = false;
    System.out.println("Your choice is invalid, please try again.");
    uc = Integer.parseInt(Keyboard.readInput());
    }


    }
    while (choiceIsValid == false);
    return uc;
    }

    public static void createChar(){

    int race = chooseRace();
    int level = 1;
    int damage = 10;
    int armor = 0;
    int hp = 100;
    int energy = 100;
    int plasmaShields = checkRace(race, plasmaShields);


    character.playerChar1 = new character(level, damage, hp, energy, plasmaShields, armor);

    }

    public static int chooseRace(){
    System.out.println("Please choose your race: ");
    System.out.println("1. Terran/n 2. Protoss/n 3. Zerg");
    int race = Integer.parseInt(Keyboard.readInput());
    return race;
    }

    public static int checkRace(int race, int plasmaShields){
    if (race == 2){
    plasmaShields = 100;
    }
    else{
    plasmaShields = 0;
    }
    return plasmaShields;
    }








    public static void printCredits()
    {
    System.out.println("Made by Adam Zhang");
    }

    }

    and here's the constructor code in another class called character

    public class character{

    private int level;
    private int damage;
    private int hp;
    private int energy;
    private int plasmaShields;
    private int armor;


    public character(int level, int damage, int hp, int energy, int plasmaShields, int armor){
    this.level = level;
    this.hp = hp;
    this.damage = damage;
    this.energy = energy;
    this.plasmaShields = plasmaShields;
    this.armor = armor;
    }

    }
    jstrike's Avatar
    jstrike Posts: 418, Reputation: 44
    Full Member
     
    #2

    Nov 12, 2008, 01:19 PM

    String myString = Keyboard.readInput();

    It's most likely looking for a class called Keyboard and can't find it. I don't see an import for it and afaik, it's not part of the java 6 sdk.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Wha does class e and class b mens [ 8 Answers ]

Hello I live in the state of ma. My question is what does class e means and class b for license electricians.

Class D felony [ 5 Answers ]

What is a Class D felony and what is the penalty? couns1337

Marie, I hear you calling, Marie the night is falling,Marie will you keep calling me [ 2 Answers ]

"Marie, I hear you calling, Marie the night is falling, Marie will you keep calling me" Every time the word"calling" is sung, it's held and rises. Any hints re anything? Title, artist, lyrics? Probably early 1950s.

Gym class task! [ 4 Answers ]

I chose Morphine as the drug I'm going to research I need the long and short term physical and psychological effects of the drug and the effects of the drug on relationships with family, family friends and other young people I just need them to finish my task :) :) thank you if decide...

Constructor Design [ 1 Answers ]

When you create a class you must create a constructor, right? so should you create more than one constructor for every class you create? 1) no argument constructor to initialize ALL private values in case the user doesn't & 2) all other possible variations depending on what the user may...


View more questions Search