Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is java. problem. i already make employee class. but i can not make employe

ID: 3787838 • Letter: T

Question

this is java. problem.

i already make employee class. but i can not make employeetester class. i want to know Employeetester class.

EmployeeTester class:

Write a main method that produces a dialog like this:

-->Enter a name : dave

-->Enter hours worked (7 values separated by spaces): 5 2 1 0 0 3 3

Output: dave worked for 5 day(s) for a total of 14.0 hours.

-->Enter a day of the week (0-6): 2

Output: Hours worked on day 2 is 1.0

************and this is my employee class.**********************

public class Employee {
   private double[] hours=new double[7];
   private String name;
  
   public Employee(String name){
   this.name=name;
   }
   public double getHours(int day){
   return hours[day];
   }
   public void setHours(int day,double hrs){
   hours[day]=hrs;
   }
   public int numDaysWorked(){
   int totalD=0;
   for(int i=0;i<7;i++){
   if(hours[i]==0.0){
  
   }else{
   totalD=totalD+1;
   }
   }
   return totalD;
   }
   public double totalHours(){
   double totalH=0;
   for(int i=0;i<7;i++){
   if(hours[i]==0.0){
  
   }else{
   totalH=totalH+hours[i];
   }
   }
   return totalH;
   }
   public String toString(){
   return name+" Worked " +numDaysWorked() + " day(s) for a total of "+totalHours() + "hours .";
   }
}

Explanation / Answer

Note:

I have made some changes to the Employee class which have provided to meet the required output.Thank You.

________________________

Employee.java

public class Employee {
   //Creating an double type array of size 7
private double[] hours=new double[7];
//Declaring variable
private String name;

//Parameterized constructor
public Employee(double[] hours, String name) {
       super();
       this.hours = hours;
       this.name = name;
   }
  
//Setters and getters
public double[] getHours() {
       return hours;
   }


   public void setHours(double[] hours) {
       this.hours = hours;
   }


   public String getName() {
       return name;
   }


   public void setName(String name) {
       this.name = name;
   }


   //This method will calculate the no of days worked by an employee
   public int numDaysWorked(){
int totalD=0;
for(int i=0;i<7;i++){
if(hours[i]!=0.0){
totalD=totalD+1;
}
}
return totalD;
}
  
   //This method will return the total no of hours worked by an employee
public double totalHours(){
double totalH=0;
for(int i=0;i<7;i++){
   //Calculating the total hours worked
totalH=totalH+hours[i];
}

return totalH;
}
  
//this method will return the hours worked on particular day of an employee
public double hoursWorkedOnParticularday(int day)
{
   return hours[day];
}
  
//this method will display the contents of an object inside it
public String toString(){
return name+" Worked " +numDaysWorked() + " day(s) for a total of "+totalHours() + " hours .";
}
}

____________________

EmployeeTester.java

import java.util.Scanner;

public class EmployeeTester {

   public static void main(String[] args) {
      
       //Declaring variables
String name;
double tot_hours=0;
int no_of_days_worked=0;
int week_day=0;
  
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //Creating an double type array of size 7
       double hours[]=new double[7];
      
       //getting the name of an employee entered by the user
       System.out.print("Enter a name : ");
       name=sc.next();
      
       /* Getting the no of hours worked on each day by
       * an employee and populating those values into an array
       */
       System.out.print("Enter hours worked (7 values separated by spaces):");
       for(int i=0;i<7;i++)
       {
           hours[i]=sc.nextDouble();
       }
      
       //creating an Employee class object by passing the inputs values as arguments
       Employee emp=new Employee(hours, name);
      
       //calling the methods on the Employee clas object
       tot_hours=emp.totalHours();
       no_of_days_worked=emp.numDaysWorked();
  
       System.out.println(emp.toString());
      
       //getting the day of the week value entered by the user
       System.out.print("Enter a day of the week (0-6):");
       week_day=sc.nextInt();
      
       //Displaying the result
       System.out.println("Hours worked on day "+week_day+" is "+emp.hoursWorkedOnParticularday(week_day));

   }

}

_____________________

output:

Enter a name : dave
Enter hours worked (7 values separated by spaces):5 2 1 0 0 3 3
dave Worked 5 day(s) for a total of 14.0 hours
.
Enter a day of the week (0-6):2
Hours worked on day 2 is 1.0

_____________Thank You