🔒 Closed Looking

Status
Not open for further replies.
import java.util.Scanner;
002
003
004 public class Payroll {
005
006 public static void main(String[] args) {
007 Scanner input = new Scanner ( System.in );
008 double hourlyRate;
009 double hoursWorked;
010 double grossPay; // Calculated weekly pay before taxes
011 double taxDeduction; // gross pay * 14%
012 double netPay; // Calculated weekly pay after taxes
013
014 System.out.print("Employee name: ");
015 String employeeName = input.nextLine();
016
017 System.out.printf("Enter hourly rate for %s: $", employeeName);
018 hourlyRate = input.nextDouble();
019
020 while(hourlyRate < 0.00){
021 System.out.print("Please enter only a positive number: $");
022 hourlyRate = input.nextDouble();
023 }
024
025 System.out.printf("total hours worked: ");
026 hoursWorked = input.nextDouble();
027
028 while (hoursWorked < 0.00){
029 System.out.print("Please enter only a positive number: ");
030 hoursWorked = input.nextDouble();
031 }
032
033 grossPay = hourlyRate * hoursWorked;
034 System.out.printf("gross pay: $%.2f\n", grossPay);
035 System.out.println();
036
037 taxDeduction = grossPay * .14;
038 System.out.printf("federal taxes: $%.2f\n", taxDeduction);
039 System.out.println();
040
041 netPay = grossPay - taxDeduction;
042 System.out.printf("net pay: $%.2f\n", netPay);
043 System.out.println();
044
045
046 input.nextLine();
047 System.out.print("Employee name:"); // Loops back to start
048 employeeName = input.nextLine();
049
050 }
051 }
Code:
052  
053 the second variation is where i am having trouble i need to incorperate a overtime calculation into it which i was able to do but now it is not calculating any taxes being with held... the code is as follows....
054 [code] import java.util.Scanner; // import delcaration for program to use class Scanner
055  import java.text.NumberFormat;
056  import java.text.DecimalFormat;
057  import java.util.Scanner;
058   public class payrollattempt
059  {
060      // main method begins execution of Java application
061      public static void main( String args[] )
062      {
063          Scanner input = new Scanner( System.in ); // create Scanner to obtain input from the command window
064    
065          boolean stop = false;
066    
067          String cleanInputBuffer; // input
068          String getName;
069          double hoursWorked; // variable for the employee's hours worked
070          double hourlyRate;  // variable for the employee's hourly rate
071          double grossPay; // Calculated weekly pay before taxes
072          double taxDeduction; // gross pay * 14%
073          double netPay; // Calculated weekly pay after taxes
074          double overTime;
075    
076          while(stop== false)
077          {
078    
079          System.out.print("Enter employees Name or 'quit' to exit: "); // prompt
080          getName = input.nextLine(); // read employee's name
081              if(getName.equalsIgnoreCase ( "quit" ) ) // condition statement to request data until stop is entered
082              {
083              System.out.print("Exiting Payroll Program. "); // prompt
084              stop = true;
085              }
086    
087                  else
088                  {
089                      System.out.print("Enter Hourly Rate: ");
090                      hourlyRate = input.nextDouble(); // read hourly rate
091    
092                          while ( hourlyRate < 0 ) // condition statement to check for negative number
093                          {
094    
095                              System.out.print("Enter the hourly rate of pay for the employee: "); // prompt
096                              hourlyRate = input.nextDouble(); // read hourly rate
097                          } // end while
098    
099              System.out.print("Enter the hours worked by employee this week: "); // prompt
100              hoursWorked = input.nextDouble(); // read hours worked
101    
102                  while ( hoursWorked < 0 ) // condition statement to check for negative number
103                  {
104                      System.out.println("Error: You have entered a negative number!"); // error message
105                      System.out.print("Enter the hours worked by employee this week: "); // prompt
106                      hoursWorked = input.nextDouble(); // read hours worked
107                  } // end while
108          if (hoursWorked > 40)// Overtime
109    
110          {
111    
112          grossPay = hoursWorked * hourlyRate;//multiplication
113          overTime = (hoursWorked-40) * (hourlyRate*1.5);
114  
115          taxDeduction = grossPay * .14;
116          System.out.printf("federal taxes: $%.2f\n", taxDeduction);
117          System.out.println();
118          
119          netPay = grossPay - taxDeduction;
120          System.out.printf("net pay: $%.2f\n", netPay);
121          System.out.println();
122    
123          System.out.println("Employee:" + getName);
124          System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
125          System.out.println("Regular Hours worked:" + "40");
126          System.out.println("Overtime Hours worked:" + (hoursWorked-40));
127          System.out.printf("Total Pay: $%.2f\n", netPay);
128          System.out.printf("Overtime Pay: $%.2f\n", overTime);
129          System.out.printf("Gross Pay: $%.2f\n", netPay+overTime);
130          }
131              else                // Under 40 Hours
132              {
133              netPay = hoursWorked * hourlyRate;
134              System.out.println("Employee:" + getName);
135              System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
136              System.out.println("Regular Hours worked:" + hoursWorked);
137              System.out.printf("Gross Pay: $%.2f\n", netPay);
138              }
139    
140              System.out.printf( "Enter employee name or 'quit' to exit:");
141              getName = input.next();
142    
143              cleanInputBuffer = input.nextLine();
144    
145    
146              }
147          }
148    
149    
150      } // end method main
151    
152  } // end class Part2
 
