@@ -4,18 +4,9 @@ If you ask someone multiple questions you likely will get multiple variables
44worth of information.
55
66``` java,no_run
7- ~import java.util.Scanner;
8- ~
9- ~Scanner scanner = new Scanner(System.in);
10- ~
11- ~String input(String message) {
12- ~ System.out.print(message);
13- ~ return scanner.nextLine();
14- ~}
15- ~
167void main() {
17- String firstName = input ("What is your first name? ");
18- String lastName = input ("What is your last name? ");
8+ String firstName = IO.readln ("What is your first name? ");
9+ String lastName = IO.readln ("What is your last name? ");
1910
2011 System.out.println("Hello " + firstName + " " + lastName + ".");
2112}
@@ -25,19 +16,10 @@ This is fine and dandy so long as you immediately use those variables. But once
2516reprompting logic code can get pretty lengthy.
2617
2718``` java,no_run
28- ~import java.util.Scanner;
29- ~
30- ~Scanner scanner = new Scanner(System.in);
31- ~
32- ~String input(String message) {
33- ~ System.out.print(message);
34- ~ return scanner.nextLine();
35- ~}
36- ~
3719void main() {
3820 String firstName;
3921 do {
40- firstName = input ("What is your first name? ");
22+ firstName = IO.readln ("What is your first name? ");
4123
4224 if (firstName.isBlank()) {
4325 System.out.println("First name cannot be blank.");
@@ -49,7 +31,7 @@ void main() {
4931
5032 String lastName;
5133 do {
52- lastName = input ("What is your first name? ");
34+ lastName = IO.readln ("What is your first name? ");
5335
5436 if (lastName.isBlank()) {
5537 System.out.println("First name cannot be blank.");
@@ -69,15 +51,6 @@ I mention all this as a reminder that when you want to return multiple values fr
6951you can use a class.[ ^ dto ]
7052
7153``` java,no_run
72- ~import java.util.Scanner;
73- ~
74- ~Scanner scanner = new Scanner(System.in);
75- ~
76- ~String input(String message) {
77- ~ System.out.print(message);
78- ~ return scanner.nextLine();
79- ~}
80- ~
8154class Person {
8255 String firstName;
8356 String lastName;
@@ -91,7 +64,7 @@ class Person {
9164Person askForName() {
9265 String firstName;
9366 do {
94- firstName = input ("What is your first name? ");
67+ firstName = IO.readln ("What is your first name? ");
9568
9669 if (firstName.isBlank()) {
9770 System.out.println("First name cannot be blank.");
@@ -103,7 +76,7 @@ Person askForName() {
10376
10477 String lastName;
10578 do {
106- lastName = input ("What is your first name? ");
79+ lastName = IO.readln ("What is your first name? ");
10780
10881 if (lastName.isBlank()) {
10982 System.out.println("First name cannot be blank.");
0 commit comments