Calculate Pay Program:
This program is implemented by Java. Which will be using Object Oriented Programming concepts. Like Object, Class, Encapsulation, Abstraction. These concepts are implemented in this program.
Other than these concepts some more are there Like Inheritance, Polymorphism.
Object:
A real-world entity is called an Object. An object will have State and behaviour. In programming, the state is nothing, but properties and behaviour is nothing but methods.
This can be defined as an instance of a class. So, each object will be having an address and it required memory to store the object. If you want to access any class in java then we need to create an object first.
Example:
A mobile phone is an object. And its states are ram, us, display, processor, camera, etc. And its behaviours are you can call, chat, take photos, watching videos.
In the Calculate Pay Program “CalculationDisplay.java” is a real-world entity. Which will be having States are input and output properties, behaviours are getting those properties values.
Class:
A Class in java will be called a template or blueprint from this you can create the object. A class can contain objects. This will have variables and methods.
Syntax:
Class {
}
In this program, I have created many classes like CalculatePay.java, CalculationDisplay.java, CalculationService.java, GetFromFile.java, etc.
Encapsulation:
This is nothing but wrapping up data and code together into a single unit.
The normal java class is an example of this. A class will be wrapping data(properties) and code (Methods). Java Bean class is called a fully encapsulated class.
Here data would be private using public members we can access the data.
In This program, I have created a class name called “CalculationDisplay.java” which is a bean class. And this is an example of Encapsulation.
Abstractions:
This is nothing but hiding the internal implementation of a process. Just using that functionality. Here you don't need to know how they implemented that functionality just uses it. In java, we can achieve abstraction 2 ways as follows
1. Using Abstract class – Partially abstracted. (Method declaration and definition will be there)
2. Using Interfaces – Fully abstracted (Only Method declaration)
Both should be implemented by other concrete classes. We cannot create an object for those.
In This program, I have used an interface for creating some constants. “PayValues.java”.
Source Code:
1) CalculatePay.java
package com.pay.app;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import com.pay.app.bean.CalculationDisplay;
import com.pay.app.service.CalculationService;
import com.pay.app.util.GetFromFile;
/**
*
* @author Mel Weaver
* @CourseName CPT 307 Data Structures & Algorithms (INE2206A)
* @InstructorName Michael Hayden
* @DateSubmited February 8, 2022
*/
public class CalculatePay {
static CalculationService service = new CalculationService();
//Need to run this main method to execute this application
public static void main(String[] args) {
System.out.println("--------------Welcome to calculate pay application----------");
GetFromFile getFromFile = new GetFromFile();
CalculationDisplay display = new CalculationDisplay();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
while(true) {
System.out.println("You can give input in following ways:");
System.out.println("1 -> Enter Manually");
System.out.println("2 -> Read from file");
System.out.println("3 -> Exit");
String inputData = reader.readLine();
if("1".equals(inputData)) {
System.out.println("Please enter employee name:");
display = new...