Guest User

Person.java

a guest
Nov 13th, 2010
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. /*
  4.  * Created by Arvind Thambidurai
  5.  * Created: 10-21-2010
  6.  * Last updated: 11-12-2010 by Brandon 
  7.  *
  8.  * The Person class is the superclass for any people in my code.  
  9.  * It contains many actions that a default person can use.
  10.  * There is a lot of interaction involved, both between other people
  11.  * (such as attack, greet, and sell), as well as between objects
  12.  * (such as attacking WITH, selling, and eating).
  13.  *
  14.  * The person class is also in charge of maintaining the basic statistics
  15.  * and properties of a person, such as name, energy, strength, life, etc.
  16.  *
  17.  * It contains all the functions within it to modify its own properties,
  18.  * which is done either through the person class, or through other classes.
  19.  *
  20.  * The two classes that inherit from Person are FARMER and BLACKSMITH
  21.  *
  22.  */
  23.  
  24. public class Person
  25. {
  26.    
  27.     //these are all the common properties of a personn
  28.     int height, weight, age, money, energy, strength, life;
  29.     String name, address, weapon, armor, weakness, rank;   
  30.     boolean isMale;
  31.    
  32.     //the constructor for a person, takes in all stats from its subclasses and assigns them as the values
  33.     public Person(int Height, int Weight, int Age, int Money, int Energy, int Strength, String Name, String Address, boolean isMan)
  34.     {
  35.         height=Height;
  36.         weight=Weight;
  37.         age=Age;
  38.         money=Money;
  39.         energy=Energy;
  40.         strength=Strength;
  41.         name=Name;
  42.         address=Address;
  43.         isMale=isMan;
  44.         life=1000;
  45.     }
  46.    
  47.     //returns the name of a person
  48.     public String getName()
  49.     {
  50.         return name;
  51.     }
  52.    
  53.     //sets the name of a person to a specific String
  54.     public void setName(String n)
  55.     {
  56.         name=n;
  57.     }
  58.    
  59.     //allows the person to rest, increasing energy and life
  60.     public void sleep()
  61.     {
  62.         energy++;
  63.         life=life+energy;
  64.         System.out.println(this.getName()+" has slept for a night and rested up.");
  65.     }
  66.  
  67.     //allows a person to attack another person (with a metal item) to inflict damage on the person
  68.     //first it calculates the amount of damage dealt  by factoring the metal used and the person's stats
  69.     //then it applies the damage to the victim
  70.     //then it reduces the stats of the attacker slightly, burning energy and strength  
  71.     public void attack(Person p, MetalA m)
  72.     {
  73.         int dmg = this.energy*this.strength*m.getStrength();
  74.         System.out.println(this.getName()+" attacks "+p.getName()+" and deals "+(dmg)+" damage.");
  75.         p.modLife(dmg);
  76.        
  77.         if (p.getLife() < 0)
  78.             System.out.println(p.getName()+" has died.");
  79.        
  80.         energy--;
  81.         strength--;
  82.     }
  83.  
  84.     //returns the current value of life a person has
  85.     public int getLife()
  86.     {
  87.         return life;
  88.     }
  89.    
  90.     //modifies the current value of life a person has by an integer n
  91.     public void modLife(int n)
  92.     {
  93.         life=life-n;
  94.         System.out.println(this.getName()+ " has " + life + " life remaining");
  95.     }
  96.    
  97.     //alters the energy value of a person by an integer n
  98.     public void modEnergy(int n)
  99.     {
  100.         this.energy=this.energy+n;
  101.     }
  102.    
  103.     //returns the current energy value of a person
  104.     public int getEnergy()
  105.     {
  106.         return energy;
  107.     }
  108.    
  109.     //alters the current strength value of a person by an integer n
  110.     public void modStrength(int n)
  111.     {
  112.         this.strength=this.strength+n;
  113.     }
  114.    
  115.     //returns the current strength value of the person
  116.     public int getStrength()
  117.     {
  118.         return strength;
  119.     }
  120.    
  121.     //adds or subtracts a certain integer amount of money from the person
  122.     public void modMoney(int n)
  123.     {
  124.         this.money=this.money+n;
  125.     }
  126.    
  127.     //returns the amount of money a person has
  128.     public int getMoney()
  129.     {
  130.         return this.money;
  131.     }
  132.  
  133.     //outputs the current stats on the person, including money, life, energy, and strength
  134.     public void status()
  135.     {
  136.         System.out.println(this.getName()+"'s Money totals "+this.getMoney());
  137.         System.out.println(this.getName()+"'s Life is at "+this.getLife());
  138.         System.out.println(this.getName()+"'s Strength is at "+this.getStrength());
  139.         System.out.println(this.getName()+"'s Energy is at "+this.getEnergy());
  140.     }
  141.    
  142.     //allows the person to eat an (Plant) object, which increases their stats
  143.     public void eat(Plant p)
  144.     {
  145.         this.modEnergy(p.getNutrition());
  146.         this.modStrength(p.getNutrition());
  147.         this.modLife(p.getNutrition()*p.getHealth());
  148.     }
  149.    
  150.     //sets the players rank based on number of kills
  151.     public void setRank(int kills)
  152.     {
  153.         if (kills < 5)
  154.         {
  155.             System.out.println("You Have killed less than 5 people, keep on killing! ");
  156.             rank = "noob";
  157.         }
  158.        
  159.         else if (kills >= 5 && kills < 10)
  160.         {
  161.             System.out.println("You have ordered the killing of 5 people, you have reached the rank of 'Blood Thirsty'");
  162.             rank = "Blood Thirsty";
  163.         }
  164.        
  165.         else
  166.         {
  167.             System.out.println("You have ordered the killing of 10 people, you have reached the rank of 'Brutal'");
  168.             rank = "Brutal";
  169.         }
  170.     }
  171.    
  172.     public String getRank()
  173.     {
  174.         return rank;
  175.     }
  176.    
  177.     public void standDown()
  178.     {
  179.         System.out.println(name+": Soldiers, Stand Down!");
  180.     }
  181.    
  182.     public int getAge()
  183.     {
  184.         return age;
  185.     }
  186.    
  187.     public int getHeight()
  188.     {
  189.         return height;
  190.     }
  191.    
  192.     public int getWeight()
  193.     {
  194.         return weight;
  195.     }
  196.    
  197.     public String getWeapon()
  198.     {
  199.         return weapon;
  200.     }
  201.    
  202.     public void setWeapon(String newWeapon)
  203.     {
  204.         weapon = newWeapon;
  205.     }
  206.    
  207.     public String getArmor()
  208.     {
  209.         return armor;
  210.     }
  211.    
  212.     public void setArmor(String newArmor)
  213.     {
  214.         armor = newArmor;
  215.     }
  216.    
  217.     public void command()
  218.     {
  219.         System.out.print("(A)ttack or (S)tand Down?");
  220.         Scanner in = new Scanner(System.in);
  221.         String choice = in.nextLine();
  222.         choice.toLowerCase();
  223.         /*
  224.         if (choice.equals("a"))
  225.             attack();
  226.         else
  227.             standDown();
  228.         */
  229.     }
  230. }
RAW Paste Data