This program will ask a user to enter their favorite color. Your program will tell the user what their “spirit animal” is based on the color entered. (Or you can do something similar but different – like online quizzes that tell you what kind of potato you are.) You will create a static method called getAnimal that takes in a single String and returns a String. In this method, you will write the code that will determine which animal gets returned. You may choose the possible colors and animals (or you may choose something else ridiculous for this program) but you must have at least 4 options for the user. For example, if they enter “red”, you might return “Tiger”. Make sure to include a response for incorrect inputs. In the main method you will give the program explanation, ask for input (favorite color), capture the input, call the getAnimal method (passing in the user’s input), and print the result. No try/catch blocks or loops are necessary. The static method should contain no print statements or requests for user input. It’s only task is to determine which animal string should be returned based on the user’s number. Example: What is your favorite color? (Select from red, green, blue, yellow, or black) I will tell you what your animal is. >>>red Tiger **************************************************************** What is your favorite color? (Select from red, green, blue, yellow, or black) I will tell you what your animal is. >>>YELLOW Does not compute. in java
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
-
This
program will ask a user to enter their favorite color. Your program will tell the user what their “spirit animal” is based on the color entered. (Or you can do something similar but different – like online quizzes that tell you what kind of potato you are.) -
You will create a static method called getAnimal that takes in a single String and returns a String. In this method, you will write the code that will determine which animal gets returned. You may choose the possible colors and animals (or you may choose something else ridiculous for this program) but you must have at least 4 options for the user. For example, if they enter “red”, you might return “Tiger”. Make sure to include a response for incorrect inputs.
-
In the main method you will give the program explanation, ask for input (favorite color), capture the input, call the getAnimal method (passing in the user’s input), and print the result.
-
No try/catch blocks or loops are necessary.
-
The static method should contain no print statements or requests for user input. It’s only task is to determine which animal string should be returned based on the user’s number.
Example:
What is your favorite color? (Select from red, green, blue, yellow, or black) I will tell you what your animal is.
>>>red
Tiger
****************************************************************
What is your favorite color? (Select from red, green, blue, yellow, or black) I will tell you what your animal is.
>>>YELLOW
Does not compute.
in java
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images