Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. public class Data
  2. {
  3. public static double average(Measurable[] objects)
  4. {
  5. double total = 0;
  6. for (Measurable obj : objects)
  7. {
  8. total = total + obj.getMeasure();
  9. }
  10. if (objects.length > 0)
  11. {
  12. return total / objects.length;
  13. }
  14. else
  15. {
  16. return 0;
  17. }
  18. }
  19. public static Measurable max(Measurable[] objects)
  20. {
  21. double max = objects[0].getMeasure();
  22. int maxIndex = 0;
  23. for (int i = 0; i < objects.length; i++)
  24. {
  25. if (objects[i].getMeasure() > max)
  26. {
  27. max = objects[i].getMeasure();
  28. maxIndex = i;
  29. }
  30. }
  31. return objects[maxIndex];
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement