93 lines
6.8 KiB
HTML
93 lines
6.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>payroll.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
|
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
|
|
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.ST0 {color: #287bde}
|
|
.literal {color: #cc7832}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/NetBeansProjects/ADSV Java/lab4_CalebFontenot/src/main/java/com/calebfontenot/lab4_calebfontenot/payroll.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> com.calebfontenot.lab4_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.text.DecimalFormat;
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> payroll {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
|
|
{
|
|
<span class="comment">// Create Scanner</span>
|
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST3">in</span>);
|
|
|
|
<span class="comment">// Define vars</span>
|
|
String employeeName;
|
|
<span class="literal">double</span> hoursWorked;
|
|
<span class="literal">double</span> hourlyPayRate;
|
|
<span class="literal">double</span> federalTaxWithholdingRate;
|
|
<span class="literal">double</span> stateTaxWithholdingRate;
|
|
<span class="literal">double</span> grossPay;
|
|
<span class="literal">double</span> federalWithholding;
|
|
<span class="literal">double</span> stateWithholding;
|
|
<span class="literal">double</span> totalDeduction;
|
|
|
|
<span class="comment">// Prompt for input</span>
|
|
System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter employee's name: </span><span class="string">"</span>);
|
|
employeeName = input.next();
|
|
System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter the number of hours worked in a week: </span><span class="string">"</span>);
|
|
hoursWorked = input.nextDouble();
|
|
System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter the hourly pay rate: $</span><span class="string">"</span>);
|
|
hourlyPayRate = input.nextDouble();
|
|
System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter the federal tax witholding rate (as a decimal, please!): </span><span class="string">"</span>);
|
|
federalTaxWithholdingRate = input.nextDouble();
|
|
System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter the state tax withholding rate (as a decimal, please!): </span><span class="string">"</span>);
|
|
stateTaxWithholdingRate = input.nextDouble();
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">"</span>); <span class="comment">//empty space</span>
|
|
|
|
<span class="comment">// Setup Decimal fomatting</span>
|
|
DecimalFormat df = <span class="literal">new</span> DecimalFormat(<span class="string">"</span><span class="string">#0.00</span><span class="string">"</span>);
|
|
|
|
<span class="comment">// Calculate</span>
|
|
grossPay = (hoursWorked * hourlyPayRate);
|
|
federalWithholding = (grossPay * federalTaxWithholdingRate);
|
|
stateWithholding = (grossPay * stateTaxWithholdingRate);
|
|
totalDeduction = (grossPay - (federalWithholding + stateWithholding));
|
|
|
|
<span class="comment">// Print output</span>
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Employee Name: </span><span class="string">"</span>+employeeName);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Hours Worked: </span><span class="string">"</span>+hoursWorked);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Pay Rate: $</span><span class="string">"</span>+ df.format(hourlyPayRate));
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Gross Pay: $</span><span class="string">"</span>+df.format(grossPay));
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Deductions:</span><span class="string">"</span>);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="literal">\t</span><span class="string">"</span>+<span class="string">"</span><span class="string">Federal Withholding (</span><span class="string">"</span>+ (federalTaxWithholdingRate * <span class="number">100.0</span>)+<span class="string">"</span><span class="string">%):$</span><span class="string">"</span>+df.format(federalWithholding));
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="literal">\t</span><span class="string">"</span>+<span class="string">"</span><span class="string">State Withholding (</span><span class="string">"</span>+ (stateTaxWithholdingRate * <span class="number">100.0</span>)+<span class="string">"</span><span class="string">%):$</span><span class="string">"</span>+df.format(stateWithholding));
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">Total Deduction: $</span><span class="string">"</span>+df.format(totalDeduction));
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|