Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. /*
  2. Name:Tommy Dong
  3. Program: Lab5
  4. Description:Get wage
  5. Date: 9/29/2016
  6. */
  7. import javax.swing.JOptionPane;
  8.  
  9. public class Lab5{
  10. public static void main(String[] argv){
  11. float hour= stringInt(JOptionPane.showInputDialog("How many hours do you work?"));
  12. float wage= stringInt(JOptionPane.showInputDialog("What is your hourly wage?"));
  13. if(hour==-1||wage==-1){
  14. JOptionPane.showMessageDialog(null,"You did not type a valid input","error",0);
  15. }
  16. else{
  17. float overtime=0,regular,total;
  18. String Message;
  19. if(hour>=40){
  20. regular=40*wage;
  21. overtime=(hour-40)*(float)(wage*1.5);
  22. }
  23. else{
  24. regular=hour*wage;
  25. }
  26. total=overtime+regular;
  27. Message="Regular:"+roundShort(regular);
  28. if(overtime>0){
  29. Message+="\nOvertime:"+roundShort(overtime);
  30. }
  31. Message+="\nTotal:"+roundShort(total);
  32. JOptionPane.showMessageDialog(null,Message,"Result",0);
  33. }
  34. System.exit(0);
  35. }
  36.  
  37. public static float stringInt(String num){
  38. float number;
  39. try{
  40. number=Float.parseFloat(num);
  41. }
  42. catch(Exception e){
  43. number=-1;
  44. }
  45. return number;
  46. }
  47. public static String roundShort(float num){
  48. String numstring=""+num;
  49. if(numstring.indexOf('.')!=-1){
  50. if(numstring.length()>numstring.indexOf('.')+3){
  51. numstring+="00";
  52. }
  53. return numstring.substring(0,numstring.indexOf('.')+3);
  54. }
  55. else{
  56. return numstring;
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement