Question
18.1: Getting Even More Methodical [(JAVA, ECLIPSE), Please keep the program as short as possible] Copy and paste the starter code into a new file
18.1: Getting Even More Methodical
[(JAVA, ECLIPSE), Please keep the program as short as possible]
- Copy and paste the starter code into a new file called EvenMore.java
- Write the required methods as described by the comments (i.e. you fill in the body of the method).
- Then, run the code when you are finished to see if you wrote the methods correctly.
- Check the test results and make any alterations to your methods as necessary.
- When all of the tests pass, upload your code to Canvas.
/* * @author * CIS 36A * */ import java.util.Scanner; public class EvenMore { /* Given a String, return true if the String starts with "hi" and false otherwise. startHi("hi there") true startHi("hi") true startHi("hello hi") false */ public static boolean startHi(String str) { return false; } /* Given a String and a non-negative int n, the front of the String is the first 3 chars, or whatever is there if the string is less than length 3 Return n copies of the front; Hint: use a for loop and string concatenation frontTimes("Chocolate", 2) "ChoCho" frontTimes("Abcd", 3) "AbcAbcAbc" frontTimes("Oy", 4) "OyOyOyOy" */ public static String frontTimes(String str, int n) { return ""; } /* Given 2 int values, return whichever value is nearest to the value 10, or return 0 in the event of a tie. Hint: recall that Math.abs(n) returns the absolute value of a number. close10(8, 13) 8 close10(13, 8) 8 close10(13, 7) 0 */ public static int close10(int a, int b) { return 0; } /* Given a String, return true if the first instance of "x" in the String is immediately followed by another "x". Hint: use a for loop and substring doubleX("axxbb") true doubleX("axaxax") false doubleX("xxxxx") true */ public static boolean doubleX(String str){ return false; } public static void main(String[] args) { String value; boolean result; int num; System.out.println("***Testing startHi*** "); result = startHi("hi there"); System.out.println("Should be true: " + result); result = startHi("hi"); System.out.println("Should be true: " + result); result = startHi("hello hi"); System.out.println("Should be false: " + result +" "); System.out.println("***Testing frontTimes*** "); value = frontTimes("Chocolate", 2); System.out.println("Should be ChoCho: " + value); value = frontTimes("Abcd", 3); System.out.println("Should be AbcAbcAbc: " + value); value = frontTimes("Oy", 4); System.out.println("Should be OyOyOyOy: " + value + " "); System.out.println("***Testing close10*** "); num = close10(8, 13); System.out.println("Should be 8: " + num); num = close10(13, 8); System.out.println("Should be 8: " + num); num = close10(13, 7); System.out.println("Should be 0: " + num + " "); System.out.println("***Testing doubleX*** "); result = doubleX("axxbb"); System.out.println("Should be true: " + result); result = doubleX("axaxax"); System.out.println("Should be false: " + result); result = doubleX("xxxxx"); System.out.println("Should be true: " + result + " "); System.out.println("***End of Tests***"); } }
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