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 8 of 8

Thread: Help with ints

Threaded View

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with ints

    I declared a public int in one class, modified it in that class, then tried to call it in another class, but when I call it, none of the modifications that were made carry over.

    The variable:
    public int dmg = 5;

    Where it is modified:
    case 1: 
    						if (gold >= 2){
    						dmg += 10;
    						gold -= 2;
    						out.println("Thank you. Have a nice day!");
    						}
    						else{
    							out.println("You are too poor.");
    						}
    						decision = 0;
    						break;
    What this is doing is buying a weapon, then adding to the dmg int.

    Where it is being called:
    static town city = new town();
    public int dmg(){
    	return dmg;
     
     
     
    case 1: 
    				wolf1hp -= city.dmg();
    				out.println("You have dealt " + city.dmg() + " damage." );
    				if (wolf1hp <= 0){
    					out.println(" You killed the first wolf.");
    				}
    				playerhealth -= wolf2dmg;
    				out.println("Wolf 2 attacked you and you lost " + wolf2dmg + ". You now have " + playerhealth + " health.");
    				decision = 0;
    				break;
    this is a simple battle scenario, and when i run it, instead of saying 15 damage it just says 5.
    Last edited by MAK; June 26th, 2014 at 03:12 PM.


Similar Threads

  1. Replies: 2
    Last Post: February 24th, 2014, 10:48 PM
  2. input.next and taking ints and doubles
    By CruelCoin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 6th, 2013, 07:00 AM
  3. Split a String into Ints
    By spunkyk014 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 7th, 2013, 09:35 PM
  4. Evaluating two ints at the same time
    By Sean448 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 05:21 AM
  5. Adding doubles and ints.
    By SkyAphid in forum Java Theory & Questions
    Replies: 6
    Last Post: September 8th, 2011, 05:54 PM