Hello I am almost finished with my assignment but I just need it to do the math correctly and I need help!!! I can easily do the problem on paper just fine however I can't get Netbeans to create the right answer. Here is the problem I need it to calculate

85,000 + (Sales x .10) = Annual compensation

Please help me or point me in the right direction. Thank you all!

//***
// Please enter total annual sales
//
// 85,000 + (Sales x .10) = Annual compensation
//***

package annualcompensation;

import java.util.Scanner;
import java.text.DecimalFormat;

public class annualcompensation
{
    public static double calculateannualcompensation(double sales, double compensation)
    {
       double salesAmount = compensation;
        sales /= 100;
        salesAmount *= sales;
        return salesAmount;
    }

    public static void main(String args[])
    {
        DecimalFormat df = new DecimalFormat("0.##");
        double compensation;
        double sales;
        double salesAmount;
        Scanner scan = new Scanner(System.in);

        System.out.println("Enter in the sales earned for the year");
        sales = scan.nextDouble();
        System.out.println("Enter in the annual salary");
        compensation = scan.nextDouble();
        salesAmount = calculateannualcompensation(sales, compensation);
        compensation += salesAmount;
        System.out.println("Total Sales tax: " + salesAmount);
        System.out.println("Total cost of the item (with sales tax): " + df.format(compensation));

    }
}

//85,000 + (Sales x .10) = Annual compensation becomes 85000 + (y*.10)= x

Recommended Answers

All 3 Replies

dividing by 100 is not the same as multiplying by 0.1

Line 18: Why do you multiply salesAmount with sales, while your formula states you have to add the quantities?

I can easily do the problem on paper

... then you are 90% of the way there.
Just do it on paper slowly, one small step at a time, and then convert those small steps to lines of code. Then reverse the process... pretend you are the computer and use your pen & paper to perform exactly and only the steps that your program specifies. If you do that carefully then it will be immediately obvious where the program deviates from the correct solution that you started with.
Even the most experienced and expert programmers will fall back on this technique when they hit a problem they can't solve by quicker techniques.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.