Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this Exercise 21 .. So the first 2 pictures are the instruction.

ID: 3574857 • Letter: N

Question

Need help with this Exercise 21 .. So the first 2 pictures are the instruction. and the 3rd is what it looks like after opening the zip file

Here is the code for class Testing :

/*
* Class Testing
*
* Do NOT modify this file.
*
*/

public class Testing
{
  
public static void main (String[] args)
{
// ******************* DO NOT MODIFY THE MAIN METHOD*******************
  
testA();
testB();
testC();
testD();
}
  
public static void testA()
{
System.out.println(" **********************************************************");
System.out.println("TESTING SECTION A ");

YourCode a = new YourCode();

a.sectionA("WooHoo");
a.sectionA("HelloThere");
a.sectionA("abcdef");   
a.sectionA("ab");   
a.sectionA("0123456789");   
a.sectionA("kitten");
}
  
public static void testB()
{
System.out.println(" **********************************************************");
System.out.println("TESTING SECTION B ");
  
YourCode b = new YourCode();
  
b.sectionB("Hello");
b.sectionB("java");   
b.sectionB("coding");   
b.sectionB("code");
b.sectionB("ab");
b.sectionB("Chocolate!");
b.sectionB("kitten");
b.sectionB("woohoo");
}

public static void testC()
{
System.out.println(" **********************************************************");
System.out.println("TESTING SECTION C ");

YourCode c = new YourCode();
  
c.sectionC("Hello");
c.sectionC("java");
c.sectionC("Hi");
c.sectionC("code");
c.sectionC("cat");
c.sectionC("12345");
c.sectionC("Chocolate");
c.sectionC("bricks");
}

public static void testD()
{
System.out.println(" **********************************************************");
System.out.println("TESTING SECTION G ");

YourCode d = new YourCode();

d.sectionD("abc hi ho");
d.sectionD("ABChi hi");
d.sectionD("hihi");
d.sectionD("hiHIhi");
d.sectionD("h");
d.sectionD("hi");
d.sectionD("Hi is no HI on ahI");
d.sectionD("hiho not HOHIhi");
}
}

And here is the code for class YourCode :

/*
* (name header)
*/

import java.util.Scanner;

public class YourCode
{
public static Scanner input = new Scanner(System.in);

  
  
public static void sectionB(String str)
{
// Your code here...
  
  
}
  
public static void sectionC(String str)
{
// Your code here...
  

}
  
public static void sectionD(String str)
{
// Your code here...
  
  
}
}

Exercise 21 Strings Using the given project Strings, complete each section in the class YourCode by using the methods specified in each exercise (you may declare additional variables). No need to ask the user to enter values; use the variables that are already declared in the method. The class Testing already has testing cases to test your code. You simply need to compile and execute either the main method or each section of this class. Details about methods of the class String can be found in the String lecture slides. The method length() requires no parameters and it returns the length of the string as an int Folder name A170 E21 YourLastName YourFirstName Part A. HALF A STRING Given a string str1 of even length, print out the first half. Methods to use substring ength() Testing cases WooHoo Woo HelloThere Hello abcdef abc ab a 0123456789 01234 kitten kit Part B. WITHOUT ENDS Given a string str1, print out the string without the first and last char. The string length is at least 2. Methods to use: substring length() Testing cases: Hello el Java av coding odin code od (empty string) ab Chocolate! hocolate kitten itte woohoo ooho

Explanation / Answer

Hi, Please find my code.

Please let me know in case of any issue.

/*

* (name header)

*/

import java.util.Scanner;

public class YourCode

{

   public static Scanner input = new Scanner(System.in);

   public static void sectionA(String str)

   {

       int length = str.length();

       String A = str.substring(0, length/2);

      

       System.out.println(A);

   }

   public static void sectionB(String str)

   {

       int length = str.length();

       String B = str.substring(1, length-1);

      

       System.out.println(B);

   }

   public static void sectionC(String str)

   {

       int length = str.length();

       if(length == 2){

           System.out.println(str);

       }else{

           String left = str.substring(0, 2);

           String right = str.substring(2);

           System.out.println(right+left);

       }

   }

   public static void sectionD(String str)

   {

       int length = str.length();

       int count = 0;

       while(length >= 2){

           String s = str.substring(0, 2);

           if(s.equals("hi"))

               count++;

           str = str.substring(1);

           length = str.length();

       }

      

       System.out.println(count);

   }

}

/*

* Class Testing

*

* Do NOT modify this file.

*

*/

public class Testing

{

   public static void main (String[] args)

   {

       // ******************* DO NOT MODIFY THE MAIN METHOD*******************

       testA();

       testB();

       testC();

       testD();

   }

   public static void testA()

   {

       System.out.println(" **********************************************************");

       System.out.println("TESTING SECTION A ");

       YourCode a = new YourCode();

       a.sectionA("WooHoo");

       a.sectionA("HelloThere");

       a.sectionA("abcdef");

       a.sectionA("ab");

       a.sectionA("0123456789");

       a.sectionA("kitten");

   }

   public static void testB()

   {

       System.out.println(" **********************************************************");

       System.out.println("TESTING SECTION B ");

       YourCode b = new YourCode();

       b.sectionB("Hello");

       b.sectionB("java");

       b.sectionB("coding");

       b.sectionB("code");

       b.sectionB("ab");

       b.sectionB("Chocolate!");

       b.sectionB("kitten");

       b.sectionB("woohoo");

   }

   public static void testC()

   {

       System.out.println(" **********************************************************");

       System.out.println("TESTING SECTION C ");

       YourCode c = new YourCode();

       c.sectionC("Hello");

       c.sectionC("java");

       c.sectionC("Hi");

       c.sectionC("code");

       c.sectionC("cat");

       c.sectionC("12345");

       c.sectionC("Chocolate");

       c.sectionC("bricks");

   }

   public static void testD()

   {

       System.out.println(" **********************************************************");

       System.out.println("TESTING SECTION G ");

       YourCode d = new YourCode();

       d.sectionD("abc hi ho");

       d.sectionD("ABChi hi");

       d.sectionD("hihi");

       d.sectionD("hiHIhi");

       d.sectionD("h");

       d.sectionD("hi");

       d.sectionD("Hi is no HI on ahI");

       d.sectionD("hiho not HOHIhi");

   }

}

/*

Output:

**********************************************************

TESTING SECTION A

Woo

Hello

abc

a

01234

kit

**********************************************************

TESTING SECTION B

ell

av

odin

od

hocolate

itte

ooho

**********************************************************

TESTING SECTION C

lloHe

vaja

Hi

deco

tca

34512

ocolateCh

icksbr

**********************************************************

TESTING SECTION G

1

2

2

2

0

1

0

2

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote