Help with following Programs:
Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Add the if... else... statements to program Salary to make it run as described above.
// *************** *************** *************** *************** ***
// Salary.java
// Computes the amount of a raise and the new
// salary for an employee. The current salary
// and a performance rating (an int: 1 = "Excellent" ,
// 2 = "Good" or 3 = "Poor") are input.
// *************** *************** *************** *************** ***
import cs1.Keyboard;
import java.text.Numbe rFormat;
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
int rating; // performance rating
System.out.prin t ("Enter the current salary: ");
currentSalary = Keyboard.readDo uble();
System.out.prin t ("Enter the performance rating (1 = Excellent, 2 = Good, or 3 = Poor): ");
rating = Keyboard.readIn t();
// Compute the raise using if ...
newSalary = (currentSalary + raise);
// Print the results
NumberFormat money = NumberFormat.ge tCurrencyInstan ce();
System.out.prin tln();
System.out.prin tln("Current Salary: " + money.format(cu rrentSalary));
System.out.prin tln("Amount of your raise: " + money.format(ra ise));
System.out.prin tln("Your new salary: " + money.format(ne wSalary));
System.out.prin tln();
}
}
I tried putting the following (below) after the comment// Compute the raise using if ... but it gave an error that said raise might not have been initialized.
if (rating == 1)
{
raise=(currentS alary * 0.06);
newSalary= currentSalary + raise;
}
if (rating == 2)
{
raise = (currentSalary * 0.04);
newSalary= currentSalary + raise;
}
if (rating == 3)
{
raise = (currentSalary * 0.015);
newSalary= currentSalary + raise;
}
The other program perfromance rating should be entered as a String. The three possible ratings are "Excellent" , "Good", and "Poor". An employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Note that you will have to use the equals method of the String class (not the relational operator ==) to compare two strings.
// *************** *************** *************** *************** ***
// Salary2.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 cs1.Keyboard;
import java.text.Numbe rFormat;
public class Salary2
{
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
System.out.prin t ("Enter the current salary: ");
currentSalary = Keyboard.readDo uble();
System.out.prin t ("Enter the performance rating (Excellent, Good, or Poor): ");
rating = Keyboard.readSt ring();
// Compute the raise using if ...
newSalary = (currentSalary + raise);
// Print the results
NumberFormat money = NumberFormat.ge tCurrencyInstan ce();
System.out.prin tln();
System.out.prin tln("Current Salary: " + money.format(cu rrentSalary));
System.out.prin tln("Amount of your raise: " + money.format(ra ise));
System.out.prin tln("Your new salary: " + money.format(ne wSalary));
System.out.prin tln();
}
}
I Tried Putting the following(below ) in the 2nd program after the coment // Compute the raise using if...but it gave an error that said raise and newSalary might not have been initialized.
String Excellent;
Excellent= Keyboard.readSt ring();
if (rating == Excellent)
raise=0.06;
String Good;
Good= Keyboard.readSt ring();
if (rating==Good)
raise=0.04;
Good= Keyboard.readSt ring();
String Poor;
Poor= Keyboard.readSt ring();
if (rating==Poor)
raise=0.015;
Poor= Keyboard.readSt ring();
newSalary = (currentSalary + (+raise));
Thanks for the help
Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Add the if... else... statements to program Salary to make it run as described above.
// *************** *************** *************** *************** ***
// Salary.java
// Computes the amount of a raise and the new
// salary for an employee. The current salary
// and a performance rating (an int: 1 = "Excellent" ,
// 2 = "Good" or 3 = "Poor") are input.
// *************** *************** *************** *************** ***
import cs1.Keyboard;
import java.text.Numbe rFormat;
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
int rating; // performance rating
System.out.prin t ("Enter the current salary: ");
currentSalary = Keyboard.readDo uble();
System.out.prin t ("Enter the performance rating (1 = Excellent, 2 = Good, or 3 = Poor): ");
rating = Keyboard.readIn t();
// Compute the raise using if ...
newSalary = (currentSalary + raise);
// Print the results
NumberFormat money = NumberFormat.ge tCurrencyInstan ce();
System.out.prin tln();
System.out.prin tln("Current Salary: " + money.format(cu rrentSalary));
System.out.prin tln("Amount of your raise: " + money.format(ra ise));
System.out.prin tln("Your new salary: " + money.format(ne wSalary));
System.out.prin tln();
}
}
I tried putting the following (below) after the comment// Compute the raise using if ... but it gave an error that said raise might not have been initialized.
if (rating == 1)
{
raise=(currentS alary * 0.06);
newSalary= currentSalary + raise;
}
if (rating == 2)
{
raise = (currentSalary * 0.04);
newSalary= currentSalary + raise;
}
if (rating == 3)
{
raise = (currentSalary * 0.015);
newSalary= currentSalary + raise;
}
The other program perfromance rating should be entered as a String. The three possible ratings are "Excellent" , "Good", and "Poor". An employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Note that you will have to use the equals method of the String class (not the relational operator ==) to compare two strings.
// *************** *************** *************** *************** ***
// Salary2.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 cs1.Keyboard;
import java.text.Numbe rFormat;
public class Salary2
{
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
System.out.prin t ("Enter the current salary: ");
currentSalary = Keyboard.readDo uble();
System.out.prin t ("Enter the performance rating (Excellent, Good, or Poor): ");
rating = Keyboard.readSt ring();
// Compute the raise using if ...
newSalary = (currentSalary + raise);
// Print the results
NumberFormat money = NumberFormat.ge tCurrencyInstan ce();
System.out.prin tln();
System.out.prin tln("Current Salary: " + money.format(cu rrentSalary));
System.out.prin tln("Amount of your raise: " + money.format(ra ise));
System.out.prin tln("Your new salary: " + money.format(ne wSalary));
System.out.prin tln();
}
}
I Tried Putting the following(below ) in the 2nd program after the coment // Compute the raise using if...but it gave an error that said raise and newSalary might not have been initialized.
String Excellent;
Excellent= Keyboard.readSt ring();
if (rating == Excellent)
raise=0.06;
String Good;
Good= Keyboard.readSt ring();
if (rating==Good)
raise=0.04;
Good= Keyboard.readSt ring();
String Poor;
Poor= Keyboard.readSt ring();
if (rating==Poor)
raise=0.015;
Poor= Keyboard.readSt ring();
newSalary = (currentSalary + (+raise));
Thanks for the help
Comment