Write a Java class named Salary
that determines whether or not each person
in a group of persons is above or below the average salary for the group.
The input will be n pairs of strings and salaries representing the
names of each person and their salary. For example:
java Salary nels 105000.80 mary 20000.50 frank 18153.33 nancy 91868.73 michelle 20858
Your program should print each name and true if the person's salary is above
the average salary for the group and false otherwise (if the salary
equals the average, then output false). For example:
average salary = 51,176.27
nels 105,000.80 true
mary 20,000.50 false
frank 18,153.33 false
nancy 91,868.73 true
michelle 20,858.00 false
You should be able to use the array search program covered in class and
shown in the example code as a guide. A few notes:
- Your error checking should be limited to ensuring that the user
enters an even number of arguments (since the arguments come in
pairs) and that the user provides at least one pair of
arguments. You may assume that the salaries represent valid numbers.
- Your output formatting should be as follows:
- names left justified in a field 15 characters wide.
String objects can be printed using %s.
- salaries should be printed right justified
in a field 10 characters wide
with two decimal points. There should be a thousands
separator (if you missed the class, read the notes on
how to do this or ask someone in the class for their notes).
- true/false should be left-justified with no field width
information provided.
- the average salary should be left justified in a field
10 characters wide with two decimal points, and a
thousands separator.
- You must declare a class to store a person's information. I don't
care what you name it. Since it only needs to be used by your
Salary class, you should nest it within the Salary class (that way
you also only need to use one file). Since your main method will
be static, make sure you declare the Person class to be static or
else the compiler will complain.
- Store the objects in an array.
- You can use the parseDouble method from the Double class
to convert a string to a double.