Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name:Tommy Dong
- Program: Lab5
- Description:Get wage
- Date: 9/29/2016
- */
- import javax.swing.JOptionPane;
- public class Lab5{
- public static void main(String[] argv){
- float hour= stringInt(JOptionPane.showInputDialog("How many hours do you work?"));
- float wage= stringInt(JOptionPane.showInputDialog("What is your hourly wage?"));
- if(hour==-1||wage==-1){
- JOptionPane.showMessageDialog(null,"You did not type a valid input","error",0);
- }
- else{
- float overtime=0,regular,total;
- String Message;
- if(hour>=40){
- regular=40*wage;
- overtime=(hour-40)*(float)(wage*1.5);
- }
- else{
- regular=hour*wage;
- }
- total=overtime+regular;
- Message="Regular:"+roundShort(regular);
- if(overtime>0){
- Message+="\nOvertime:"+roundShort(overtime);
- }
- Message+="\nTotal:"+roundShort(total);
- JOptionPane.showMessageDialog(null,Message,"Result",0);
- }
- System.exit(0);
- }
- public static float stringInt(String num){
- float number;
- try{
- number=Float.parseFloat(num);
- }
- catch(Exception e){
- number=-1;
- }
- return number;
- }
- public static String roundShort(float num){
- String numstring=""+num;
- if(numstring.indexOf('.')!=-1){
- if(numstring.length()>numstring.indexOf('.')+3){
- numstring+="00";
- }
- return numstring.substring(0,numstring.indexOf('.')+3);
- }
- else{
- return numstring;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement