Question

In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that...

In Java

#2 JAVA Write a program named salaryCalculator that accepts input from the user that represents an annual salary for employees. This program should all be written in the main driver program no additional classes are needed.

Your program should do the following:

  1. Prompt the user for a salary continually until the user enters a sentinel value, a negative number.
  2. Keep two running totals the first is the total of all original salaries and the second is a total of all revised salaries
  3. The program should determine whether the salary is below $50000. If it is, then increase the salary by 10%
  4. Output the average salary without raises and the average salary with raises.

Sample:

Enter a salary or negative number to quit: 55000

Enter a salary or negative number to quit: 52000

Enter a salary or negative number to quit: 40000

Enter a salary or negative number to quit: 30000

Average salary without raises is $44,250

Average salary with raises is $46,000

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class salaryCalculator
{
   public static void main(String[] args)
   {
   //scanner for input
   Scanner sc = new Scanner(System.in);
  
   //declaration of variable
   float totalWithRaise = 0, totalWithoutRaise = 0, salary;
   float avgWithRaise, avgWithoutRaise;
  
   int count = 0;
   while(true)
   {
   //display message on the computer screen
   System.out.print("Enter a salary or negative number to quit: ");
   salary = sc.nextFloat();
   if(salary<0)
   break;
  
   //calculate total without raise   
   totalWithoutRaise = totalWithoutRaise + salary;
   if(salary<50000)
   {
   salary = salary + salary * 10 / 100;
   }
  
   //calculate total with raise
   totalWithRaise = totalWithRaise + salary;
   count++;
   }
  
   //calcuate average
   avgWithoutRaise = totalWithoutRaise / count;
   avgWithRaise = totalWithRaise / count;
  
   //display the result on the computer screen
   System.out.printf("\nAverage salary without raises is $%.2f", avgWithoutRaise);
   System.out.printf("\nAverage salary with raises is $%.2f", avgWithRaise);
      
   }
}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications....

    Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications. It should use a do-while loop to prompt the user with the following starting prompt (without the horizontal lines) until the user enters 4 to quit. The program should start with an initial account balance, which you can set to any legitimate double value. Prompt the user with the following prompt (without the horizontal lines). Enter the number of your desired transaction type. Deposit...

  • Write a Java program that will create an array of Strings with 25 elements. Input Strings...

    Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...

  • In Java please: Write a program that will prompt the user to enter GPA values one...

    In Java please: Write a program that will prompt the user to enter GPA values one per line, stopping when the user enters a negative Input: value. Print the following on separate lines: . The number of vaild GPAs entered » The sum of the GPAs 4.0 3.7 2.9 3.5 -1 The average GPA

  • Java Write a program that prompt the user to enter a decimal number representing the radius...

    Java Write a program that prompt the user to enter a decimal number representing the radius of a circle. If the number is greater or equal to zero, the program displays the area of the circle. Otherwise, the program displays “negative input”

  • Write a small JAVA program that continually reads in user values and calculates the average of all values. The program s...

    Write a small JAVA program that continually reads in user values and calculates the average of all values. The program should first ask the user for the number of values to be entered. Upon storing this value, the program should proceed to read in that amount of values. What will be the best strategy here? a suggestion would be only calculating the average after you know you have read in all values. You can expect to use some type of...

  • Write a program that allows the user to enter a series of exam scores. The number...

    Write a program that allows the user to enter a series of exam scores. The number of scores the user can enter is not fixed; they can enter any number of scores they want. The exam scores can be either integers or floats. Then, once the user has entered all the scores they want, your program will calculate and print the average of those scores. After printing the average, the program should terminate. You need to use a while loop...

  • Create a java program which will prompt a user to input a product and its cost....

    Create a java program which will prompt a user to input a product and its cost. Using a while loop that will run until the sentinel value of “stop” (any case) is entered, the program will look for items with a cost greater than or equal to $100.00. The program will find the average cost of those items. Note: immediately after your statement containing input.nextDouble() you will need to add the following input.nextLine() statement. This will cause the input scanner...

  • Write a program that receives a series of numbers from the user and allows the user...

    Write a program that receives a series of numbers from the user and allows the user to press the enter key to indicate that he or she is finished providing inputs. After the user presses the enter key, the program should print the sum of the numbers and their average.   >>> totalSum =0 >>> count=0 >>> while True:    number=input("Enter a number or press enter to quit:")    if number =="":        break    totalSum += float(number)    count+=1...

  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • Write a Java program which allows the user to perform simple tasks on a calculator. A...

    Write a Java program which allows the user to perform simple tasks on a calculator. A series of methods allows the user to select an operation to perform and then enter operands. The first method displays a menu, giving the user the choice of typing in any one of the following: +, -, *, /, or % representing the usual arithmetic operators (Each operation should be done on numbers negative(-) to positive(+), positive(+) to negative(-), negative(-) to negative(-), and positive(+)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT