Ask Question
10 April, 12:55

Clue Eye Witness The goal of this problem is to practice using appropriate branching statements. You will add to the main method to take in user input and output a message based on the input. This program 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!"

+5
Answers (1)
  1. 10 April, 16:27
    0
    The Complete Question:

    The goal of this problem is to practice using appropriate branching statements. You will add to the main method to take in user input and output a message based on the input. This program 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." Your program should also handle situations where the witness input does not use proper-case. Hint: look at the toUpperCase () or equalsignoreCase () method for Strings. Example input: amos Example output: It was Amos with the candlestick! 2 import java. util. Scanner; public class Clue{ public static void main (String[] args) { Scanner scnr = new Scanner (System. in); System. out. println ("Who was the murderer?");

    Answer:

    import java. util. Scanner;

    public class detective {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Who was the murderer?");

    String name = in. next ();

    if (name. equalsIgnoreCase ("amos")) {

    System. out. println ("It was Amos with the candlestick!");

    }

    else if (name. equalsIgnoreCase ("kevin")) {

    System. out. println ("It was Kevin with the revolver!");

    }

    else if (name. equalsIgnoreCase ("juan")) {

    System. out. println ("It was Juan with the lead pipe!");

    }

    else{

    System. out. println ("We're not sure who that is. We need to investigate further");

    }

    }

    }

    Explanation:

    1. Prompt user for input Using Scanner class

    2. Save user input in a variable (name)

    3. Using if and else test if name entered is equal to Amos, Kevin or Juan

    4. Use String method equalsIgnoreCase

    5. output appropriate message if name entered is equal to any of the three
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Clue Eye Witness The goal of this problem is to practice using appropriate branching statements. You will add to the main method to take in ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers