# Some guidance with a program please

• June 10th, 2011, 01:35 PM
derekxec
Some guidance with a program please
Hi i am trying to make a program that gets 2 inputs from a user(command line program) and calculates them with some static information and gives the user the result.

Guess its better if i explain what the program is for first...

i play an MMORPG game kinda like final fantasy and im trying to make a damage calculator...i want the user to put in their attack or matk and then the skill they will use to hit the target and the program should calculate the dmg they will cause

this is the equation that the program will perform to get the result

(Atk/Matk * 1.4 + Skill increase - 200 * 0.98)

so what i need to do is have the user put in their atk/matk number and their skill(to figure out the increase that should be applied and i already know the numbers for the skills) but there is like 30 or so skills that you can choose from

so here is the code i have so far

Code :

```package DamageCalc;   import java.util.Scanner;   public class DmgCalc { public static void main (String args[]) {   int Attack; Scanner input = new Scanner(System.in);   System.out.println("Enter your Atk/Matk?"); Attack = input.nextInt();   System.out.println("Your Attack is: " + Attack); } }```

i just put the your attack is part so i could see if i did the scanner part right :D

so my question is for all the 30 skills i think i could do if/then statements for all right? but what im wondering is there an easier way to do the skills than to have 30 if/then statements? im not looking for the exact code to finish it just more about what i could learn to make it smaller than 30 if/then statements(if that will work).

edit: sorry i forgot to mention that each skill has a different increase

thanks for any help you can provide and i hope i posted this in the right section:cool:
• June 10th, 2011, 02:04 PM
Norm
Re: Some guidance with a program please
Look at using the switch statement instead of a bunch of if/else if statements.

Another possibility would be to use an array with 30 elements. Index it with the attack value entered by the user.

BTW Java coding conventions have variables beginning with lower case letters. Upper case is use for class names. See int Attack
• June 10th, 2011, 02:31 PM
derekxec
Re: Some guidance with a program please
ahhh thank you very much lol sorry my fiancee gets on me about naming stuff with lower case letters so it spills over to this haha
• June 11th, 2011, 05:52 AM
dlorde
Re: Some guidance with a program please
You could write a Skills class that contains the name of the skill and its value. Then you create a Skills object for every skill and add them to a List (e.g. ArrayList). This gives you a list of skills. Then you can loop through the list using the name of each skill to prompt for the value to put into it. This way you only need to code the prompt and input once (no long, messy 'if..else' or 'switch.. case' statements), and you can have as many skills as you want.