Scanner Practice Assignments

Overview

One of the most common ways to get input from the user is to use a Scanner object.

Submission Instructions

Submit each of the following practice assignments at codePost.io. To register for a free codePost account, please follow these instructions.
Watch this short video for a demonstration of submitting an assignment and reviewing the results:
YouTube video: codePost: Submission and Checking Results Thumbnail
Note, currently, feedback is not visible in Safari.

Practice Assignments

Scanner: Sum

Write a Java program that outputs your 909-number. Then, have it prompt the user for three (whole) numbers. Use a (single) Scanner object to read these three numbers from the user. Add the numbers together and then display their sum. Save the program in a file named ScannerSum.java.

Examples

Note, user input is in bold face blue and the text that is underlined is required for the test cases.
Example 1
909123456
Please enter the first number: 1
Please enter the second number: 10
Please enter the third number: 100
The sum is 111
Example 2
909123456
Please enter the first number: 3
Please enter the second number: 7
Please enter the third number: 42
The sum is 52

Scanner: Total

Write a Java program that outputs your 909-number. Then, have it calculate the total weight of a group of objects. Do this by prompting the user to enter the average weight then the number of items. Read in the average weight as a real number (double) and the number of items as a whole number (int). Use a (single) Scanner object to read these values from the user. Multiple the values together and display their product. Save the program in a file named ScannerTotal.java.
Example 1
Note, user input is in bold face blue and the text that is underlined is required for the test cases.
909123456
Please enter the average weight: 1.75
Please enter the number of items: 2
The total weight is 3.5
Example 2
909123456
Please enter the average weight: 0.2
Please enter the number of items: 11
The total weight is 2.2

Scanner: Phrase

Write a Java program that outputs your 909-number. Then, have it prompt the user for an inspirational message using a (single) Scanner object. Display the message. Save the program in a file named ScannerPhrase.java.
Example 1
Note, user input is in bold face blue and the text that is underlined is required for the test cases.
909123456
Please enter your favorite inspirational message: Do or do not, there is no try.
You entered: "Do or do not, there is no try"
Example 2
909123456
Please enter your favorite inspirational message: You are loved far more than you know
You entered "You are loved far more than you know"