14. Asking Questions - Link
- Task
- Output
- Question
It’s now time to pick up the pace a bit. I’ve got you doing a lot of printing so that you get used to typing simple things, but those simple things are fairly boring. What we want to do now is get you getting data into your programs. This though is a little tricky so we have to have you learn to do two things that may not make sense right away, but if you stick with it they should click suddenly a few exercises from now.Most of what software does is the following:
- Take some kind of input from a person.
- Change it.
- Print out something to show how it changed.
AskingQuestions.java
Notice that we used print instead of println. This is so that the program doesn’t end the line with a newline and go to the next line.
15. The Forgetful Machine - Link
- Task
- Answer
- Output
Ask the user for two words and two numbers, and let the person at the keyboard type in some values, but don’t bother storing their responses into any variables.Again, there is no need to create any variables, except for the
Scanner variable typically named keyboard.16. Name, Age, and Salary - Link
- Task
- Answer
- Output
Ask the user for their name. Then display their name to prove that you can recall it. Ask them for their age. Then display that. Finally, ask them for how much they make and display that. You should use the most appropriate data type for each variable.
17. More User Input of Data - Link
- Task
- Answer
- Output
Ask the user for several pieces of information, and display them on the screen afterward as a summary.
- first name
- last name
- grade (classification)
- student id number
- login name
- GPA (0.0 to 4.0)
You must use the most appropriate type for each variable and not just
Stringsfor everything.
18. Age in Five Years - Link
- Task
- Answer
- Output
Ask the user for their name. Then display their name to prove that you can recall it. Ask them for their age. Then display what their age would be five years from now. Then display what their age would be five years ago.
19. A Dumb Calculator - Link
- Task
- Answer
- Output
Make a simple numeric calculator. It should prompt the user for three numbers. Then add the numbers together and divide by 2. Display the result. Your program must support numbers with decimals and not just integers.
20. BMI Calculator - Link
- Task
- Answer
- Bonus
(This assignment was suggested by Joel H in 2012.)The body mass index (BMI) is commonly used by health and nutrition professionals to estimate human body fat in populations.It is computed by taking the individual’s weight (mass) in kilograms and dividing it by the square of their height in meters.