// // todo.java: task code in Java // import java.nio.BufferOverflowException; class Task { private String description; private double hours; public Task(String description, double hours) { this.description = description; this.hours = hours; } public double getHours() { return hours; } public String getDescription() { return description; } } class TaskList { private static final int MAX = 50; private Task[] todo = new Task[MAX]; private int count = 0; public void add(Task new_task) { if ( count >= MAX ) throw new BufferOverflowException(); todo[count] = new_task; ++count; } public double totalHours() { double tot = 0.0; for(int i = 0; i < count; ++i) tot += todo[i].getHours(); return tot; } public static void main(String[] args) { TaskList tasks = new TaskList(); tasks.add(new Task("sleep", 6.5)); tasks.add(new Task("shower", 0.17)); tasks.add(new Task("program", 16.5)); tasks.add(new Task("eat", 0.5)); System.out.println("Total time: " + tasks.totalHours()); } } // // output: // // Total time: 23.67 //