Question: Modify the assignment 3 (Classes) program to include the following elements. In the main program add a function that: Creates an Employee Class object Prompts
Modify the assignment 3 (Classes) program to include the following elements.
- In the main program add a function that:
- Creates an Employee Class object
- Prompts the user for data and use this data to set the object properties (name, Employee ID, hourly rate, hours worked)
- Return the Employee object to the main program.
- Call the Employee object method to return total pay
- Print out the total pay value to the screen.
Code:
import java.util.*;
class employee { String firstname; String lastname; int employeeID; Float hourlypay; Float hoursworked;
void Set() { Scanner ob=new Scanner(System.in); System.out.println("Enter Employee First Name :"); firstname=ob.nextLine(); System.out.println("Enter Employee Last Name :"); lastname=ob.nextLine(); System.out.println("Enter Employee ID:"); employeeID=ob.nextInt(); System.out.println("Enter Amount Paid Per Hour:"); hourlypay=ob.nextFloat(); System.out.println("Enter Hours Worked:"); hoursworked=ob.nextFloat(); }
void Get() { Float Total_pay=(hourlypay)*(hoursworked); System.out.println("Total Pay :"+Total_pay); } }
class main { public static void main(String [] args) { employee s1=new employee(); s1.Set(); s1.Get(); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