import java.util.Scanner;
002
003
004 public class Payroll {
005
006 public static void main(String[] args) {
007 Scanner input = new Scanner ( System.in );
008 double hourlyRate;
009 double hoursWorked;
010 double grossPay; // Calculated weekly pay before taxes
011 double taxDeduction; // gross pay * 14%
012 double netPay; // Calculated weekly pay after taxes
013
014 System.out.print("Employee name: ");
015 String employeeName = input.nextLine();
016
017 System.out.printf("Enter hourly rate for %s: $", employeeName);
018 hourlyRate = input.nextDouble();
019
020 while(hourlyRate < 0.00){
021 System.out.print("Please enter only a positive number: $");
022 hourlyRate = input.nextDouble();
023 }
024
025 System.out.printf("total hours worked: ");
026 hoursWorked = input.nextDouble();
027
028 while (hoursWorked < 0.00){
029 System.out.print("Please enter only a positive number: ");
030 hoursWorked = input.nextDouble();
031 }
032
033 grossPay = hourlyRate * hoursWorked;
034 System.out.printf("gross pay: $%.2f\n", grossPay);
035 System.out.println();
036
037 taxDeduction = grossPay * .14;
038 System.out.printf("federal taxes: $%.2f\n", taxDeduction);
039 System.out.println();
040
041 netPay = grossPay - taxDeduction;
042 System.out.printf("net pay: $%.2f\n", netPay);
043 System.out.println();
044
045
046 input.nextLine();
047 System.out.print("Employee name:"); // Loops back to start
048 employeeName = input.nextLine();
049
050 }
051 }
Code:
052 
053 the second variation is where i am having trouble i need to incorperate a overtime calculation into it which i was able to do but now it is not calculating any taxes being with held... the code is as follows....
054 [code] import java.util.Scanner; // import delcaration for program to use class Scanner
055  import java.text.NumberFormat;
056  import java.text.DecimalFormat;
057  import java.util.Scanner;
058   public class payrollattempt
059  {
060      // main method begins execution of Java application
061      public static void main( String args[] )
062      {
063          Scanner input = new Scanner( System.in ); // create Scanner to obtain input from the command window
064   
065          boolean stop = false;
066   
067          String cleanInputBuffer; // input
068          String getName;
069          double hoursWorked; // variable for the employee's hours worked
070          double hourlyRate;  // variable for the employee's hourly rate
071          double grossPay; // Calculated weekly pay before taxes
072          double taxDeduction; // gross pay * 14%
073          double netPay; // Calculated weekly pay after taxes
074          double overTime;
075   
076          while(stop== false)
077          {
078   
079          System.out.print("Enter employees Name or 'quit' to exit: "); // prompt
080          getName = input.nextLine(); // read employee's name
081              if(getName.equalsIgnoreCase ( "quit" ) ) // condition statement to request data until stop is entered
082              {
083              System.out.print("Exiting Payroll Program. "); // prompt
084              stop = true;
085              }
086   
087                  else
088                  {
089                      System.out.print("Enter Hourly Rate: ");
090                      hourlyRate = input.nextDouble(); // read hourly rate
091   
092                          while ( hourlyRate < 0 ) // condition statement to check for negative number
093                          {
094   
095                              System.out.print("Enter the hourly rate of pay for the employee: "); // prompt
096                              hourlyRate = input.nextDouble(); // read hourly rate
097                          } // end while
098   
099              System.out.print("Enter the hours worked by employee this week: "); // prompt
100              hoursWorked = input.nextDouble(); // read hours worked
101   
102                  while ( hoursWorked < 0 ) // condition statement to check for negative number
103                  {
104                      System.out.println("Error: You have entered a negative number!"); // error message
105                      System.out.print("Enter the hours worked by employee this week: "); // prompt
106                      hoursWorked = input.nextDouble(); // read hours worked
107                  } // end while
108          if (hoursWorked > 40)// Overtime
109   
110          {
111   
112          grossPay = hoursWorked * hourlyRate;//multiplication
113          overTime = (hoursWorked-40) * (hourlyRate*1.5);
114 
115          taxDeduction = grossPay * .14;
116          System.out.printf("federal taxes: $%.2f\n", taxDeduction);
117          System.out.println();
118         
119          netPay = grossPay - taxDeduction;
120          System.out.printf("net pay: $%.2f\n", netPay);
121          System.out.println();
122   
123          System.out.println("Employee:" + getName);
124          System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
125          System.out.println("Regular Hours worked:" + "40");
126          System.out.println("Overtime Hours worked:" + (hoursWorked-40));
127          System.out.printf("Total Pay: $%.2f\n", netPay);
128          System.out.printf("Overtime Pay: $%.2f\n", overTime);
129          System.out.printf("Gross Pay: $%.2f\n", netPay+overTime);
130          }
131              else                // Under 40 Hours
132              {
133              netPay = hoursWorked * hourlyRate;
134              System.out.println("Employee:" + getName);
135              System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
136              System.out.println("Regular Hours worked:" + hoursWorked);
137              System.out.printf("Gross Pay: $%.2f\n", netPay);
138              }
139   
140              System.out.printf( "Enter employee name or 'quit' to exit:");
141              getName = input.next();
142   
143              cleanInputBuffer = input.nextLine();
144   
145   
146              }
147          }
148   
149   
150      } // end method main
151   
152  } // end class Part2
Marunong ka nmn pla eh. Create ka ng app? O mod lng?
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 12
    Replies
  • 587
    Views
  • 2
    Participants
Last reply from:
ken russh

Trending Topics

Online now

Members online
1,007
Guests online
1,257
Total visitors
2,264

Forum statistics

Threads
2,271,492
Posts
28,935,904
Members
1,238,639
Latest member
jaycel
Back
Top