জাভা প্রোগ্রামিং পর্ব-০৯



2.11* (Financial application: payroll) Write a program that reads the following information
and prints a payroll statement:
Employee’s name (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 6.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)
Write this program in two versions: (a) Use dialog boxes to obtain input and display
output; (b) Use console input and output.

Code : (a) File name-Payroll2.java
import java.util.*;
import javax.swing.*;
public class Payroll2 {
    public static void main (String arg[]){
        String hours =JOptionPane.showInputDialog("Enter hours: ");
        double hour=Double.parseDouble(hours);
        String rates =JOptionPane.showInputDialog("Enter rate: ");
        double rate=Double.parseDouble(rates);
        String fts =JOptionPane.showInputDialog("Enter fedaral tax: ");
        double ft=Double.parseDouble(fts);
        String sts =JOptionPane.showInputDialog("Enter state tax: ");
        double st=Double.parseDouble(sts);

        double totalPay=hour*rate;
        double federaltax = (totalPay*ft)/100;
        double statetax = (totalPay*st)/100;
        double deduc =(federaltax+statetax);
        double net=(totalPay-deduc);

        String output = "Worked hours: = " + hour+"\nPay rate: =$ " + rate +"\nFederal tax: =$ " +federaltax+"\nState tax: =$ "+statetax+ "\nTotal deduction: =$ "+deduc +"\nNet pay: =$ " +net;
        JOptionPane.showMessageDialog(null, output);
        }
    }

Code : (b) File name-Payroll.java
import java.util.*;
import javax.swing.*;
public class Payroll {
    public static void main (String arg[]){
        Scanner input= new Scanner (System.in);
        System.out.print("Enter employee name: = ");
        String name=input.nextLine();
        System.out.print("Number of hours worked in a week: = ");
        double hours= input.nextDouble();
        System.out.print("Hourly rate: = ");
        double rate =input.nextDouble();
        System.out.print("Federal tax: = ");
        double ft =input.nextDouble();
        System.out.print("State tax: = ");
        double st =input.nextDouble();

        double totalpay=hours*rate;
         ft=((totalpay*ft)/100);
         st=((totalpay*st)/100);
        double detuction =ft+st;
        double pay=(totalpay-(detuction));
        System.out.println("Description belue:");
        System.out.println("Employee Name=" + name);
        System.out.println("Hours Worked=" + hours);
        System.out.println("Pay Rate=$" + rate);
        System.out.println("Federal tax=$" + ft);
        System.out.println("State tax=$" + st);
        System.out.println("State detuction=$" + detuction);
        System.out.println("Net pay=$" + pay);
        }
    }

Loading
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Flying Twitter Bird Widget By ICT Sparkle