Advertisement
oona

super heroes 2

Apr 10th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.63 KB | None | 0 0
  1. package oop;
  2.  
  3. class superHero
  4. {
  5.     String heroName; //name of the superhero
  6.     String realName; //alias name
  7.     boolean human; //is he/she a human
  8.     String powers; //special abilities
  9.     String weakness; //not able to do
  10.     int createdYear; //when did he/she appear
  11.     String nemesis; //worst enemy
  12.    
  13.     public void setHName(String heroName)
  14.     {
  15.         this.heroName = heroName;
  16.     }
  17.     public void setRName(String realName)
  18.     {
  19.         this.realName = realName;
  20.     }
  21.     public void setHuman(boolean human)
  22.     {
  23.         this.human = human;
  24.     }
  25.     public void setPowers(String powers)
  26.     {
  27.         this.powers = powers;
  28.     }
  29.     public void setWeakness(String weakness)
  30.     {
  31.         this.weakness = weakness;
  32.     }
  33.     public void setCYear(int createdYear)
  34.     {
  35.         this.createdYear = createdYear;
  36.     }
  37.     public void setNemesis(String nemesis)
  38.     {
  39.         this.nemesis = nemesis;
  40.     }
  41.     public String getHName()
  42.     {
  43.         return this.heroName;
  44.     }
  45.     public String getRName()
  46.     {
  47.         return this.realName;
  48.     }
  49.     public boolean getHuman()
  50.     {
  51.         return this.human;
  52.     }
  53.     public String getPowers()
  54.     {
  55.         return this.powers;
  56.     }
  57.     public String getWeakness()
  58.     {
  59.         return this.weakness;
  60.     }
  61.     public int getCYear()
  62.     {
  63.         return this.createdYear;
  64.     }
  65.     public String getNemesis()
  66.     {
  67.         return this.nemesis;
  68.     }  
  69. }
  70.  
  71. public class superHeroes {
  72.  
  73.     public static void main(String[] args) {
  74.         // TODO Auto-generated method stub
  75.        
  76.         superHero[] array = new superHero[10];
  77.        
  78.         for(int i=0; i<10; i++)
  79.         {
  80.             array[i] = new superHero();
  81.            
  82.             int choice = -1;
  83.             int counter = 0;
  84.  
  85.         while(choice!=4)
  86.         {
  87.             choice = TextIO.getInt(); //accept choice as an integer
  88.            
  89.             if(choice == 1)
  90.             {
  91.                 System.out.println("Add the name of a superhero");
  92.                 array[counter].setHName(TextIO.getWord());
  93.                
  94.                 System.out.println("What's the hero's real name?");
  95.                 array[counter].setRName(TextIO.getWord());
  96.                
  97.                 System.out.println("Is he/she a human");
  98.                 array[counter].setHuman(TextIO.getBoolean());
  99.                
  100.                 System.out.println("What is his/her special ability");
  101.                 array[counter].setPowers(TextIO.getWord());
  102.                
  103.                 System.out.println("What isn't he/she able to do?");
  104.                 array[counter].setWeakness(TextIO.getWord());
  105.                
  106.                 System.out.println("Enter the year the hero was created");
  107.                 array[counter].setCYear(TextIO.getInt());
  108.                
  109.                 System.out.println("Worst enemy ever");
  110.                 array[counter].setNemesis(TextIO.getWord());
  111.                
  112.                 counter++;
  113.             }
  114.             if(choice == 2)
  115.             {
  116.                 System.out.println("Print detail about the superhero");
  117.                 System.out.println(array[counter].getHName());
  118.                 System.out.println(array[counter].getRName());
  119.                 System.out.println(array[counter].getHuman());
  120.                 System.out.println(array[counter].getPowers());
  121.                 System.out.println(array[counter].getWeakness());
  122.                 System.out.println(array[counter].getCYear());
  123.                 System.out.println(array[counter].getNemesis());
  124.                 counter++;
  125.             }
  126.             if(choice == 3)
  127.             {
  128.                 char choice3 = 'A';
  129.                 choice3 = TextIO.getChar();
  130.                
  131.                 if(choice3 == 'A')
  132.                 {
  133.                     array[counter].setCYear(TextIO.getInt());
  134.                     System.out.println(array[counter].getHName() + " since " + array[counter].getCYear());
  135.                 }
  136.                 if(choice3 == 'B')
  137.                 {
  138.                     array[counter].setNemesis(TextIO.getWord());
  139.                     System.out.println(array[counter].getHName() + "'s worst enemy is " + array[counter].getNemesis());
  140.                 }
  141.                 if(choice3 == 'C')
  142.                 {
  143.                     array[counter].setPowers(TextIO.getWord);
  144.                     System.out.println(array[counter].getHName() + "'s special ability is " + array[counter].getPowers());
  145.                 }
  146.             }
  147.             if(choice == 4)
  148.             {
  149.                 System.out.println("Goodbye!");
  150.             }
  151.            
  152.         }
  153.         }
  154.        
  155.     } //main ends here
  156.  
  157. } //class ends here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement