Engineeringserver.com

A community for computer science students & developers about software development, game development, game design, games, anime preview & reviews and more!


Employee class , get the weekly salary

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.5 out of 5)
Loading ... Loading ...
417 views

A small application I wrote for someone to calculate a salary.

JAVA:
  1. import java.util.InputMismatchException;
  2. import java.util.Scanner;
  3. public class Employee {
  4. static double hourlyRate = 0.0;
  5. static double hoursWorked = 0.0;
  6. public static void main(String[] args){
  7. Scanner sc = new Scanner(System.in);
  8. try{
  9. System.out.print("Employee name: ");
  10. String name  = sc.nextLine();
  11. System.out.print("Hourly rate $");
  12. hourlyRate = sc.nextDouble();
  13. System.out.print("Hour(s) worked: " );
  14. hoursWorked = sc.nextDouble();
  15. System.out.println("Employee " + name + " " + "with an hourly rate of $" + hourlyRate + " earned $" + getPay()
  16. + " by working " + hoursWorked + " hours a week.");
  17. }
  18. catch(InputMismatchException IMME){
  19. System.out.println("Input not correct!");
  20. }
  21. }
  22. public static double getPay(){
  23. double pay = hourlyRate * hoursWorked;
  24. return pay;
  25. }
  26. }

(more...)


Your Ad Here