Question: The following do - while loop is suppose to ask the price for a gallon of gas. The price must a positive number. The price
The following dowhile loop is suppose to ask the price for a gallon of gas. The price must a positive number. The price can be an integer value or a double value. for example the price can be or or
To create a robust program, we must do the data validation and as long as the user is entering a negative value or a String, the program must keep asking the user to enter a valid input.
in this program you need to use some of the scanner methods listed here, make sure to use the proper ones: hasNextInt hasNextDouble hasNextLine hasNext nextInt nextDouble nextLine
Must flush the buffer at the proper locations in the code
sample output:
Enter the price for a gallon of gas: dfdfdf
Enter the price for a gallon of gas: sadfdf
Enter the price for a gallon of gas:
Enter the price for a gallon of gas:
Enter the price for a gallon of gas:
The price you entered is a valid amount
Fill in the blank so that the dowhile loop works based on the given description:
Must use a dowhile and some conditional statements
double price ;
Systemout.printEnter the price for a gallon of gas: ;
ifkbhasNextDouble kb
kb ; flush the buffer
else
price kb ;
kb ; flush the buffer
;
Systemout.printlnThe price price you entered is a valid amount";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
