So I've been trying to write a program where it will be able to get any integer from a string input despite it's length. I've only been able to get it if the length of the integer is 1. Here is my code so far with methods from another class I wrote.
Scanner input = new Scanner(System.in);
Object user1 = new Object();
String user1Input = null;
System.out.println("Please enter coins");
user1Input = input.nextLine();
while(!(user1Input.contains("end"))){
if(user1Input.contains("Quarters")){
user1.depositQuarters(Character.getNumericValue(user1Input.charAt(0)));
}
}
So this code I have so far, say I enter "2 Quarters" it will return me the balance of $0.50 But if I enter "20 Quarters" it will return me $0.50 as well. I have tried another way of having declaring another variable
System.out.println("Please enter coins");
int coins = input.nextInt();
String user1Input = input.nextLine();
And then the same while loop with if-statements follows this and returns an error. Any help would be appreciated. Thanks