You can convert an char
to an int
in Java by subtracting their absolute ASCII values. Below is a method that returns the product of the integer values of each character in a String (useful for ride.java
):
public static int makeNumber(String name) {
int product = 1;
//iterate through each character in the String name
for (int i = 0; i < name.length(); i++) {
//get the character value
int charVal = (name.charAt(i) - 'A') + 1;
//multiply the product by the character value
product *= charVal;
}
return product;
}
}