'F' → Fullscreen
import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
}}import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Age to Months Calculator ---");
System.out.print("Enter your age: "); int age = input.nextInt();
System.out.println("You are " + age + " years old. That's " + (age * 12) + " months old!");
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();// }}import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Age to Months Calculator ---");
System.out.print("Enter your age: "); int age = input.nextInt();
System.out.println("You are " + age + " years old. That's " + (age * 12) + " months old!");
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 2 - Square Area Calculator ---");
System.out.print("Enter the length of the square: "); double length = input.nextDouble();
double area = length * length; System.out.println("The area of the square is " + area);
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();// }}import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Age to Months Calculator ---");
System.out.print("Enter your age: "); int age = input.nextInt();
System.out.println("You are " + age + " years old. That's " + (age * 12) + " months old!");
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 2 - Square Area Calculator ---");
System.out.print("Enter the length of the square: "); double length = input.nextDouble();
double area = length * length; System.out.println("The area of the square is " + area);
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 3 - Score Calculator ---");
System.out.print("Enter the score for game 1: "); int score1 = input.nextInt(); System.out.print("Enter the score for game 2: "); int score2 = input.nextInt(); System.out.print("Enter the score for game 3: "); int score3 = input.nextInt();
int totalScore = score1 + score2 + score3; System.out.println("The total score for the games is " + totalScore);
input.nextLine(); System.out.print("Press Enter to continue..."); input.nextLine();// }}import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Age to Months Calculator ---");
System.out.print("Enter your age: "); int age = input.nextInt();
System.out.println("You are " + age + " years old. That's " + (age * 12) + " months old!");
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 2 - Square Area Calculator ---");
System.out.print("Enter the length of the square: "); double length = input.nextDouble();
double area = length * length; System.out.println("The area of the square is " + area);
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 3 - Score Calculator ---");
System.out.print("Enter the score for game 1: "); int score1 = input.nextInt(); System.out.print("Enter the score for game 2: "); int score2 = input.nextInt(); System.out.print("Enter the score for game 3: "); int score3 = input.nextInt();
int totalScore = score1 + score2 + score3; System.out.println("The total score for the games is " + totalScore);
input.nextLine(); System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 4 - Shopping Cart Subtotal ---");
System.out.print("Enter the price of the first item: "); double item1Price = input.nextDouble(); System.out.print("Enter the price of the second item: "); double item2Price = input.nextDouble();
double subtotal = item1Price + item2Price; System.out.println("The subtotal is $" + subtotal);
// Try this to force the subtotal to two decimal places. // System.out.println(String.format("The subtotal is $%.2f", subtotal));
input.nextLine(); System.out.print("Press Enter to continue..."); input.nextLine();// }}import java.util.Scanner;
public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in);
System.out.println("--- Demo 1 - Age to Months Calculator ---");
System.out.print("Enter your age: "); int age = input.nextInt();
System.out.println("You are " + age + " years old. That's " + (age * 12) + " months old!");
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 2 - Square Area Calculator ---");
System.out.print("Enter the length of the square: "); double length = input.nextDouble();
double area = length * length; System.out.println("The area of the square is " + area);
input.nextLine(); // Consume leftover \n [Enter] from numeric input System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 3 - Score Calculator ---");
System.out.print("Enter the score for game 1: "); int score1 = input.nextInt(); System.out.print("Enter the score for game 2: "); int score2 = input.nextInt(); System.out.print("Enter the score for game 3: "); int score3 = input.nextInt();
int totalScore = score1 + score2 + score3; System.out.println("The total score for the games is " + totalScore);
input.nextLine(); System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 4 - Shopping Cart Subtotal ---");
System.out.print("Enter the price of the first item: "); double item1Price = input.nextDouble(); System.out.print("Enter the price of the second item: "); double item2Price = input.nextDouble();
double subtotal = item1Price + item2Price; System.out.println("The subtotal is $" + subtotal);
// Try this to force the subtotal to two decimal places. // System.out.println(String.format("The subtotal is $%.2f", subtotal));
input.nextLine(); System.out.print("Press Enter to continue..."); input.nextLine();
// -----------------------------------------------------------------------------
System.out.println("\n--- Demo 5 - Hours to Minutes Converter ---");
System.out.print("Enter a number of hours: "); int hours = input.nextInt(); int minutes = hours * 60;
System.out.println(hours + " hours is equal to " + minutes + " minutes.");// }}Your program output should something similar to the sample output below.
--- Demo 1 - Age to Months Calculator ---Enter your age: 35You are 35 years old. That's 420 months old!Press Enter to continue...
--- Demo 2 - Square Area Calculator ---Enter the length of the square: 12.5The area of the square is 156.25Press Enter to continue...
--- Demo 3 - Score Calculator ---Enter the score for game 1: 76Enter the score for game 2: 45Enter the score for game 3: 32The total score for the games is 153Press Enter to continue...
--- Demo 4 - Shopping Cart Subtotal ---Enter the price of the first item: 13.12Enter the price of the second item: 14.28The subtotal is $27.4Press Enter to continue...
--- Demo 5 - Hours to Minutes Converter ---Enter a number of hours: 1111 hours is equal to 660 minutes.You may write your reflection answers as comments at the bottom of your code.
Scanner.nextInt() method versus the Scanner.nextDouble() method? Give one specific example for each.
\n character with
Scanner.nextLine() after using numeric input methods? What would happen if you forgot
to include this step in a program that also needed to read a string?
Submit your activity and reflection answers to the appropriate dropbox.