Question
Hello I need a second pair of to see if I did this Java program correctly with all the requirements given. Here is the assignment.
Hello
I need a second pair of to see if I did this Java program correctly with all the requirements given. Here is the assignment. It does come with a test-harness so I wanted to see if the test-harness wouldn't be effect either. I did this program using a few video game characters for fun. My professor seems like he doesn't mind it.
Assignment:
Concepts:
Generics
Arrays
Objects
Part I:
Make a method in Java that takes an array, the length of
the array, and an element and returns the position of the element in the array. For example, given
the array with values [2, 4, 6, 8] and element 6, the routine should return 2 (since counting from 0,
6 occurs at position 2 in the array). Your routine should use generics to enable your routine to
be reusable for different element types. Be sure to test your code with a Java compiler before you
submit it.
Part II:
Make a generic "greater-than" method that (a) takes two objects as
arguments, each of which contains a method called "value", which returns an integer; and (b) returns the
object whose "value" method returns the larger integer. Your generic function should constrain
its type argument so that object types that do not contain a method called "value" cannot be used.
Test-Harness:
public class TestGenerics {
public static void main(String[] args) {
MyFirstObject myObj1 = new MyFirstObject();
MySecondObject myObj2 = new MySecondObject();
MyGenerics mg = new MyGenerics();
int[] array = {2,4,6,8};
System.out.println( mg.partOne(array, array.length, 6) );
System.out.println( mg.partTwo(myObj1, myObj2) );
}
}
My code:
public class tVirus {
public static
for(int nemesis = 0; nemesis < arr.length; nemesis++) {
if(arr[nemesis].equals(ada)) {
return nemesis;
}
}
return -1;
}
public static
if (virus1 == null) {
return virus2;
}
if(virus1.intValue() > virus2.intValue()) {
return virus1;
} else {
return virus2;
}
}
public static void main(String[] args) {
System.out.println(tVirus.
System.out.println(tVirus.
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started