i don't know how to make it..but it is an assignment that must pass up on this sunday..can someone help me..its really important..it should applied array,object and classes...please help me...:(

Suppose the weekly hours for all employees are stored in a two-dimensional array. Each row records an employee’s seven-day work hours with seven columns. For example, the following array stores the work hours for eight employees. Write a program that displays employees and their total hours

Su M T W Th F Sa
Employee 0 2 4 3 4 5 8 8
Employee 1 7 3 4 3 3 4 4
Employee 2 2 3 4 3 3 2 2
Employee 3 9 3 4 7 3 4 1
Employee 4 3 5 4 3 6 3 8
Employee 5 3 4 4 6 3 4 4
Employee 6 3 7 4 8 3 8 4
Employee 7 6 3 5 9 2 7 9

Dani AI

Generated

As indicated, the task should use arrays and classes to compute each employee's weekly total. As suggested, decide what belongs in an array (the seven daily numbers) and what belongs in an object (an employee record). and pointed toward tutorials; below is a concise design and a minimal Java example that satisfies "array + object + class" without repeating the original data.

A simple Employee class that holds a seven-element int[] and exposes a totalHours() method:

public class Employee {
    private final String id;
    private final int[] hours; // expected length: 7

    public Employee(String id, int[] hours) {
        if (hours == null || hours.length != 7) {
            throw new IllegalArgumentException("hours must contain 7 entries");
        }
        this.id = id;
        this.hours = hours.clone(); // defensive copy
    }

    public int totalHours() {
        int sum = 0;
        for (int h : hours) sum += h;
        return sum;
    }

    public String getId() { return id; }
}

Wrap a 2D int[][] into Employee objects and print totals:

public class WeeklyReport {
    public static void main(String[] args) {
        int[][] raw = new int[8][7]; // populate rows with 7-day data

        Employee[] employees = new Employee[raw.length];
        for (int i = 0; i < raw.length; i++) {
            employees[i] = new Employee("Employee " + i, raw[i]);
        }

        for (Employee e : employees) {
            System.out.printf("%s -> %d%n", e.getId(), e.totalHours());
        }
    }
}

Troubleshooting notes: validate each row length before wrapping, clone arrays to avoid accidental sharing, watch index bounds in loops, and keep the model (Employee) separate from presentation (printing). If the assignment allows collections, List<Employee> makes input handling easier, but the above satisfies a strictly array-based solution.

Recommended Answers

All 3 Replies

To start with your test data has one to many columns in it.
Now to start thinking about how to code this what do you know about arrays? What data in this assignment can be easily stored in an array?
Also think about how your going to keep track of which employee is connected with which hours. I hope this helps get you started.

start by reading the tutorials in the sun java website. there are simple examples that you can look into as well on that website. google is your friend!

sun tutorials are good. It will be good to spend some hours on studying about arrays, classes etc. instead of directly attempting to somehow complete the assignment. Then you may visit this website (or any similar) for code examples. Best of luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.