I have created a text.file that a user adds values to. This is the part where the users data gets read and validated. My struggle is that when the user add values when prompted to, it does not return any data. It shows up as zeroes. I must not be returning the values somewhere.
Here are the directions for this section.
"Ask the user if there are any more amounts to add that were not in the text file. Ifso: Use the static methods to read and validate an amount type and an amount Use the instance method to add the amount to one of the totals"
and here is what i have so far. Thanks for any direction and help.
public static char readValidateAmountType()
{
System.out.println("Enter the amount type(T, D, E) you would like to enter: ");
Scanner keyboard = new Scanner(System.in);
char amountType = keyboard.next().charAt(0);
amountType = Character.toUpperCase(amountType);
do
{
if(amountType !='T' && amountType !='D' && amountType !='E')
{
System.out.println("Invalid amount type!");
System.out.println("Enter the amount type(T, D, E) you would like to enter: ");
amountType = keyboard.next().charAt(0);
amountType = Character.toUpperCase(amountType);
}
else
{
return amountType;
}
}
while(amountType !='T' && amountType !='D' && amountType !='E');
return amountType;
}
public static double readValidateAmount()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a dollar amount: ");
amount = keyboard.nextDouble();
if(amount <=0)
{
do
{
System.out.println("Invalid amount!");
System.out.println("Please enter a dollar amount: ");
amount = keyboard.nextDouble();
}
while(amount <=0);
return amount;
}
else
{
return amount;
}
Aucun commentaire:
Enregistrer un commentaire