Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

17.1: Getting More Methodical [(JAVA, ECLIPSE), Please keep the program as short as possible] Copy and paste the starter code into a new file called

17.1: Getting More Methodical

[(JAVA, ECLIPSE), Please keep the program as short as possible]

  • Copy and paste the starter code into a new file called More.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 More { /** * Given a string, take the last char and return a new String with the last char added at the front and back, * so "cat" yields "tcatt". The original string will be length 1 or more. * backAround("cat") "tcatt" * backAround("Hello") "oHelloo" * backAround("a") "aaa" * @param str the input String * @return a new String with the last char added to front and back */ public static String backAround(String str) { return ""; } /** * Given 2 strings, a and b, return a String of the form short+long+short, * with the shorter String on the outside and the longer String on the inside. * The Strings will not be the same length, but they may be empty (length 0). * comboString("Hello", "hi") "hiHellohi" * comboString("hi", "Hello") "hiHellohi" * comboString("aaa", "b") "baaab" * @param a the first String to combine * @param b the second String to combine * @return a new String short+long+short */ public static String comboString(String a, String b) { return ""; } /** * Given a String of even length, return a String * made of the middle two chars, so the String * "string" yields "ri". * Note: You can assume the String length will be at least 2. * middleTwo("string") "ri" * middleTwo("code") "od" * middleTwo("Practice") "ct" * @param str the String to extract the middle * @return the middle of the String */ public static String middleTwo(String str){ return ""; } /** * Given a string, return a new String made of 3 copies of the last 2 chars of the original String. * The String length will be at least 2. * extraEnd("Hello") "lololo" * extraEnd("ab") "ababab" * extraEnd("Hi") "HiHiHi" * @param str the String to copy * @return the repeated characters */ public static String extraEnd(String str) { return ""; } /** * Given a String, determines whether the given character is in the String * contains('@', "bob@jobs.com") true * contains('@', "bobajobs.com") false * contains('2', "tr2dat") true * @param c the character to locate in the String * @param s the String to search * @return whether c is in s */ public static boolean contains(char c, String s) { return false; } public static void main(String[] args) { String value; boolean b; System.out.println("***Testing backAround*** "); value = backAround("cat"); System.out.println("Should print tcatt: " + value); value = backAround("Hello"); System.out.println("Should print oHelloo: " + value); value = backAround("a"); System.out.println("Should print aaa: " + value +" "); System.out.println("***Testing comboString*** "); value = comboString("Hello", "hi"); System.out.println("Should be hiHellohi: " + value); value = comboString("hi", "Hello"); System.out.println("Should be hiHellohi: " + value); value = comboString("aaa", "b"); System.out.println("Should be baaab: " + value + " "); System.out.println("***Testing middleTwo*** "); value = middleTwo("string"); System.out.println("Should be ri: " + value); value = middleTwo("code"); System.out.println("Should be od: " + value); value = middleTwo("Practice"); System.out.println("Should be ct: " + value + " "); System.out.println("***Testing extraEnd*** "); value = extraEnd("Hello"); System.out.println("Should be lololo: " + value); value = extraEnd("ab"); System.out.println("Should be ababab: " + value); value = extraEnd("feet"); System.out.println("Should be etetet: " + value + " "); System.out.println("***Testing contains*** "); b = contains('a', "bob@jobs.com"); System.out.println("Should be true: " + b); b = contains('a', "bobajobs.com"); System.out.println("Should be false: " + b); b = contains('2', "tr2dat"); System.out.println("Should be true: " + b); System.out.println("***End of Tests***"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

305 mg of C6H12O6 in 55.2 mL of solution whats the molarity

Answered: 1 week ago