/**
* Program: LabTwoA
*
* Note:
* The methods commented out all do the same thing and work
* To verify just comment out the far left comment markers for the
* block of code you want to see.
*
*
*
* Formula used:
* @author Mr Mike S.
*/
public class LabTwoA {
//----------------------------------------------------------------//
// FIRST PROBLEM //
//----------------------------------------------------------------//
/**
* A method used to print an array of objects
* @param object any type
*/
/* public static void printArray(Object [] object){
for(int i = 0; i < object.length; i++){
System.out.print(object[i] + " ");
}// end of for loop
System.out.println();// space after list is printed
}// end of printArray(Object [] object)
//-----------------------------------------------------------------//
// EXERCISE TWO //
//-----------------------------------------------------------------//
/**
* Prints an array of integers
* @param integer
*/
/* public static void printArray(Integer[] integer ){
for(int i = 0; i < integer.length; i++){
System.out.print(integer[i] + " ");
}// end of for loop
System.out.println();// space
}// end of printArray(Integer)
/**
* Prints an array of doubles
* @param doubArray
*/
/* public static void printArray(Double [] doubArray ){
for(int i = 0; i < doubArray.length; i++){
System.out.print(doubArray[i] + " ");
}
System.out.println();
}// end of printArray(Double)
/**
* Prints an array of Characters
* @param character
*/
/* public static void printArray(Character [] character ){
for(int i = 0; i < character.length; i++){
System.out.print(character[i] + " ");
}
System.out.println();
}// end of printArrray(Character)
/**
* Prints an array of Strings
* @param strArray
*/
/* public static void printArray(String [] strArray ){
for(int i = 0; i < strArray.length; i++){
System.out.print(strArray[i] + " ");
}
System.out.println();
}// end of printArray(String)
//------------------------------------------------------------------//
// EXCERSISE THREE //
//------------------------------------------------------------------//
*
*/
/**
* Generic method used to print values of an array
* @param <Values> Integers, Double, Character, String, etc.
* @param anyArray any array value
*/
public static <Values> void printArray(Values[] anyArray){
for(Values values : anyArray){
System.out.print(values + " ");
}
System.out.println("\n");
}// end of generic method
//----------------------------------------------------------------//
// EXCERSISE FOUR //
//----------------------------------------------------------------//
/**
* This method will find the max value in array
* @param a
* @return
*/
public static Comparable getMax(Comparable [] a){
}
/**
* Main method
* @param arrrgs command line argument
*/
public static void main(String [] arrrgs){
Integer[] intArray = {2, 3, 4, 5, 6};
Double[] doubleArray = {2.3, 3.4, 4.5, 5.6, 6.7};
Character[] charArray = {'H', 'E', 'L', 'L', 'O'};
String[] strArray = {"one", "two", "buckle", "your", "shoe"};
System.out.println("The intArray produces this list:");
printArray(intArray);
System.out.println("The doubleArray produces this list:");
printArray(doubleArray);
System.out.println("The charArray produces this list:");
printArray(charArray);
System.out.println("The strArray produces this list:");
printArray(strArray);
}// end of main method
}// end of LabTwo class
Here are my questions:
1. Will the array have to be sorted before getting compared using compareTo method?
2. Can someone give me an example using Generics for the below method with
comments a "dumbed dow version"? Please try to find an alternate way to show me without answer handed to me.
3. Not related question: What is the function object technique?
/**
* This method will find the max value in array
* @param a
* @return
*/
public static Comparable getMax(Comparable [] a){
// body ...... return .....
}
Thanks to all in advance.
Good answers will definitely get +rep


Sign In
Create Account


Back to top









