Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.17 part 2 pls have a neat code in java and no null pointer exception 4.17 Ch 4 Program, Part 2: Clue Eye Witness Method

4.17 part 2 pls have a neat code in java and no null pointer exception

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

4.17 Ch 4 Program, Part 2: Clue Eye Witness Method The goal of this problem is to build on the previous exercise and make a user-defined method that can take input and output the correct message. You will also build a test method to ensure that your new method works as expected. You will add a new method that takes in the murderer as an input and returns the murder message. Note: this new method should return a String rather than printing a String. You will also create a test method to make sure that your new method works as expected. You will call the test method from the main method. (1) Complete the following method: * Determines the detective's message. The input should be case insensitive. * If the murderer is not recognized or is null, the message * "We're not sure who that is. We need to investigate further." is returned. * @param murderer abbreviation. * @return the detective's message for a given murderer. public static String murdererMessage (String murderer) { // FILL IN BODY Like in part 1 this method emulates a detective questioning an eye-witness of a murder. The detective has three suspects each with a potential murder weapon. Based on the eye-witness's user input, the detective will reach a conclusion about the murderer and the murder weapon. If the witness input is "Amos" the detective will output "It was Amos with the candlestick!" If the witness input is "Kevin", the detective will output "It was Kevin with the revolver!" If the witness input is "Juan", the detective will will output "It was Juan with the lead pipe!" Otherwise, the detective will output "We're not sure who that is. We need to investigate further." Example method input: kevin Example method return value: It was Kevin with the revolver! Now create a test method to verify that your method in part(1) works as expected. Each test case should print out the value of the method directly without saving it in a local variable (print the value returned by the method). Try testing various types of capitalization. (2) Complete the following method: * Runs tests to validate the detective's message via the murderMessage method **/ public static void testMurdererMessage() { System.out.println("murdererMessage (\"AMOS\") expected \"It was Amos with the candlestick!\" actual "" + murdererMessage ("AMOS") + """); System.out.println(/* FIX ME */); System.out.println( /* FIX ME */); (3) Call your test method from your main method Before turning in, remember to Style and Comment following the course standards CS 200 Style. Created by Amos - Reviewed by Kevin LAB ACTIVITY 4.17.1: Ch 4 Program, Part 2: Clue Eye Witness Method Clue.java Load default template... Created by Amos - Reviewed by Kevin LAB 4.17.1: Ch 4 Program, Part 2: Clue Eye Witness Method 6190 Clue.java Load default template... 21 import java.util.Scanner; public class Clue{ public static void main(String[] args) { testMurdererMessage(); public static String murderer Message(String murderer) { if (murderer == null) { System.err.println("We're not sure who that is. We need to investigate further."); String message = ""; if (murderer.equalsIgnoreCase("amos") message = "It was Amos with the candlestick!"; else if (murderer.equalsIgnoreCase("kevin" message = "It was Kevin with the revolver!"; else if (murderer.equalsIgnoreCase("juan") message = "It was Juan with the lead pipe!"; else message = "We're not sure who that is. We need to investigate further."; return message; public static void testMurdererMessage() { System.out.println("murdererMessage(\"AMOS") expected \"It was Amos with the candlestick!" actual " + murdererMessage("AMOS") + "\""); System.out.println("murdererMessage(\"KEVIN") expected \"It was Kevin with the revolver!\" actual "" + murdererMessage("KEVIN") + "\""); System.out.println("murdererMessage(\"JUAN") expected \"It was Juan with the lead pipe!\" actual ("" + murdererMessage("JUAN") + "\""); Latest submission - 10:31 PM on 02/19/20 Total score: 6/9 Only show failing tests Download this submission 1: Added Test Methods 2/2 Tests that the murderer Message method is added and used correctly 2: murderer Message unit test A Tests that the murderer Message method returns the correct values for normal inputs 3: File Header Test A 4: murderer Message unit test Tests that the murderer Message method returns the correct values for corner case inputs Your output We're not sure who that is. We need to investigate further. java.lang.NullPointerException 5 previous submissions 10:21 PM on 2/19/20 6/9 View v 10:06 PM on 2/19/20 6/9 View

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions