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

Thread: Math Problem

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Math Problem

    Processing:

    Declare a String object to hold the programmer’s name - FINISH
    Declare three floating-point numbers and fill them from the Scanner input - FINISH
    Add the floating-point numbers together to create a subtotal - FINISH
    Calculate the tax for this subtotal, based on a tax rate of 9.25% - FINISH
    Calculate the total amount, which is the sum of the tax amount and subtotal - HELP ( no error but it's giving me the wrong answer)

    String firstNameString;
    	float firstTax;
    	float secondTax;
    	float thirdTax;
    	final double taxRate = 9.25;
     
     
     
    	Scanner inputScanner = new Scanner(System.in);
     
    	firstNameString = JOptionPane.showInputDialog("Enter your name");
    	System.out.print("\nEnter your First Number: ");
    	firstTax = inputScanner.nextFloat();
    	System.out.print("\nEnter your Second Number: ");
    	secondTax = inputScanner.nextFloat();
    	System.out.print("\nEnter your Third Number: ");
    	thirdTax = inputScanner.nextFloat();
     
    	//Display our input values
    	System.out.println("Name: " + firstNameString);
    	System.out.println("Total of three numbers: " + (firstTax + secondTax + thirdTax));
    	System.out.println("Tax " +(firstTax + secondTax + thirdTax) / taxRate);
    	System.out.println("Subtotal Tax: "+firstTax + secondTax + thirdTax + (+firstTax + secondTax + thirdTax / taxRate));
    Last edited by kidsforsale; September 14th, 2010 at 11:58 AM.


  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: Math Problem

    it's giving me the wrong answer)
    Please show what the program outputs and explain why it is wrong and what you want it to be.

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Math Problem

    Enter your First Number: 11.11
     
    Enter your Second Number: 11.11
     
    Enter your Third Number: 11.11
     
    Name: My Code
    Total of three numbers: 33.329998
    Tax 3.603243028795397
    Total of 3 numbers + Tax: 11.1111.1111.1123.4210803573196

    thanks for the reply

  4. #4
    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: Math Problem

    You left off this part:
    explain why it is wrong and show what you want it to be.

    The + operator does different things that can be confusing. Some times it sums two numbers to give a numeric result and some times it is used to concatenate Strings. You seem to be getting the latter. If you put what you want to be an addition inside of ()s then the two numeric operands will be added vs concatenated.

  5. #5
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Math Problem

    Sample Data (could be used for testing):

    If you input the following three values for your floating-point numbers:
    50.99
    75.95
    53.95
    The subtotal (3 numbers added) will be: 180.89
    The tax will be: 16.73
    The total amount including the tax will be: 197.62
    (The number of your decimal places will be different)
    first i want to get the answer of 9.25% of the total of 3 numbers
    then i want to add that 9.25% of that number to the total or the 3 numbers

    for example

    Your First Number: 11.11
    Your Second Number: 11.11
    Your Third Number: 11.11
    Total: 33.33
    9.25% of 33.33 is: ?? ( i dont know how to do it)
    9.25% of 33.33 + 33.33 = ?? ( same here )
    Last edited by kidsforsale; September 14th, 2010 at 12:52 PM.

  6. #6
    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: Math Problem

    ( i dont know how to do it)
    Can you compute 9.25% of 33.33?
    If you can do it, what are the steps you took to do it?
    If you don't know what percent means, try googling to find out.
    Hasn't your math training explained what percent means?

  7. #7
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Math Problem

    never mind i just dropped my programming in java class effin professor didn't explain how the eff are we gonna do that sht arggh

  8. #8
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Math Problem

    =o! It's not the professors fault, it's your arithmetic skills.

  9. #9
    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: Math Problem

    What grade level do they teach percentages?

    Basic math should be a prerequisite for a programming course.

  10. #10
    Junior Member
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Math Problem

    System.out.println("Subtotal Tax: "+firstTax + secondTax + thirdTax...)
    It prints these numbers next to each other, so if they're all 11.11 it'll print 11.1111.1111.11
    if you'll write it this way:
    System.out.println("Subtotal Tax: "+(firstTax + secondTax + thirdTax)...)
    it'll print 33.33
    a good programmer can write a Java program in any language

  11. #11
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Math Problem

    Well, for future references, you calculate a percentage of something by dividing the percent by 100, then multiplying by the the number you are wanting to get the percent of.

    So,
    Step 1 - Problem:
    9.25% of 33.33
    Step 2 - Get Percent in Decimal:
    0.0925 of 33.33
    Step 3 - Multiply:
    0.0925 x 33.33
    Step 4 - Answer:
    3.083025

    There are other ways, but thats how I do it.

  12. #12
    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: Math Problem

    Step 2 - Get Percent in Decimal:
    0.0925 of 33.33
    I would change that to this:
    9.25% is 0.0925

Similar Threads

  1. Help need on math java program
    By zidangus in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 6th, 2010, 07:41 PM
  2. Magic square class (modular math problem)
    By mjpam in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 30th, 2010, 10:56 AM
  3. switch and math problem issues
    By emartino in forum Java Theory & Questions
    Replies: 1
    Last Post: January 19th, 2010, 05:34 PM
  4. Question on my math
    By SwEeTAcTioN in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 25th, 2009, 05:42 PM
  5. Math in Java?
    By [Kyle] in forum Java Theory & Questions
    Replies: 3
    Last Post: September 23rd, 2009, 12:21 PM