Question

In: Computer Science

Computing A Raise File Salary.java contains most of a program that takes as input an employee’s...

Computing A Raise

File Salary.java contains most of a program that takes as input an employee’s salary and a rating of the employee’s performance and computes the raise for the employee. This is similar to question #3 in the pre-lab, except that the performance rating here is being entered as a String—the three possible ratings are “Excellent”, “Good”, and “Poor”. As in the pre-lab, 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. Note that you will have to use the equals method of the String class (not the relational operator ==) to compare two strings (see Section 5.3, Comparing Data).

// ************************************************************
  • // 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;
double raise;
double newSalary;
String rating;
// employee's current  salary
// amount of the raise
// new salary for the employee
// 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 ... 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();

}

Solutions

Expert Solution

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

CODE TO COPY

NOTE: YOU CAN REPLACE rating.equals() TO rating.equalsIgnoreCase() INORDER TO AVOID CASE SENSITIVE


// ************************************************************
// 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 = 0; // amount of the raise
       double newSalary = 0; // 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 ...
       if (rating.equals("Excellent")) {
           raise = 6;
//           raise = currentSalary*(raise/100);
           newSalary = currentSalary + raise;
       } else if (rating.equals("Good")) {
           raise = 4;
//           raise = currentSalary*(raise/100);
           newSalary = currentSalary + raise;
       } else if (rating.equals("Poor")) {
           raise = 1.5;
//           raise = currentSalary*(raise/100);
           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();

   }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EXPLANATION


// ************************************************************
// 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 = 0; // amount of the raise
       double newSalary = 0; // 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 ...
       if (rating.equals("Excellent")) { // if the string entered is Excellent then raise is 6
           raise = 6; //set raise as 6
//           raise = currentSalary*(raise/100); //uncomment this if you want to raise by percentage
           newSalary = currentSalary + raise; // by default it raises just by adding
       } else if (rating.equals("Good")) { // if entered string is Good
           raise = 4; //set raise as 4
//           raise = currentSalary*(raise/100);
           newSalary = currentSalary + raise; // by default it raises just by adding
       } else if (rating.equals("Poor")) { // if entered string is Poor
           raise = 1.5;/ / set raise a s1.5
//           raise = currentSalary*(raise/100); //uncomment this if you want to raise by percentage
           newSalary = currentSalary + raise; // by default it raises just by adding
       }

       // 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();

   }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

OUTPUT

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

IF YOU HAVE ANY PROBLEM REGARDING THE SOLUTION PLEASE COMMENT BELOW I WILL HELP YOU///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Related Solutions

[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
Modify this program so that it takes in input from a TEXT FILE and outputs the...
Modify this program so that it takes in input from a TEXT FILE and outputs the results in a seperate OUTPUT FILE. (C programming)! Program works just need to modify it to take in input from a text file and output the results in an output file. ________________________________________________________________________________________________ #include <stdio.h> #include <string.h> // Maximum string size #define MAX_SIZE 1000 int countOccurrences(char * str, char * toSearch); int main() { char str[MAX_SIZE]; char toSearch[MAX_SIZE]; char ch; int count,len,a[26]={0},p[MAX_SIZE]={0},temp; int i,j; //Take...
Write a program that takes two sets ’A’ and ’B’ as input read from the file...
Write a program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the file...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
Write a program that takes a date as input and outputs the date's season. The input...
Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...
Write a program that asks the user for a file name. The file contains a series...
Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in the array 5)...
Write a short C++ program that takes all the lines input to standard input and writes...
Write a short C++ program that takes all the lines input to standard input and writes them to standard output in reverse order. That is, each line is output in the correct order, but the ordering of the lines is reversed. Please use vector datatype standaard library #include <vector> Thanks
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT