Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Some guidance with a program please

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 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

    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

    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
    Last edited by derekxec; June 10th, 2011 at 01:42 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default 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

  3. The Following User Says Thank You to Norm For This Useful Post:

    derekxec (June 10th, 2011)

  4. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default 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

  5. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default 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.

Similar Threads

  1. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM
  2. Looking for guidance and instructions
    By coyboss in forum Java Theory & Questions
    Replies: 4
    Last Post: February 12th, 2011, 10:57 AM
  3. [SOLVED] Medication of ArrayDemo.java to include iterative menu
    By xyldon27 in forum Loops & Control Statements
    Replies: 8
    Last Post: June 30th, 2009, 02:10 AM