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: My first program. opinions on what i could do better

  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 My first program. opinions on what i could do better

    This is my first program i have ever made in java and i am wonder what you all think of how its laid out and what i could do better to improve it or on the next program i make....It's a damage calculator for a game i play online thanks

    package DamageCalc;
     
    import java.util.Scanner;
     
    public class DmgCalc {
    	public static void main (String args[]) {
     
    		int attack,element;
     
    		Scanner input = new Scanner(System.in);
     
    		System.out.println("Enter your Attack");
    		attack = input.nextInt();
     
    		System.out.println("What is your Element? (Use 1-4) 1-Fire 2-Water 3-Earth 4-Wind");
    		element = input.nextInt();
     
    		if(attack == 0) {
    			System.out.println("Your damage is 0.");
    		}else{
     
    		switch(element) {
    		case 1:
    			attack =(int)((attack * 1.4 + 0 - 2 * 0.98) * 1.6);
    			System.out.println("Your Damage against your weak element is " + attack);
    		    break;
    		case 2:
    			attack =(int)((attack * 1.4 + 0 - 2 * 0.98) * 1.3);
    			System.out.println("Your Damage against your weak element is " + attack);
    		    break;
    		case 3:
    			attack =(int)((attack * 1.4 + 0 - 2 * 0.98) * 1.4);
    			System.out.println("Your Damage against your weak element is " + attack);
    		    break;
    		case 4:
    			element =(int)((attack * 1.4 + 0 - 2 * 0.98) * 1.3);
    			System.out.println("Your Damage against your weak element is " + element);
    		    break;
     
    		    default:
    		    	System.out.println("Exiting...Please follow directions.");
    		    }
    		}
    	}
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: My first program. opinions on what i could do better

    That's a great example of learning how to program by writing little programs that are useful for something else you already enjoy. That's the way to go.

    You asked for a critique, but honestly, if it works, and it fits in your head (so you understand it really well), then I wouldn't spend too much time worrying about how to improve it. Just keep on trucking, keep programming, and in a few months you'll look back and think to yourself "WHAT was I thinking?!". Not that there's anything blatantly wrong with the program, but that feeling happens to everybody.

    That being said, are these just constant numbers, or do/will they change? You could just store them in an array at the corresponding index instead of using a switch statement. But like I said, don't worry too much about it.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    derekxec (June 20th, 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: My first program. opinions on what i could do better

    this is exactly what i was looking for thanks for responding

    the only numbers that change are the attack and the end number on the calculation(1.6 1.3 1.4) depending on the element chosen everything else stays the same

    the next chapter in my book is on arrays so ill try to drop the switch statement for an array

  5. #4
    Member
    Join Date
    Jun 2011
    Location
    Rhode Island
    Posts
    69
    My Mood
    Bored
    Thanks
    11
    Thanked 7 Times in 6 Posts

    Default Re: My first program. opinions on what i could do better

    Quote Originally Posted by derekxec View Post
    This is my first program i have ever made in java
    I think Kevin Said it all, great job on that switch statement, error checking on your input lines. Keep Programming challenges and increase functionality. To help keep track of your logic write it down on paper and then follow your design. Pseudo code helps think out your program logic before you have hours of wasted time.

    Keep up the good work.

  6. The Following User Says Thank You to william For This Useful Post:

    derekxec (June 20th, 2011)

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. A few opinions on a project desired
    By LDM91 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 17th, 2010, 02:36 PM