Advertisement
MalsvirVishe

Out Of Bounds

Oct 22nd, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Calculator
  4. {
  5.   public char hp;
  6.   public int finalStat;
  7.   public double natureMult;
  8.  
  9.   public void readInput()
  10.   {
  11.     Scanner keys = new Scanner(System.in);
  12.    
  13.     System.out.println("Enter the base stat.");
  14.     int base = keys.nextInt();
  15.      
  16.     System.out.println("Enter the IV.");
  17.     int iv = keys.nextInt();
  18.    
  19.     System.out.println("Enter the EV.");
  20.     int ev = keys.nextInt();
  21.    
  22.     System.out.println("Enter the level.");
  23.     int level = keys.nextInt();
  24.     if(level<1 || level>100)
  25.     {
  26.       System.out.println("Error! Invalid level!");
  27.       System.exit(0);
  28.     }
  29.    
  30.     System.out.println("Is the nature increase, decrease, or neutral?");
  31.     char nature;
  32.     nature = keys.nextLine().toLowerCase().charAt(0);
  33.    
  34.     if(nature=='i')
  35.       natureMult=1.1;
  36.     else if(nature=='n')
  37.       natureMult=1.0;
  38.     else if(nature=='d')
  39.       natureMult=0.9;
  40.     else
  41.     {
  42.       System.out.println("Error! You entered an invalid multiplier!");
  43.       System.exit(0);
  44.     }
  45.    
  46.     System.out.println("Is the stat HP?");
  47.     hp = keys.nextLine().toLowerCase().charAt(0);
  48.     if(hp!='y' || hp!='n')
  49.     {
  50.       System.out.println("Error! You did not pick yes or no!");
  51.       System.exit(0);
  52.     }
  53.    
  54.     if(hp=='y')
  55.       finalStat = hpCalc(base, iv, ev, level);
  56.     else
  57.       finalStat = statCalc(base, iv, ev, level, natureMult);
  58.   }
  59.  
  60.   public void writeOutput()
  61.   {
  62.     if(hp=='y')
  63.       System.out.println("The final stat is: " + finalStat);
  64.     else if(hp=='n')
  65.       System.out.println("The final stat is: " + finalStat);
  66.   }
  67.  
  68.   private int hpCalc(int a, int b, int c, int d)
  69.   {
  70.     int stat;
  71.     stat = (int)((b+2*a+c/4.0+100)*d/100+10);
  72.     return stat;
  73.   }
  74.  
  75.   private int statCalc(int e, int f, int g, int h, double i)
  76.   {
  77.     int stat;
  78.     stat = (int)(((f+2*e+g/4.0)*g/100+5)*h);
  79.     return stat;
  80.   }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement