How properly handle exceptions in scanner? I have different types of inputs and no idea how avoid, for example InputMisMatchException without using try catch block and without ending program. Many methods with many inputs. How can I resolve this problem and have a clean code? I'm still learning and I'm beginner. Any ideas to short my code? This method seems to be to extensive. I have no experience with refactoring. For example my addPerson method:
private static void addPerson(Scanner scanner) {
System.out.println("name:");
String name = scanner.next();
System.out.println("surname:");
String surname = scanner.next();
System.out.println("age:");
int age = scanner.nextInt();
System.out.println("height (in CM):");
int height = scanner.nextInt();
System.out.println("weight:");
double weight = scanner.nextDouble();
System.out.println("ADDRESS - city:");
String city = scanner.next();
System.out.println("ADDRESS - zipCode:");
String zipCode = scanner.next();
System.out.println("ADDRESS - street:");
String street = scanner.next();
System.out.println("ADDRESS - home number:");
int homeNumber = scanner.nextInt();
Person person = new Person();
person.setName(name);
person.setSurname(surname);
person.setAge(age);
person.setWeight(weight);
person.setHeight(height);
Address address = new Address(city, zipCode, street, homeNumber);
person.setAddress(address);
personService.add(person);
System.out.println("Person added to the base with id: " + person.getId());
}