0

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.

AbsoluteSpace
  • 710
  • 2
  • 11
  • 21
Arial
  • 1
  • 1
  • 1
    Create a `Map`: `String` -> `Person` –  Jul 29 '19 at 04:00
  • Use. A. `Map`. https://docs.oracle.com/javase/tutorial/collections/interfaces/map.html – Boris the Spider Jul 29 '19 at 05:54
  • System.out.println("Enter Name:"); String nam = scanner.next(); Map map = new HashMap(); map.put() System.out.println(); I tried this, I feel like Im missing something can you see what im missing? – Arial Jul 31 '19 at 02:24
  • @dyukha System.out.println("Enter Name:"); String nam = scanner.next(); Map map = new HashMap(); map.put() System.out.println(); I tried this, I feel like Im missing something can you see what im missing? – Arial Aug 01 '19 at 02:38

0 Answers0