Homework Solution: Junit provided, its easy and not suppose to take you more than 15 mins….

    Junit provided, its easy and not suppose to take you more than 15 mins. ------------------------------------------------------------------------ Write an interface named Speaker which declares a two methods: public String noiseMade() andpublic String formatName(String name). You then need to write 4 classes that implement your Speaker interface. The name and description of each of these classes is as follows: Cow -- The formatName method should return the latin name for a cow (Bos taurus), a space, and then the value of name. Cow's noiseMade() method should return the String "Moo". Duck -- The formatName method should return the latin name for a duck (Anas platyrhynchos), a space, and then the value of name. Duck's noiseMade() method should return the String "Quack". Bullfrog -- The formatName method should return the latin name for a bullfrog (Rana catesbeiana), a space, and then the value of name. Bullfrog's noiseMade() method should return the String "Biggest rain we ever had". Person -- The formatName method should return the latin name for a person (Homo sapiens), a space, and then the value of name. The Person class should define a field named emotion which has an appropriate access modifier & getters and setters. Person's constructor should define a single String parameter specifying the emotional state for the instance. Person's noiseMade() method should return the String "Hello, I feel " and then the instance's emotion. ----------------------------------------------------------------------------- Test for Spekaer: package edu.buffalo.cse116; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Method; import org.junit.Test; /** * This is actually a bad set of tests, since each class should only define tests for a single class. I am doing this * anyway, however, to simplify the work you must do on this weekly assignment. * * @author Matthew Hertz */ public class SpeakerTest { // Test that the interface is properly defined. @Test public void testSpeaker() throws SecurityException, NoSuchMethodException { Class<?> speaker = Speaker.class; assertTrue("Speaker must be an interface!", speaker.isInterface()); Method[] methods = speaker.getMethods(); assertEquals("Speaker should define 2 methods", 2, methods.length); Method formatName = speaker.getMethod("formatName", String.class); assertNotNull("Speaker should define a method name formatName with a single String parameter", formatName); assertEquals("formatName should return a String", String.class, formatName.getReturnType()); Method noiseMade = speaker.getMethod("noiseMade"); assertNotNull("Speaker should define a method name noiseMade with no parameters", noiseMade); assertEquals("noiseMade should return a String", String.class, noiseMade.getReturnType()); } // Test that your Cow class works and is properly defined. @Test public void testCow() { Class<?> cowClass = Cow.class; Class<?>[] interfaces = cowClass.getInterfaces(); assertEquals("Cow should only implement 1 class", 1, interfaces.length); assertEquals("Cow should implement the Speaker interface", Speaker.class, interfaces[0]); Cow cow = new Cow(); assertEquals("Bos taurus Bessie", cow.formatName("Bessie")); assertEquals("Bos taurus Clara bell", cow.formatName("Clara bell")); assertEquals("Moo", cow.noiseMade()); } // Test that your Duck class works and is properly defined. @Test public void testDuck() { Class<?> duckClass = Duck.class; Class<?>[] interfaces = duckClass.getInterfaces(); assertEquals("Duck should only implement 1 class", 1, interfaces.length); assertEquals("Duck should implement the Speaker interface", Speaker.class, interfaces[0]); Duck duck = new Duck(); assertEquals("Anas platyrhynchos Howard", duck.formatName("Howard")); // Ask your parents why this is funny assertEquals("Anas platyrhynchos Jack", duck.formatName("Jack")); // Make way! assertEquals("Quack", duck.noiseMade()); } // Test that your Bullfrog class works and is properly defined. @Test public void testBullfrog() { Class<?> frogClass = Bullfrog.class; Class<?>[] interfaces = frogClass.getInterfaces(); assertEquals("Bullfrog should only implement 1 class", 1, interfaces.length); assertEquals("Bullfrog should implement the Speaker interface", Speaker.class, interfaces[0]); Bullfrog frog = new Bullfrog(); assertEquals("Rana catesbeiana Toad", frog.formatName("Toad")); // Arnold Lobel told me that he and Frog are // "friends" assertEquals("Rana catesbeiana Bob", frog.formatName("Bob")); assertEquals("Biggest rain we ever had", frog.noiseMade()); } // Test that your Person class works and is properly defined. @Test public void testPerson() { Class<?> personClass = Person.class; Class<?>[] interfaces = personClass.getInterfaces(); assertEquals("Person should only implement 1 class", 1, interfaces.length); assertEquals("Person should implement the Speaker interface", Speaker.class, interfaces[0]); Person bimodal = new Person("happy"); assertEquals("Homo sapiens Red Sox nation", bimodal.formatName("Red Sox nation")); assertEquals("Homo sapiens Eddie", bimodal.formatName("Eddie")); assertEquals("Hello, I feel happy", bimodal.noiseMade()); assertEquals("happy", bimodal.getEmotion()); bimodal.setEmotion("sad"); assertEquals("sad", bimodal.getEmotion()); assertEquals("Hello, I feel sad", bimodal.noiseMade()); } }

    Expert Answer

     
    Speaker.java: public interface Speaker {

    Junit supposing, its gentle and not attributable attributable attributable guess to obtain?} you more than 15 mins.

    ————————————————————————

    Transcribe an interface spectryd Debater which declares a two regularitys: generally-known String noiseMade() andgenerally-known String cematName(String spectry). You then deficiency to transcribe 4 rankes that utensil your Debater interface. The spectry and cognomen of each of these rankes is as follows:

    Damp — The cematSpectry regularity should repay the latin spectry ce a damp (Bos taurus), a quantity, and then the esteem of spectry. Damp’s noiseMade() regularity should repay the String “Moo”.

    Dip — The cematSpectry regularity should repay the latin spectry ce a dip (Anas platyrhynchos), a quantity, and then the esteem of spectry. Dip’s noiseMade() regularity should repay the String “Quack”.

    Bullfrog — The cematSpectry regularity should repay the latin spectry ce a bullfrog (Rana catesbeiana), a quantity, and then the esteem of spectry. Bullfrog’s noiseMade() regularity should repay the String “Biggest rain we coercionforeternally had”.

    Peculiar — The cematSpectry regularity should repay the latin spectry ce a peculiar (Homo sapiens), a quantity, and then the esteem of spectry. The Peculiar rank should designate a opportunity spectryd agitation which has an alienate entrance modifier & getters and fixedters. Peculiar’s originator should designate a uncombined String parameter specifying the agitational aver ce the illustration. Peculiar’s noiseMade() regularity should repay the String “Hello, I handle ” and then the illustration’s agitation.

    —————————————————————————–

    Test ce Spekaer:

    package edu.buffalo.cse116;

    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertNotNull;
    import static org.junit.Assert.assertTrue;

    import java.lang.reflect.Method;

    import org.junit.Test;

    /**
    * This is substantially a indisposed fixed of tests, gone each rank should simply designate tests ce a uncombined rank. I am doing this
    * anyway, ultimately, to disencumber the fruit you must do on this weekly ordinance.
    *
    * @author Matthew Hertz
    */
    generally-known rank DebaterTest {

    // Test that the interface is well designated.
    @Test
    generally-known destitute testSpeaker() throws SecurityException, NoSuchMethodException {
    Class<?> debater = Debater.class;
    assertTrue(“Debater must be an interface!”, debater.isInterface());
    Method[] regularitys = debater.getMethods();
    assertEquals(“Debater should designate 2 regularitys”, 2, regularitys.length);
    Regularity cematSpectry = debater.getMethod(“formatName”, String.class);
    assertNotNull(“Debater should designate a regularity spectry cematSpectry with a uncombined String parameter”, cematName);
    assertEquals(“formatSpectry should repay a String”, String.class, cematName.getReturnType());
    Regularity noiseMade = debater.getMethod(“noiseMade”);
    assertNotNull(“Debater should designate a regularity spectry noiseMade with no parameters”, noiseMade);
    assertEquals(“noiseMade should repay a String”, String.class, noiseMade.getReturnType());

    }

    // Test that your Damp rank fruits and is well designated.
    @Test
    generally-known destitute testCow() {
    Class<?> dampRank = Damp.class;
    Class<?>[] interfaces = dampClass.getInterfaces();
    assertEquals(“Damp should simply utensil 1 rank”, 1, interfaces.length);
    assertEquals(“Damp should utensil the Debater interface”, Debater.class, interfaces[0]);
    Damp damp = odd Damp();
    assertEquals(“Bos taurus Bessie”, damp.formatName(“Bessie”));
    assertEquals(“Bos taurus Clara bell”, damp.formatName(“Clara bell”));
    assertEquals(“Moo”, damp.noiseMade());
    }

    // Test that your Dip rank fruits and is well designated.
    @Test
    generally-known destitute testDuck() {
    Class<?> dipRank = Dip.class;
    Class<?>[] interfaces = dipClass.getInterfaces();
    assertEquals(“Dip should simply utensil 1 rank”, 1, interfaces.length);
    assertEquals(“Dip should utensil the Debater interface”, Debater.class, interfaces[0]);
    Dip dip = odd Dip();
    assertEquals(“Anas platyrhynchos Howard”, dip.formatName(“Howard”)); // Ask your parents why this is funny
    assertEquals(“Anas platyrhynchos Jack”, dip.formatName(“Jack”)); // Make way!
    assertEquals(“Quack”, dip.noiseMade());
    }

    // Test that your Bullfrog rank fruits and is well designated.
    @Test
    generally-known destitute testBullfrog() {
    Class<?> frogRank = Bullfrog.class;
    Class<?>[] interfaces = frogClass.getInterfaces();
    assertEquals(“Bullfrog should simply utensil 1 rank”, 1, interfaces.length);
    assertEquals(“Bullfrog should utensil the Debater interface”, Debater.class, interfaces[0]);
    Bullfrog frog = odd Bullfrog();
    assertEquals(“Rana catesbeiana Toad”, frog.formatName(“Toad”)); // Arnold Lobel told me that he and Frog are
    // “friends”
    assertEquals(“Rana catesbeiana Bob”, frog.formatName(“Bob”));
    assertEquals(“Biggest rain we coercionforeternally had”, frog.noiseMade());
    }

    // Test that your Peculiar rank fruits and is well designated.
    @Test
    generally-known destitute testPerson() {
    Class<?> peculiarRank = Peculiar.class;
    Class<?>[] interfaces = peculiarClass.getInterfaces();
    assertEquals(“Peculiar should simply utensil 1 rank”, 1, interfaces.length);
    assertEquals(“Peculiar should utensil the Debater interface”, Debater.class, interfaces[0]);
    Peculiar bimodal = odd Peculiar(“happy”);
    assertEquals(“Homo sapiens Red Sox nation”, bimodal.formatName(“Red Sox nation”));
    assertEquals(“Homo sapiens Eddie”, bimodal.formatName(“Eddie”));
    assertEquals(“Hello, I handle happy”, bimodal.noiseMade());
    assertEquals(“happy”, bimodal.getEmotion());
    bimodal.setEmotion(“sad”);
    assertEquals(“sad”, bimodal.getEmotion());
    assertEquals(“Hello, I handle sad”, bimodal.noiseMade());
    }
    }

    Expert Repartee

     

    Speaker.java:

    generally-known interface Debater {

    generally-known String noiseMade();

    generally-known String cematName(String spectry);

    }

    Cow.java:

    generally-known rank Damp utensils Debater{

    @Override

    generally-known String noiseMade() {

    repay “Moo”;

    }

    @Override

    generally-known String cematName(String spectry) {

    repay “Bos taurus ” + spectry;

    }

    }

    Duck.java:

    generally-known rank Dip utensils Debater{

    @Override

    generally-known String noiseMade() {

    repay “Quack”;

    }

    @Override

    generally-known String cematName(String spectry) {

    repay “Anas platyrhynchos ” + spectry;

    }

    }

    BullFrog.java:

    generally-known rank Bullfrog utensils Debater{

    @Override

    generally-known String noiseMade() {

    repay “Biggest rain we coercionforeternally had”;

    }

    @Override

    generally-known String cematName(String spectry) {

    repay “Rana catesbeiana ” + spectry;

    }

    }

    Person.java:

    generally-known rank Peculiar utensils Debater{

    private String agitation;

    generally-known Peculiar(String agitation) {

    this.agitation = agitation;

    }

    generally-known String getEmotion() {

    repay agitation;

    }

    generally-known destitute fixedEmotion(String agitation) {

    this.agitation = agitation;

    }

    @Override

    generally-known String noiseMade() {

    repay “Hello, I handle ” + agitation;

    }

    @Override

    generally-known String cematName(String spectry) {

    repay “Homo sapiens ” + spectry;

    }

    }