I am in need of a Java program that integrates MySQL into it ASAP: Purpose: Buil
ID: 3705411 • Letter: I
Question
I am in need of a Java program that integrates MySQL into it ASAP:
Purpose: Build an application to calculate an Employee’s Gross Pay.
Problem: Build an application that would allow a person to calculate an Employee’s Gross Pay. The person will enter the employee’s name, regular hours worked, overtime hours worked and hourly pay rate. The program then calculates and displays the employee’s name and Gross Pay (see both inputs and outputs listed in the tables below).
Assumptions: Gross Pay = (Regular hours* pay rate) + (Over Time hours * pay rate *1.5) Regular hours are less than or equal to 40
Languages: Java, JDBC, MySQL
Steps:
1) Create Employee Table in MySQL
2) Insert Data into Employee table (See Table #1 for Input data)
3) Read Data from Employee table and process in Java
4) Create in java a report (either on screen or in a file ie. Report.txt)
Data Requirements Fields Data-T Employee Info First Name: Last Name: Hours Worked Pay Rate Strin Strin Double Cu or Double Processes Process Data to calculate Gross Pay Output (See Table #3 for output) Advanced Insert data using java code Table I TOE Chart Task Obiect Event Get the following information from the user xtID None Student's ID Close window cmdClose ClickExplanation / Answer
1. Create SQL Table
create table tablename(
firstname VARCHAR(15) NOT NULL,
lastname VARCHAR(15),
hoursworked DOUBLE,
payrate DOUBLE
);
2. Inserting Values
INSERT into tablename values('Smith','Seth',55.5,12.50);
3. Java Program
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
Double regularPay;
Double otPay;
Double grossPay;
Double otHours;
Double payOut=(double) 0;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/databasename","username","password");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from tablename");
System.out.println("Name Hours OT PayRate RegularPay OtPay GrossPay");
while(rs.next()) {
String name = rs.getString(1)+" "+rs.getString(2);
Double hours = rs.getDouble(3);
Double payRate = rs.getDouble(4);
if(hours >40) {
regularPay = (double) 40;
otHours = hours-40;
otPay = otHours * payRate;
grossPay = (40*payRate) + (otHours * payRate * 1.5);
}
else {
otHours = (double) 0;
regularPay = hours * payRate;
otPay = (double) 0;
grossPay = regularPay;
}
payOut = payOut + grossPay;
System.out.println(name+" "+hours+" "+otHours+" $"+payRate+" $"+regularPay+" $"+otPay+" $"+grossPay);
}
System.out.println("Department Total");
System.out.println("Payout "+payOut);
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
4. Report
Name Hours OT PayRate RegularPay OtPay GrossPay
SmithSeth 55.5 15.5 12.50 $500.00 $193.75 $790.62
Department Total
Payout $790.62
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.