Java Bootcamp – Workbooks and Challenges
)}
Variables (Challenge)

Chatbot

A chatbot is an application that talks to the user. You're going to build an app that carries a simple conversation.

Open the challenge


From Java-Bootcamp-Resources -> Module 1 - Introduction to Java -> 2. Variables, open Challenge 2.

1. Store each answer.


After each question, add code that picks up the user's answer and stores it.

Careful from the nextLine() trap


  • nextLine() gets "skipped" if you put it ahead of nextInt() , nextDouble(), nextLong(). You can expect this behaviour when you try to pick up the user's favorite language.

  • You will understand why this happens when we cover Delimiters in the next section (Booleans and Conditionals).

  • The solution is to add a throwaway scan.nextLine() before the "real" scan.nextLine().

2. Update each reply.


Update each reply with the user's answer.

3. Run your code.


Why is the cat scared?

The screaming cat appears when something's wrong or looks bad. In this case, the output is very messy. There should be a line of spacing between each answer and reply (see arrows).

4. Add a new line


Before every reply, add a new line.

Follow the comments to guide your code.

Final output:

Good luck!


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.