I have a class named "Person". I have some objects for two classes, mark and alexis. I have scanner take an input. Now I want to use the Scanner to take the user input to select one of the classes.
package lesson1;
import java.util.Scanner;
public class MyClass {
public static void main(String[] args) {
Person mark = new Person();
mark.name = "Mark";
mark.age = 22;
mark.height = 70;
mark.eyeColor = "brown";
Person alexis = new Person();
alexis.name = "Alexis";
alexis.age = 26;
alexis.height = 60;
alexis.eyeColor = "blue";
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Name:");
String name = scanner.next();
System.out.println(name.eyeColor);
}
}
I just want the string "name" from the scanner to fill in the blank for my already made classes. Example I want (input from scanner).eyeColor to show on println.
If you type in mark on the input, it would show mark.eyeColor on the output.
The last line is showing an error, there is no name.eyeColor.