Java Simple Console Application: Payroll Evaluation - 1 Week
Java Simple Console Application: Payroll Evaluation - 1 Week
Introduction
The primary type of application you can create with the Java language is a console or teminal application. In this exercise, we will have an introduction to Java by creating a simple small console or terminal application.
Java is a freely accessible computer language. You can download and install in your computer everything that is necessary to create application in Java.
There are various ways you can create a Java application, including the Command prompt or a terminal. You can also use a programming environment such as Eclipse (which is free). For our example, we will use Visual Studio Code (which also is free).
Practical Learning: Creating the Application
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); System.out.print("Payroll Evaluation\n"); System.out.print("----------------------------------------------\n"); System.out.print("Enter the following pieces of information\n"); System.out.print("----------------------------------------------\n"); System.out.print("Employee Information\n"); System.out.print("----------------------------------------------\n"); String firstName, lastName; System.out.print("First Name:\t\t"); firstName = scnr.next(); System.out.print("Last Name:\t\t"); lastName = scnr.next(); System.out.print("Hourly Salary:\t\t"); double hSalary = 0.00; hSalary = scnr.nextDouble(); System.out.print("----------------------------------------------"); System.out.print("\nTime worked"); System.out.print("\n---------------------------------------------"); System.out.print("\nMonday:\t\t\t"); double mon; mon = scnr.nextDouble(); System.out.print("Tuesday:\t\t"); double tue = scnr.nextDouble(); System.out.print("Wednesday:\t\t"); double wed = scnr.nextDouble(); System.out.print("Thursday:\t\t"); double thu = scnr.nextDouble(); System.out.print("Friday:\t\t\t"); double fri = scnr.nextDouble(); scnr.close(); double timeWorked = mon + tue + wed + thu + fri; double regTime = timeWorked; double regPay = hSalary * timeWorked; double overtime = 0.00; double overPay = 0.00; if(timeWorked > 40.00) { regTime = 40.00; regPay = hSalary * 40.00; overtime = timeWorked - 40.00; overPay = hSalary * 1.50 * overtime; } double netPay = regPay + overPay; System.out.print("\n=============================================="); System.out.print("\nPayroll Evaluation"); System.out.print("\n=============================================="); System.out.print("\nEmployee Information"); System.out.print("\n----------------------------------------------"); System.out.print("\nFull Name:\t\t"); System.out.print(firstName); System.out.print(" "); System.out.print(lastName); System.out.print("\nHourly Salary:\t\t"); System.out.print(hSalary); System.out.print("\n=============================================="); System.out.print("\nTime Worked Summary"); System.out.print("\n----------------------------------------------"); System.out.print("\n\tMonday:\t\t"); System.out.print(String.format("%.2f", (double)mon)); System.out.print("\n\tTuesday:\t"); System.out.print(String.format("%.2f", (double)tue)); System.out.print("\n\tWednesday:\t"); System.out.print(String.format("%.2f", (double)wed)); System.out.print("\n\tThursday:\t"); System.out.print(String.format("%.2f", (double)thu)); System.out.print("\n\tFriday:\t\t"); System.out.print(String.format("%.2f", (double)fri)); System.out.print("\n=============================================="); System.out.print("\nPay Summary"); System.out.print("\n----------------------------------------------"); System.out.print("\n\t\t\tTime\tPay"); System.out.print("\n----------------------------------------------"); System.out.print("\n\tRegular:\t"); System.out.print(String.format("%.2f", (double)regTime)); System.out.print("\t"); System.out.print(String.format("%.2f", (double)regPay)); System.out.print("\n----------------------------------------------"); System.out.print("\n\tOvertime:\t"); System.out.print(String.format("%.2f", (double)overtime)); System.out.print("\t"); System.out.print(String.format("%.2f", (double)overPay)); System.out.print("\n----------------------------------------------"); System.out.print("\n\t\tNet Pay:\t"); System.out.print(String.format("%.2f", (double)netPay)); System.out.print("\n=============================================="); } }
| First Name: | Michael |
| Last Name: | Carlock |
| Hourly Salary: | 28.25 |
| Monday | 7 |
| Tuesday: | 8 |
| Wednesday: | 6.5 |
| Thursday: | 8.5 |
| Friday: | 6.5 |
Payroll Evaluation
----------------------------------------------
Enter the following pieces of information
----------------------------------------------
Employee Information
----------------------------------------------
First Name: Michael
Last Name: Carlock
Hourly Salary: 28.46
----------------------------------------------
Time worked
---------------------------------------------
Monday: 7
Tuesday: 8
Wednesday: 6.5
Thursday: 8.5
Friday: 6.5
==============================================
Payroll Evaluation
==============================================
Employee Information
----------------------------------------------
Full Name: Michael Carlock
Hourly Salary: 28.46
==============================================
Time Worked Summary
----------------------------------------------
Monday: 7.00
Tuesday: 8.00
Wednesday: 6.50
Thursday: 8.50
Friday: 6.50
==============================================
Pay Summary
----------------------------------------------
Time Pay
----------------------------------------------
Regular: 36.50 1038.79
----------------------------------------------
Overtime: 0.00 0.00
----------------------------------------------
Net Pay: 1038.79
==============================================Using an Opposite Conditional Statement
In the previous section, we use a Greater Than operator to check a condition. That operator has an opposite, which is the Less Than Or Equal operator. We will uase apply as an example.
Practical Learning: Using an Opposite Conditional Statement
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
System.out.print("Payroll Evaluation\n");
System.out.print("----------------------------------------------\n");
System.out.print("Enter the following pieces of information\n");
System.out.print("----------------------------------------------\n");
System.out.print("Employee Information\n");
System.out.print("----------------------------------------------\n");
String firstName, lastName;
System.out.print("First Name:\t\t");
firstName = scnr.next();
System.out.print("Last Name:\t\t");
lastName = scnr.next();
System.out.print("Hourly Salary:\t\t");
double hSalary = 0.00;
hSalary = scnr.nextDouble();
System.out.print("----------------------------------------------");
System.out.print("\nTime worked");
System.out.print("\n---------------------------------------------");
System.out.print("\nMonday:\t\t\t");
double mon;
mon = scnr.nextDouble();
System.out.print("Tuesday:\t\t");
double tue = scnr.nextDouble();
System.out.print("Wednesday:\t\t");
double wed = scnr.nextDouble();
System.out.print("Thursday:\t\t");
double thu = scnr.nextDouble();
System.out.print("Friday:\t\t\t");
double fri = scnr.nextDouble();
scnr.close();
double timeWorked = mon + tue + wed + thu + fri;
double regTime = 40.00;
double regPay = hSalary * 40.00;
double overtime = timeWorked - 40.00;
double overPay = hSalary * 1.50 * overtime;
if(timeWorked <= 40.00)
{
regTime = timeWorked;
regPay = hSalary * timeWorked;
overtime = 0.00;
overPay = 0.00;
}
double netPay = regPay + overPay;
System.out.print("\n==============================================");
System.out.print("\nPayroll Evaluation");
System.out.print("\n==============================================");
System.out.print("\nEmployee Information");
System.out.print("\n----------------------------------------------");
System.out.print("\nFull Name:\t\t");
System.out.print(firstName);
System.out.print(" ");
System.out.print(lastName);
System.out.print("\nHourly Salary:\t\t");
System.out.print(hSalary);
System.out.print("\n==============================================");
System.out.print("\nTime Worked Summary");
System.out.print("\n----------------------------------------------");
System.out.print("\n\tMonday:\t\t");
System.out.print(String.format("%.2f", (double)mon));
System.out.print("\n\tTuesday:\t");
System.out.print(String.format("%.2f", (double)tue));
System.out.print("\n\tWednesday:\t");
System.out.print(String.format("%.2f", (double)wed));
System.out.print("\n\tThursday:\t");
System.out.print(String.format("%.2f", (double)thu));
System.out.print("\n\tFriday:\t\t");
System.out.print(String.format("%.2f", (double)fri));
System.out.print("\n==============================================");
System.out.print("\nPay Summary");
System.out.print("\n----------------------------------------------");
System.out.print("\n\t\t\tTime\tPay");
System.out.print("\n----------------------------------------------");
System.out.print("\n\tRegular:\t");
System.out.print(String.format("%.2f", (double)regTime));
System.out.print("\t");
System.out.print(String.format("%.2f", (double)regPay));
System.out.print("\n----------------------------------------------");
System.out.print("\n\tOvertime:\t");
System.out.print(String.format("%.2f", (double)overtime));
System.out.print("\t");
System.out.print(String.format("%.2f", (double)overPay));
System.out.print("\n----------------------------------------------");
System.out.print("\n\t\tNet Pay:\t");
System.out.print(String.format("%.2f", (double)netPay));
System.out.print("\n==============================================");
}
}| First Name: | Catherine |
| Last Name: | Busbey |
| Hourly Salary: | 24.37 |
| Monday | 9.50 |
| Tuesday: | 8 |
| Wednesday: | 10.50 |
| Thursday: | 9 |
| Friday: | 10.50 |
Payroll Evaluation
----------------------------------------------
Enter the following pieces of information
----------------------------------------------
Employee Information
----------------------------------------------
First Name: Catherine
Last Name: Busbey
Hourly Salary: 28.37
----------------------------------------------
Time worked
---------------------------------------------
Monday: 9.5
Tuesday: 8
Wednesday: 10.5
Thursday: 9
Friday: 10.5
==============================================
Payroll Evaluation
==============================================
Employee Information
----------------------------------------------
Full Name: Catherine Busbey
Hourly Salary: 28.37
==============================================
Time Worked Summary
----------------------------------------------
Monday: 9.50
Tuesday: 8.00
Wednesday: 10.50
Thursday: 9.00
Friday: 10.50
==============================================
Pay Summary
----------------------------------------------
Time Pay
----------------------------------------------
Regular: 40.00 1134.80
----------------------------------------------
Overtime: 7.50 319.16
----------------------------------------------
Net Pay: 1453.96
==============================================|
|
|||
| Home | Copyright © 2001-2026, FunctionX | Tuesday 14 October 2025, 12:24 | Home |
|
|
|||