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

Thread: Simple addition problem help please!

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Simple addition problem help please!

    SOLVED!
    Thanks
    Last edited by UbaldoJimenez; April 4th, 2012 at 07:50 PM.


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Simple addition problem help please!

    I've tried Car1(sellingprice) and made a variable for it in Car but it did not work.
    What does "did not work" mean? Specifically I guess we are talking out the lines:

    //14
    System.out.println("\n" + car1.CalcSellingprice() + car2.CalcSellingprice() + car3.CalcSellingprice() + car4.CalcSellingprice());

    What output does that expression produce?

    -----

    A separate matter, but it would be a good idea to follow Java coding conventions and begin your methods with a lower case letter: calcTax() etc.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple addition problem help please!

    It produced: 18889.529925.042000.025200.0

    Which are the totals of each separate car without spacing but I need the total of them all.


    Thanks

  4. #4
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Simple addition problem help please!

    Yes, what you get is the string concatenation of all the items. + does two things in Java: it performs string concatenation and it performs arithmetic addition. Basically you should do the additions first, before the concatenation. And to determine the order of operations we use parentheses.

    public class Foo {
        public static void main(String[] args) {
            System.out.println("" + 4 + 2);
            System.out.println("" + (4 + 2));
        }
    }

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple addition problem help please!

    Got it I also corrected the capitalization on my calcs.

    Thanks I greatly appreciate the help brockway.

  6. #6
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Simple addition problem help please!

    You're welcome - I'm glad you've got it sorted out.

Similar Threads

  1. simple addition inside { of after the if
    By spongyballs in forum Loops & Control Statements
    Replies: 2
    Last Post: October 23rd, 2011, 06:42 PM
  2. [SOLVED] Addition Quiz
    By javaneedhelp in forum Loops & Control Statements
    Replies: 5
    Last Post: October 9th, 2011, 12:55 AM
  3. Addition
    By ruffu054 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: August 14th, 2011, 10:49 PM
  4. text value addition problem
    By kundan_101 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: January 8th, 2011, 10:46 AM