Question

Java need to create an array that keeps track of the number of employees that where...

Java

need to create an array that keeps track of the number of employees that where absent each day. Needs to be large enough to store a full month of date.

Ex) on the first day of the month, 1 employee was absent; second day of the month only 2 absence and this information does not need to but put in by user.

Prompt the user to input a number to display the number of absences on the day they entered.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

hi

please find below java code for your question. Store below code in Employee.java file and run the program. it will ask to enter data for entire month and will display for given day.

in Employee.java put..

import java.util.Scanner;

public class Employee {
    //array to hold absence data
    int absenceData[];
    //scanner to read data from console
    Scanner scan =new Scanner(System.in);
   
    //default constructor
    public Employee(){}
   
    //method to input absence data into array
    public void enterAbsesnceData()
    {
        //define array to hold data for 30 days
        absenceData=new int[30];
        //read and store data into array
        for(int i=0;i<30;i++ ){
           
            System.out.println("Enter no of employee absent on day "+(i+1));
            absenceData[i]=scan.nextInt();
        }
    }
   
    //method to display data for entered day
    public void DisplayAbsenceData()
    {
        int day=0;
        //ask user to enter day
        System.out.println("Enter day to display data(1-30)");
        day=scan.nextInt();
        System.out.println("Number of enployee absent:"+absenceData[day-1]);
    }
   
    /*method to display option for different operations.
    this method call differnt mehod based on choice of user.
    */
    public void displayOption(){
        int option=0;
        while(option!=3){
        System.out.println("\nplease choose an option");
       System.out.println("1.enter data");
        System.out.println("2.display data");
        System.out.println("3. exit");
        option=scan.nextInt();
       
        switch(option){
           
            case 1:
                this.enterAbsesnceData();
                break;
               
            case 2:
                this.DisplayAbsenceData();
               
            case 3:
                break;
               
            default:
                System.out.println("please enter a valid option");
           
            }
        }
       
    }
       
   
    //driver method
    public static void main(String[] args){
        //define employee object to call displayOptionMethod.
        Employee e=new Employee();
       
        //call displayOption method
        e.displayOption();
      
       
    }
   
   
   
   
}

output:

Enter no of employee absent on day 28 Enter no of employee absent on day 2s Enter no of employee absent on day 30 please choo

Add a comment
Know the answer?
Add Answer to:
Java need to create an array that keeps track of the number of employees that where...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • Using Java Create an application that creates and displays a list of names using an array....

    Using Java Create an application that creates and displays a list of names using an array. Then modify the application to create and use a list of numbers. Console for the names application Please enter a name or type “exit” to quit: Diane Please enter a name or type “exit” to quit: Joe Please enter a name or type “exit” to quit: Greta Please enter a name or type “exit” to quit: Henry Please enter a name or type “exit”...

  • Write a Java program that will create an array of Strings with 25 elements. Input Strings...

    Write a Java program that will create an array of Strings with 25 elements. Input Strings from the user and store them in the array until either the user enters “quit” or the array is full. HINT: the sentinel value is “quit” all lowercase. “Quit” or “QUIT” should not stop the loop. HINT: you have to use the equals method (not ==) when you are comparing two Strings. After the input is complete, print the Strings that the user entered...

  • java programe Write a program that prompts the user to enter in an integer number representing...

    java programe Write a program that prompts the user to enter in an integer number representing the number of elements in an integer array. Create the array and prompt the user to enter in values for each element using a for loop. When the array is full, display the following: The values in the array on a single line. The array with all of the elements reversed. The values from the array that have even numbered values. The values from...

  • Create a Java program application that creates an ArrayList that holds String objects. It needs to...

    Create a Java program application that creates an ArrayList that holds String objects. It needs to prompt the user to enter the names of friends, which are then put into the ArrayList; allow the user to keep adding names until they enter "q" to quit. After input is complete, display a numbered list of all friends in the list and prompt the user to enter the number of the friend they wish to delete. After deleting that entry, output the...

  • A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold...

    A car dealer has 10 salespersons. Each salesperson keeps track of the number of cars sold each month and reports it to the management at the end of the month. The management keeps the data in a file and assigns a number, 1 to 10 to each salesperson. The following statement declares an array, cars, of 10 components of type int to store the number of cars sold by each salesperson. Int cars[10]; Write the C++ code to store the...

  • I need to write a program in java using two array lists. I need to program...

    I need to write a program in java using two array lists. I need to program to prompt the user to enter a day of the week and return an output of a predetermined temperature for the day they selected. I also need the program the output the average of daily temperatures across the week if the user inputs "week". So basically if i set the temperatures to something arbitrary i.e.: Monday = 50 Tuesday = 55 Wednesday = 52...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT