Assume two arrays, one of student records, the other of employee records. Each s
ID: 441429 • Letter: A
Question
Assume two arrays, one of student records, the other of employee records. Each student record contains for a last name, first name, and grade index. Each employee record contains members for a last name, first name and salary. Both arrays are ordered in alphabetical order by last name and first name. Two records with the same last name/ first name do not appear in the same array. a.write a java method to five a 10 percent raise to every employee who has a student record and whose grade point index is higher than 3.0. b. Write a method as in the preceding exercise, but assume that the employee and student records are kept in a vector rather than two ordered arrays. Part B is WHAT I CARE ABOUT THE MOST...YOU DON'T HAVE TO DO PART A. IT MUST BE IN JAVAExplanation / Answer
I have written the complete code and is working fine in eclipse.
I have used Three classes named Employee Student and RaiseSalary.
Sample output is also given below. Hope this will help you
---------------------------
RaiseSalary class
----------------------------
import java.util.Scanner;
import java.util.Vector;
public class RaiseSalary {
Vector employeeList=new Vector();
Vector studentList=new Vector();
Scanner scan=new Scanner(System.in);
public void getEmployee()
{
String firstName;
String lastName;
Double salary;
//lets take input for 5 employee
for(int i=0;i<5;i++)
{
System.out.println("enter details of "+i+1+"employee");
System.out.println("first name ?");
firstName=scan.nextLine();
System.out.println("last name ?");
lastName=scan.nextLine();
System.out.println("salary ?");
salary=Double.parseDouble(scan.nextLine());
employeeList.addElement(new Employee(firstName,lastName,salary));
}
}
public void getStudent()
{
String firstName;
String lastName;
Double grade;
//lets take input for 5 employee
for(int i=0;i<5;i++)
{
System.out.println("enter details of "+i+1+"student");
System.out.println("first name ?");
firstName=scan.nextLine();
System.out.println("last name ?");
lastName=scan.nextLine();
System.out.println("grade ?");
grade=Double.parseDouble(scan.nextLine());
studentList.addElement(new Student(firstName,lastName,grade));
}
}
public void raiseSalary()
{
System.out.println("Initial name and Salary of employee:");
for(int i=0;i
{
Employee emp=new Employee();
emp=employeeList.get(i);
System.out.println(emp.getFirstName()+" "+emp.getSalary() );
}
//...........raising salary.............
Employee tempEmp=new Employee();
Student tempStudent=new Student();
for(int i=0;i
{
tempEmp=employeeList.get(i);
for(int j=0;j
{
tempStudent=studentList.get(j);
if(tempEmp.getFirstName().equals(tempStudent.getFirstName())&& tempEmp.getLastName().equals(tempStudent.getLastName()) && tempStudent.grade>3.0)
{
tempEmp.setSalary(1.1*tempEmp.getSalary());
employeeList.remove(i);
employeeList.add(i,tempEmp);
}
}
}
//............................
System.out.println("After Raise,name and Salary of employee:");
for(int i=0;i
{
Employee emp=new Employee();
emp=employeeList.get(i);
System.out.println(emp.getFirstName()+" "+emp.getSalary() );
}
}
public static void main(String[] args)
{
RaiseSalary raiseSalary=new RaiseSalary();
raiseSalary.getEmployee();
raiseSalary.getStudent();
raiseSalary.raiseSalary();
}
}
---------------------------------
Employee Class
------------------------------
public class Employee {
String firstName;
String lastName;
Double Salary;
public Employee() {
super();
}
public Employee(String firstName, String lastName, Double salary) {
super();
this.firstName = firstName;
this.lastName = lastName;
Salary = salary;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Double getSalary() {
return Salary;
}
public void setSalary(Double salary) {
Salary = salary;
}
}
-------------------------------
Student class
----------------------------
public class Student {
String firstName;
String lastName;
Double grade;
public Student() {
super();
}
public Student(String firstName, String lastName, Double grade) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.grade = grade;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Double getGrade() {
return grade;
}
public void setGrade(Double grade) {
this.grade = grade;
}
}
---------------------------------
sample output
----------------------------
enter details of 01employee
first name ?
amit
last name ?
kumar
salary ?
2000
enter details of 11employee
first name ?
vivek
last name ?
kumar
salary ?
4000
enter details of 01student
first name ?
amit
last name ?
kumar
grade ?
4
enter details of 11student
first name ?
vivek
last name ?
kumar
grade ?
2
Initial name and Salary of employee:
amit 2000.0
vivek 4000.0
After Raise,name and Salary of employee:
amit 2200.0
vivek 4000.0