Using Console
In this program, you will use the Scanner class and
System.out object to perform console I/O. In the main method,
you will:
- Read two integers
- Read the user's name
- Read a double
- Display the following: the user's name, the sum of the two integers, and the sum multiplied by the double.
You can copy the following class skeleton into a new class file to start with.
// Import the Scanner class from the Java library here.
public class Lab2
{
// Declare a Scanner reference variable and create
// a Scanner object here.
// Note that this reference will have class scope.
// Define and implement an add( ) method here.
// add( ) returns the sum of two integers.
// Define and implement a product( ) method here.
// product( ) returns the product of two doubles.
public static void main( String[ ] args)
{
// Prompt for and read in two integers.
// Prompt for and read in the user's name.
// Note that the user's name may contain spaces.
// Prompt for and read in a double.
// Display the user's name with an appropriate label.
// Call the add( ) helper method here.
// Display its return value with an appropriate label.
// Call the product( ) helper method here.
// Display its return value with an appropriate label.
}
}