Please complete in Java.
/**
*
* Implement all the methods described below.
*
* Student name: YOUR NAME GOES HERE.
*/
public class Subroutines1 {
///////////////////////////////////////////////////////////////////////////
// The main() method tests your program's completeness.
public static void main(String[] args) {
int numCorrect = 0;
if( getMaximum(1, 2, 3) == 3 ) { numCorrect++; }
if( getMaximum(4,-5, 2) == 4 ) { numCorrect++; }
if( getMaximum(0, 7, 5) == 7 ) { numCorrect++; }
if( !isEven(3) ) { numCorrect++; }
if( isEven(-2) ) { numCorrect++; }
if( isEven(0) ) { numCorrect++; }
if( !isEven(-2*(int)(Math.random()*100)+1) ) {numCorrect++;}
if( !hasG( "man" ) ) { numCorrect++; }
if( hasG( "dog" ) ) { numCorrect++; }
if( hasG( "EGGSHELL" ) ) { numCorrect++; }
if( indexOfG( "man" ) == -1 ) { numCorrect++; }
if( indexOfG( "EGGSHELL" ) == 1 ) { numCorrect++; }
if( indexOfG( "dog" ) == 2 ) { numCorrect++; }
if( indexOfG( "xyzggGGggG" ) == 3 ) { numCorrect++; }
if( indexOfG( "xyzGGggGGg" ) == 3 ) { numCorrect++; }
System.out.println( "Your program's completeness is currently: "
+ numCorrect + "/15" );
}
///////////////////////////////////////////////////////////////////////////
/**
* Returns largest of its arguments.
* @param x First argument
* @param y Second argument
* @param z Third argument
* @return Maximum of x, y and z
*/
private static int getMaximum( int x, int y, int z) {
// REPLACE THE METHOD BODY
// This is an obviously wrong return value
// that exists only to allow the file to compile
return -1000;
}
///////////////////////////////////////////////////////////////////////////
/**
* Is the argument even?
* (Recall that even numbers are divisible by 2)
* @param x Value to check.
* @return True if x is an even number, false otherwise.
*/
private static boolean isEven( int x ) {
// REPLACE THE METHOD BODY
// Hardcoded value will be "correct" sometimes,
// but you must make it work for all input
return false;
}
///////////////////////////////////////////////////////////////////////////
/**
* Does the given string contain the letter G (either upper or
* lower case)?
* @param x String to check
* @return True if x contains G, false otherwise.
*/
private static boolean hasG( String x ) {
// REPLACE THE METHOD BODY
// Again, hardcoding a value to compile
return false;
}
///////////////////////////////////////////////////////////////////////////
/**
* Where is the location of the letter G (upper or lower case) in
* the given string?
* @param x String to check
* @return 0 based location of first occurrence of G in x,
* -1 if G is not present.
*/
private static int indexOfG( String x ) {
// REPLACE THE METHOD BODY
// This is an obviously wrong return value
// that exists only to allow the file to compile
return -1234;
}
///////////////////////////////////////////////////////////////////////////
}
1 Assignment Description I have provided you with some starter code in a file named
Subroutines1.java. Open this file in your editor and use it as a sta.
2. if( indexOfG( "xyzggGGggG" ) == 3 ) { numCorrect++; }
if( indexOfG( "xyzGGggGGg" ) == 3 ) { numCorrect++; }
System.out.println( "Your program's completeness is currently: "
+ numCorrect + "/15" );
}
///////////////////////////////////////////////////////////////////////////
/**
* Returns largest of its arguments.
* @param x First argument
* @param y Second argument
* @param z Third argument
* @return Maximum of x, y and z
*/
private static int getMaximum( int x, int y, int z) {
// REPLACE THE METHOD BODY
// This is an obviously wrong return value
// that exists only to allow the file to compile
return -1000;
}
///////////////////////////////////////////////////////////////////////////
/**
* Is the argument even?
* (Recall that even numbers are divisible by 2)
* @param x Value to check.
* @return True if x is an even number, false otherwise.
*/
private static boolean isEven( int x ) {
3. // REPLACE THE METHOD BODY
// Hardcoded value will be "correct" sometimes,
// but you must make it work for all input
return false;
}
///////////////////////////////////////////////////////////////////////////
/**
* Does the given string contain the letter G (either upper or
* lower case)?
* @param x String to check
* @return True if x contains G, false otherwise.
*/
private static boolean hasG( String x ) {
// REPLACE THE METHOD BODY
// Again, hardcoding a value to compile
return false;
}
///////////////////////////////////////////////////////////////////////////
/**
* Where is the location of the letter G (upper or lower case) in
* the given string?
* @param x String to check
* @return 0 based location of first occurrence of G in x,
* -1 if G is not present.
*/
private static int indexOfG( String x ) {
// REPLACE THE METHOD BODY
4. // This is an obviously wrong return value
// that exists only to allow the file to compile
return -1234;
}
///////////////////////////////////////////////////////////////////////////
}
1 Assignment Description I have provided you with some starter code in a file named
Subroutines1.java. Open this file in your editor and use it as a starting point. Do not modify the
main() method. Using this code, complete all the methods as written in the descriptions provided.
There are four methods that must be completed. The program will test your methods and assign a
completeness score when run out of 15 . Submitting code that compiles and produces a score of
15/15 is expected. 2 Turning in your assignment Submit your Subroutines1.java file to the Lab 5
assignment in Canvas. Do not attach .class files or any other files. 3 Grading Rubric (total of 30
points) A (5 points): Exactly one file submitted in Canvas with name Subroutines1.java B (5
points): Compiles and runs without errors C (5 points): Adheres to the coding standards D (15
points): Passes 15 tests (1 point per test) IMPORTANT: You will not receive credit for a method
if you merely hard code the test case output rather than correctly implementing the described
behavior.