Ive been sitting in 3 hours trying to figure out whats wrong, read in my book, seen the Powerpoint and google search and now im giving up.. This is my last resort and I hope to learn how to do it.. Would appriciate the help guys.
Well, here i post my (what I have so far):

// ***************************************************************
// Salary.java
//
// Computes the amount of a raise and the new
// salary for an employee. The current salary
// and a performance rating (a String: "Excellent",
// "Good" or "Poor") are input.
// ***************************************************************
import java.util.Scanner;
import java.text.NumberFormat;
public class Salary
{
	public static void main (String[] args)
	{
	double currentSalary; // employee's current salary
	double raise; // amount of the raise
	double newSalary; // new salary for the employee
	String rating; // performance rating

	Scanner scan = new Scanner(System.in);
	
	System.out.print ("Enter the current salary: ");
	currentSalary = scan.nextDouble();
	
	System.out.print ("Enter the performance rating (Excellent, Good, or Poor): ");
	rating = scan.next();

	// Compute the raise using if ...
	// Comparation of String is a little different than int. We use a
	// String method equals as follow:
		//HERE i have problem, I think this is the only
                                 //Thing thats left to fix..

		if (rating.equalsIgnoreCase("Exellent"))
		{
			raise = 0.06
		}
		if (rating.equalsIgnoreCase("Good"))
		{
			raise = 0.04
		}
		if (rating.equalsIgnoreCase("Poor"))
		{
			raise = 0.015
		}
		
	newSalary = currentSalary + raise;

	// Print the results
	NumberFormat money = NumberFormat.getCurrencyInstance();
	System.out.println();
	System.out.println("Current Salary: " + money.format(currentSalary));
	System.out.println("Amount of your raise: " + money.format(raise));
	System.out.println("Your new salary: " + money.format(newSalary));
	System.out.println();		
	}
}

Thx

Recommended Answers

All 5 Replies

Looks like raise is intended to be a % value, so you shouldn't just add that to the salary - you're only adding 1.5 to 6 cents in your current code.

Yeah, i notised after a few testing and sorted it by myself :D

added

double amount;
double raise = 0; // amount of the raise = 0;

and changed a few things at the end

newSalary = currentSalary * raise;
	amount = newSalary - currentSalary;
	
	DecimalFormat fmt = new DecimalFormat ("0.##");
	// Print the results
	NumberFormat money = NumberFormat.getCurrencyInstance();
	System.out.println();
	System.out.println("Current Salary: " + money.format(currentSalary));
	System.out.println("Amount of your raise: " + fmt.format(amount) + " kr");
	System.out.println("Your new salary: " + money.format(newSalary));
	System.out.println();

Line 1 still not quite right - a raise in normally in addition to the current salary!

Yeah, but I have done it like this:
Taking the raisenumber i decimalformat as 1.06 and mulptiplies it.
newSalary = currentSalary * 1.06
Its the same as newSalary = currenSalasry + (currentSalary*0.06)
Both of this are the same result

Yes, OK. You didn't show the code where you changed from 0.06 to 1.06, so I didn't know that you had done that!
Mark as solved now?

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.