MyGenerics6.java - package hw6\/Purpose Practicing with Generics Recursion and Interfaces\/Author Jonathan Andre Justin young\/Course CS 1302\/Date\/Program

MyGenerics6.java - package hw6/Purpose Practicing with...

This preview shows page 1 - 3 out of 4 pages.

package hw6; //******************************************************************************* //Purpose: Practicing with Generics, Recursion, and Interfaces // //Author: Jonathan Andre, Justin young // //Course: CS 1302 //Date: 7/11/17 //Program: MyGenerics6.java //******************************************************************************* import java.util.ArrayList; public class MyGenerics6{ //Declarations //**************************************************************************** //No-argument constructor: //**************************************************************************** public MyGenerics6 (){ }//end of constructor //**************************************************************************** //max: Receives a generic one-dimensional array and returns the maximum // value in the array. //**************************************************************************** public <E extends Comparable<E>> E max(E[] list){ E max = list[0]; for (int i = 1; i < list.length; i++) { E el = list[i]; if (el.compareTo(max) > 0) { max = el; } } return max; }//end of max //**************************************************************************** //max: Receives a generic two-dimensional array and returns the maximum // value in the array. //**************************************************************************** public <E extends Comparable<E>> E max(E[][] list) { E max = list[0][0]; for (int i = 1; i < list.length; i++) {
Image of page 1
for (int j = 1; j < list[i].length; j++) { E element =list[i][j]; if (element.compareTo(max) > 0) { max = (E)element; } } } return max; } //**************************************************************************** //largest: Receives a generic arrayList and returns the maximum // value in the array. //**************************************************************************** public <E extends Comparable<E>> E largest(ArrayList<E> list) { E largest = list.get(0); for (int i = 1; i < list.size(); i++){ if (list.get(i).compareTo(largest) > 0){
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '08
  • STAFF
  • String Theory, Array, E max, JONATHAN ANDRE, public class MyGenerics6

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture