
-----------------------------------
Benner
Wed Apr 10, 2013 9:01 pm

How would I implement my classes into my program?
-----------------------------------
Hi.  For a school project I was instructed to create a class(s) that contain methods and variables relating to a game, for example everything from appearance of a character, to stats such as that character's strength, health, etc.  In my program I created two classes (class1 and class2) that have all of the methods and variables I need.  I made another class that creates a swing interface (swingclass) to display the information and change it etc through methods in the two classes.   Once I finish the code for swingclass I need to be able to open the interface in which it is able to interact with all the methods and variables in the 2 other classes.  

My dilemma is I don't know what to do in terms of using my classes to create the program.  I need my swingclass to have access to class1 and class2's methods. I need class1 and class2 to have access to eachother's methods. Right now my main method in my main class is empty and I don't know what to do.  Any help would greatly be appreciated... thanks.

If you are familiar with RPG games, this will be helpful I assume. Class1 contains methods and variables about the character (name, gender, inventory, level, xp etc) while class2 contains methods and variables about the character's class (stats like strength, stamina, health).  These two classes need to use eachother's methods.  On top of this my guiclass needs to be able to use all of the methods in both of the classes.  

Any help at all would greatly be appreciated. I'm sorry if my code looks like a mess. I'm think I should just paste the important bits but then again I'm not sure which parts are important for what I need to do.

MainClass [code] package chapter7project;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;


public class Chapter7project {
    
    public static void Message(String message){     //pop up message
        JOptionPane.showMessageDialog(null,message);
    }
    
    public static void main(String[] args) {
        newCharacterSwing gui = new newCharacterSwing();
        character character = new character();
        
        
        Message("");
        Message("");
        Message("");
        
        
       }
       
    }

[/code]

Class1 [code]package chapter7project;
import java.util.Scanner;

public class character {
   Scanner input = new Scanner(System.in);
   String name;
   boolean gender;
   int level;
   int xp;
   String[] inventory = new String[10];
   double[] xpToLvl = new double[90];
   Warrior charname;
   int killBoar;
   int damage;
   int goldLoot, baconLoot;
   int totalFood, totalGold;
    
   public character(){   
       level = 1;
       xp = 0;
       xpToLvl[1] = 50;
       charname = new Warrior();
       killBoar = 20; //xp given when you kill boar
       
       for (int i = 2; i  10){
           totalGold = totalGold -10;
           totalFood++;
       }
   }
   
   public void eatFood(){
       if (totalFood > 0){
           totalFood--;
           charname.changeHealth((int)(charname.maxHealth*0.15));
       }
   }
   
   public void changeFood(int amount){
       totalFood += amount;
   }
   
   public int getFood(){
          return(totalFood);
      }
   
   public void changeName(String name){
       this.name = name;
   }
   
   public String getName(){
       return(name);
   }
   
   public void changeGender(boolean gender){
       this.gender = gender;
   }
   
   public boolean getGender(){
       return(gender);
   }
   
   public void levelUp(){
       int remainder;
       if (xp >= (int)xpToLvl[level]){
           remainder = (xp - (int)xpToLvl[level]);
           xp = 0 + remainder;
           level++;
           charname.changeStrength((int)(charname.getStrength()*0.2));
           charname.changeCrit((int)(charname.getCrit()*0.2));
           charname.changeStamina((int)(charname.getStamina()*0.2));
           charname.maxHealth = ((int)(charname.maxHealth*0.2));
           charname.health = charname.maxHealth;
           
           System.out.println("Congratulations! You have reached level "+level+"!");
           System.out.println("Your Stength increased by "+(int)(charname.getStrength()/1.2)+"!");
           System.out.println("Your Stamina increased by "+(int)(charname.getStamina()/1.2)+"!");
           System.out.println("Your Critical Strike Chance increased by "+(int)(charname.getCrit()/1.2)+"!");
           System.out.println("Your Health increased by "+(int)(charname.getHealth()/1.2)+"!");
       }
                  
    }
   public void addItem(){
       int i; 
       String addItemID = input.nextLine();
       for (i = 0; i 