My code is not working and there's errors in "checkValidNumber(momentary_value)" saying that String can not convert to double.
/**
* Add a pokémonCard to collection
*/
public void addPokémonCard()
{
final int INCREMENT = 1;
boolean repeat = true; // a boolean variable return true
// Ask user for details
String name = UI.askString("Name of PokémonCard: ");
if (name.equals("")) {
UI.println("I don't recognise that command");
addPokémonCard();
} else if (name == null ) {
UI.println("Please type a PokémonCard's name: ");
addPokémonCard();
} else {
// Check boundaries for the number of the momentary value of PokémonCard added
do {
String momentary_value = UI.askString("Momentary value: ");
// Check a suitable value of a PokémonCard
if (checkValidNumber(momentary_value)){
double momentary_value1 = Double.parseDouble(momentary_value);
// Increment the PokémonCard ID count and add to hashmap
pokémonCards.setPokémonCardId(); // Increment the id by 1
//add a PokémonCard image to display in the GUI
String imgFileName = UIFileChooser.open("Choose Image File: ");
pokémonCards.addPokémonCard(name, momentary_value1, imgFileName);
UI.println("Added");
repeat = false;
} else if (checkValidNumber(momentary_value) == false) { // Check for invalid value
UI.println("Please input a valid price!");
} else { // Check for invalid value
UI.println("Must be a number!");
}
}while (repeat); //repeat the method again if there's null input
}
}
/**
* Check a valid number for momentary value
* @return boolean false if it's an invalid number
* @param momentary_value for the price of PokemonCard
*/
public boolean checkValidNumber(double momentary_value){
boolean validNumber = false;
if (momentary_value > 0) {
validNumber = true;
}
return validNumber;
}