SlideShare a Scribd company logo
1 of 6
Download to read offline
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 .";
}
}
Solution
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

More Related Content

Similar to this is java. problem.i already make employee class. but i can not.pdf

This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
aamousnowov
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
Mark Whitaker
 
In this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docxIn this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docx
jaggernaoma
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
marketing413921
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
anwarsadath111
 
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docxINTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
normanibarber20063
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
arasanmobiles
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
adithyaups
 

Similar to this is java. problem.i already make employee class. but i can not.pdf (20)

This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
C# for C++ programmers
C# for C++ programmersC# for C++ programmers
C# for C++ programmers
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
TDC2016SP - Trilha .NET
TDC2016SP - Trilha .NETTDC2016SP - Trilha .NET
TDC2016SP - Trilha .NET
 
Initial Java Core Concept
Initial Java Core ConceptInitial Java Core Concept
Initial Java Core Concept
 
In this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docxIn this assignment, you will continue working on your application..docx
In this assignment, you will continue working on your application..docx
 
source-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaisource-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawai
 
Military time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdfMilitary time and Standard time, JavaOne of the assignments given .pdf
Military time and Standard time, JavaOne of the assignments given .pdf
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
package employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdfpackage employeeType.employee;public class Employee {   private .pdf
package employeeType.employee;public class Employee {   private .pdf
 
Trace the following code to determine what will be outputted when Empl.pdf
Trace the following code to determine what will be outputted when Empl.pdfTrace the following code to determine what will be outputted when Empl.pdf
Trace the following code to determine what will be outputted when Empl.pdf
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptx
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docxINTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
INTERMIDIATE PROGRAMMINGCMPSC 122LAB 9 INHERITANCE AND POLYMO.docx
 
Thread
ThreadThread
Thread
 
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdfoperating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
operating system ubuntu,Linux,Macpublic class SuperMarket {   .pdf
 
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdfin C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 

More from PRATIKSINHA7304

A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdf
PRATIKSINHA7304
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
PRATIKSINHA7304
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdf
PRATIKSINHA7304
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdf
PRATIKSINHA7304
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
PRATIKSINHA7304
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdf
PRATIKSINHA7304
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
PRATIKSINHA7304
 

More from PRATIKSINHA7304 (20)

Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Find the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfFind the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdf
 
A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdf
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
 
1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf
 
[10 points]Add the.pdf
[10 points]Add the.pdf[10 points]Add the.pdf
[10 points]Add the.pdf
 
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
 
You are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfYou are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdf
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdf
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdf
 
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
 
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfWhat led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdf
 
What factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfWhat factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdf
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
 
This fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfThis fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdf
 
The term refers to a. Global Analysis of the proteins produced in .pdf
The term  refers to  a. Global Analysis of the proteins produced in .pdfThe term  refers to  a. Global Analysis of the proteins produced in .pdf
The term refers to a. Global Analysis of the proteins produced in .pdf
 
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdfThe inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
The inflation rate of Country Alpha in 2014 was 3.5. Due to their w.pdf
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 

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

  • 1. 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; }
  • 2. 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 ."; } } Solution 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; }
  • 3. //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]; }
  • 4. 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 : ");
  • 5. 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
  • 6. Hours worked on day 2 is 1.0 _____________Thank You