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

Need help with Java as I need to create one application with a class that has a

ID: 3669159 • Letter: N

Question

Need help with Java as I need to create one application with a class that has a main() method that will test each of the following classes. (a.) Perform a unit test of the MyClone class to test all getters (accessors) and setters (mutators)and method(s) of the class. (b.) Perform a unit test of the ShoutBox class to test all methods of the class.

MyClone and ShoutBox are below:

MyClone: Create a Virtual World application. This Virtual World will have several objects including a MyClone object and another object of your choice. Develop the MyClone class by adding accessor methods, mutator methoda, and an introduction() method. The introduction() method will introduce yourself to the virtual world by displaying a greeting, your first and last name, and anything else you would want to say.

package myclonev2;

public class MyCloneV2 {

private String firstName;

   private String lastName;

public MyCloneV2(String firstName, String lastName)

   {

       this.firstName=firstName;

       this.lastName=lastName;

         }

public void introduction()

   {

       System.out.println("Hi virtual world!");

       System.out.println("My name is "+firstName+" "+lastName);

              }

       /*Mutator methods of instance variables*/

   /*Set firstname*/

   public void setFName(String firstName)

   {

       this.firstName=firstName;

   }

/*Set last name*/

   public void setLName(String lastName) {

       this.lastName=lastName;   }

   {

   }

          /*Accessor methods of instance variables*/

   /*Returns first name*/

   public String getFName() {

       return firstName; }

/*Returns last name*/

   public String getLName() {

       return lastName; }

   public String getFTeam()

   {

     /** return favTeam;

   } **/

public static void main(String[] args) {

MyCloneV2 m = new MyCloneV2("Benny", "Bourque");

m.introduction();

   }

}

ShoutBox:

Create the ShoutBox class for your Virtual World. Your ShoutBox class will have two methods:

Method shoutOutCannedMessage() will return type String. The shoutOutCannedMessage will use an Array or an ArrayList to store 10 messages of type String. You can load this data structure with 10 messages of your choosing. You can initialize your Array or ArrayList with the messages or have the user enter the messages. The choice is yours. shoutOutCannedMessage() will loop through the data structure to first display all canned messages and allow the user to select one. The shoutOutCannedMessage() will return the selected message String. The shoutOutRandomMessage() method will return type String. The shoutOutRandomMessage() will use several Arrays or an ArrayList to store words. You will have one data structure that holds a list of words that are subjects, another data structure that holds a list of words that are objects, another that holds a list of verbs, another that holds a list of adverbs, and another that holds a list of adjectives. You can initialize your data structures with words or have the user enter the words. The choice is yours. The shoutOutRandomMessage() method will use a random number generator that selects one word from each data structure to form a random message. The shoutOutRandomMessage() method will return the random message as a String data type. Random messages will be of the form: Subject - Verb - Adjective - Object - Adverb.

package shoutbox;

import java.util.Scanner;

public class ShoutBox {

    private static Object scanner;

    public static void main(String[] args) { // main method

        shoutOutRandomMessage();

        }

        public static void shoutOutRandomMessage() {

        String shoutSubject;

        String shoutVerb;

        String shoutAdjective;

       String shoutObject;

        String shoutAdverb;

        

        int length; // instance variable that determines the length of the array

        Scanner input = new Scanner(System.in); // the Scanner utility is added

        

        System.out.println("You can choose how many words you want to be able to choose from. "

                           + "Please enter a number between 1 and 10 and hit Enter: ");

        length = input.nextInt(); // takes user input of integer

        int number = 0;

        /* create array to store user subjects */

        String[] subject = new String[length];

        for(int counter = 0; counter < length; counter++){

        System.out.println("Please enter words that are Subjects " + (counter+1) + ": ");

        subject[counter] = input.next(); /* Takes input and stores the words in array*/

        }

        System.out.println("The Subjects you chose are: ");

        for(int counter = 0; counter < length; counter++){

        System.out.println(subject[counter]);

        }

       /* create array to store user verbs */

        String[] verb = new String[length];

        for(int counter = 0; counter < length; counter++){

        System.out.println("Please enter words that are Verbs " + (counter+1) + ": ");

        verb[counter] = input.next(); /* Takes input and stores the words in array*/

        }

        System.out.println("The Verbs you chose are: ");

        for(int counter = 0; counter < length; counter++){

        System.out.println(verb[counter]);

        }

       /* create array to store user adjectives */

        String[] adjective = new String[length];

        for(int counter = 0; counter < length; counter++){

        System.out.println("Please enter words that are Adjectives " + (counter+1) + ": ");

        adjective[counter] = input.next(); /* Takes input and stores the words in array*/

        }

        System.out.println("The Adjectives you chose are: ");

        for(int counter = 0; counter < length; counter++){

        System.out.println(adjective[counter]);

        }

       /* create array to store user objects */

        String[] object = new String[length];

        for(int counter = 0; counter < length; counter++){

        System.out.println("Please enter words that are Objects " + (counter+1) + ": ");

        object[counter] = input.next(); /* Takes input and stores the words in array*/

        }

        System.out.println("The Objects you chose are: ");

        for(int counter = 0; counter < length; counter++){

        System.out.println(object[counter]);

      }

       /* create array to store user adverbs */

        String[] adverb = new String[length];

        for(int counter = 0; counter < length; counter++){

        System.out.println("Please enter Adverb " + (counter+1) + ": ");

      adverb[counter] = input.next();/* Takes input and stores the words in array*/

        }

        System.out.println("The Adverbs of your choice are: ");

        for(int counter = 0; counter < length; counter++){

        System.out.println(adverb[counter]);

        }

       // retrieve random number that equals index and returns array element

        int random = (int) (Math.random()*length);

        System.out.println("Your message is: " +

                subject[random] + " " + object[random] + " " + verb[random]

                + " " + adverb[random] + " " + adjective[random]);

    }

}

Explanation / Answer

package shoutbox;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TestClass {
  
   private MyCloneV2 clone;
   private ShoutBox shoutbox;
   private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
  
   @Before
   public void createInstance() {
       clone = new MyCloneV2("Moby", "Dick");
       shoutbox = new ShoutBox();
   }
  
   @After
   public void cleanUpStream() {
       System.setOut(null);
   }
  
   @Before
   public void setUpStream() {
       System.setOut(new PrintStream(outContent));
   }
  
   @Test
   public void testGetFName() {
       Assert.assertEquals("Moby", clone.getFName());
   }
  
   @Test
   public void testGetLName() {
       Assert.assertEquals("Dick", clone.getLName());
   }
  
   @Test
   public void testSetFName() {
       clone.setFName("Jack");
       Assert.assertEquals("Jack", clone.getFName());
   }
  
   @Test
   public void testSetLName() {
       clone.setLName("Nash");
       Assert.assertEquals("Nash", clone.getLName());
   }
  
   @Test
   public void testIntroduction() {
       clone.introduction();
       Assert.assertEquals("Hi virtual world! My name is " + clone.getFName() + " " + clone.getLName(), outContent.toString().trim());
   }
  
  

}

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