classes, double format specifier and pound sign

Hi all,
finally following the advice on this forum I got hold of the Deitel and Deitel java how to program 9th edition! Great book I must say so far (only got to chapter 3). Now, I am doing some of the exercises as I go along, and today I have done 3.14:

p 137 ex 3.14 EMPLOYEE CLASS: create a class called Employee that includes three instances variables - a first name (string), a last name (string) and a monthly
salary (double). Provide a constructor that initializes the three instance variable. Provide a set and get method for each instance variable. If the monthly salary is
not positive do not set its value. Write a test application named employeeTest that demonstrates class Employee's capabilities. Create two Employee objects and
display each object's yearly salary. Then give each employee a 10% raise and display each Employee's yearly salary

It all went quite well, but there are a few things I had some problems with. My program has 2 files Employee.java and EmployeeClass.java:

Now, first problem: format specifier: I was looking for a double format specifier and I thought I found it in %l but I had a runtime error - sorry I amended the code now and I didn't take a screenshot of the error(I am using the ubuntu terminal by the way). I had something like System.out.printf("\nSalary:%l ", employee1.getSalary()); but I had to change it to System.out.println("\nSalary: \u00A3" + employee1.getSalary()); ANy idea if there is such a thing as a double format specifier?

Other thing, the £ sign: that was driving me insane. I have finally managed to find this \u00A3 that prints a £ sign, but I am really sure that there's got to be another way to do this...I had a look online but I didn't find much help, any advice?

You shouldn't use floating point types to represent money because they are imprecise. They are designed to give you a close approximation of the correct answer. Doubles especially can give you a very close approximation because they are large enough to store a large amount of precision, which is great for most scientific calculations, simulations, and games. For money, people don't just want a large amount of precision; they want total precision; they won't accept the calculated answer being different from the true answer by even a tenth of a penny, and with floating point arithmetic it is difficult to be sure exactly how far off your answer might be. You might accidentally gain or lose entire dollars. It's just not safe.

You can usually hold money as an integer number of cents - very few applications ever neen to handle a fraction of cent. int will usually do, or long if you need amounts over 20 million dollars. If you write a simple method to take a value in cents and format it as a String with dollars and cents, dollar sign, commas etc then it's no harder than working in floating point dollars.

oh right, that's interesting. So basically it's a bit like the price of petrol you mean, say £1,489.00 will be 148900. But how do I then format it as a tring? Is there a specific class in java the can do it, or should I do it manually

You can use the Formatter class, but even so I think it's simpler if you get that the way you want it then put it in a simple method yoiy can call every time you want to display a money value. (That also puts you in a good place if you want to change currency to (eg) Euros, with . as the thousands delimiter and , for the cents)