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

1. 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));```

2. 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. 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. 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. 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 )

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

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

9. Re: Math Problem

What grade level do they teach percentages?

Basic math should be a prerequisite for a programming course.

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

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