This repository has been archived on 2025-12-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-09-20 14:17:13 +03:00

29 lines
941 B
Java

import data.Hedgehog;
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Boolean exit = false;
Scanner sc = new Scanner(System.in);
System.out.println("Give a name to the hedgehog: ");
String name = sc.nextLine();
Hedgehog hedgehog = new Hedgehog(name);
System.out.println(hedgehog.speak());
while (!exit) {
System.out.println("What should the hedgehog say?");
String inp = sc.nextLine();
try {
Integer inp2 = Integer.parseInt(inp);
System.out.println(hedgehog.speakInt(inp2));
} catch (NumberFormatException e) {
if ("exit".equals(inp)) {
exit = true;
sc.close();
} else {
System.out.println(hedgehog.speakString(inp));
}
}
}
}
}