Question: Lab Exercise 02.1 Payroll (looping) PLEASE USE JAVA This program will demonstrate the use of loops to repeat Java statements. The problem to be solved
Lab Exercise 02.1
Payroll (looping)
PLEASE USE JAVA
This program will demonstrate the use of loops to repeat Java statements. The problem to be solved is a simulated payroll program. A commercially written program would get its information from a database and print the output on a special paycheck form. We will have neither but will get the input from you, the user and the output will display on the monitor screen. All input values will be validated (checked for correctness and reasonableness).
It is an exercise in using the repeat statements and it is also an exercise in working out an algorithm. Be sure to figure out the steps to solve the problem before starting to code the program.
Please perform the following steps;
Work out the steps to solve the problem.
Start Eclipse and name the project something appropriate like Week01_Exercise 02.1
Place your program statements inside the main method of the Main class.
The program should first announce itself by printing a heading such as Payroll and then skip a line of output.
The user should be prompted to enter company information; this will be (a) the company name, (b) the number of employees and (c) the date today.
The user should be prompted to enter employee information; this should be name (first and last), pay rate for this employee (dollars per hour) and number of hours worked.
The program will then calculate the paycheck amount for this employee and display the following information on 4 output lines;
Company name
Todays date
Employees name
Paycheck amount
Skip 2 lines
Steps f. and g. (above) should be repeated for all employees in the company. The number of employees was input in step e (above). This means that all program code for steps f. and g. will be inside a loop.
All input values should be validated with a while loop. This includes
Number of employees in the company must be a positive integer number
The date today will be a String and so we wont test it for correct format.
Employees pay rate must be a positive number and should be $75.00 per hour or less.
Number of hours worked must be a positive number and must be 72 hours or fewer (thats 12 hours per day for 6 days and thats more than enough for anybody who doesnt want a heart attack).
Testing:
The program should be tested with 2-3 employees. More would be overkill! Use a variety of values and be sure to supply bad values to test the input validation loops.
Lab Exercise 02.2
Compound Interest
PLEASE USE JAVA
Compound interest is the way that you can turn a little bit of money into a lot of money, if and only if you have enough time. If I invest $100 at 6% and leave it alone for 10 years, I will have $179 at the end. If I keep adding money to the base amount (the $100), I can end up with lots more.
This problem is simple; the program will ask for the Present Value (the amount that you start with), the interest rate (which will be compounded annually) and the number of years over which to calculate. You must understand that this is not the way that interest is calculated today, by banks, credit card companies or anybody else. But it is an easy problem to understand and so we use it as a programming example.
The formula for compound interest is as follows;
FV = PV ( 1 + i)n
Where: FV Future Value
PV Present Value
i interest rate per period (as a decimal)
n number of periods over which to compound
The method for the program is
Ask for and read the Present Value
Ask for and read the Interest Rate
Ask for and read the number of Years
Perform the calculation
Display the result
In order to make the program easy to rerun, you will put the entire algorithm (steps 1 3 above) inside of a loop. Use a while loop which will terminate when the user answers N to the question Do you want to run again? Dont forget to validate your input each time!
Testing: In order to test this program, use at least the following values:
PV = 100 i = 6% n = 10
PV = 24 i = 5.5% n = 400
PV = 1000 i = 0.05 n = 240
Lab Exercise 02.3
Temperature Conversion
PLEASE USE JAVA
This problem is a temperature conversion problem. It is intended to give you more practice in writing methods for specific, separable purposes. You will write two new methods.
The main method will operate inside a loop and each time that the program completes a conversion, the user will be asked if Continue? is an option. If not, the program will terminate. The main method will be used to get a temperature and the validation limits will be between + 100.0 and 100.0 degrees.
The two new methods will be
Convert from Celsius to Fahrenheit
C = 5.0/9 * (F 32)
Convert from Fahrenheit to Celsius
F = 9.0/5 * C + 32
The program will ask whether Fahrenheit-to-Celsius or Celsius-to-Fahrenheit is wanted and then proceed to perform the requested conversion. You may want to check your program by remembering that F-61 is very near to C-16
NOTE: Since you now know how to use the two JOptionPane methods, showMessageDialog and showInputDialog, you may want to investigate a third method in JOptionPane called showConfirmDialog. It is ideal for asking if the user wants to continue converting temperatures.
NOTE: Validate all input values!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
