Question: In java Write a program that will be used to submit bid on items from an online auction site. Each item is available in multiple
In java Write a program that will be used to submit bid on items from an online auction site. Each item is available in multiple lots - for example, there might be 100 boxes of crayons available. Your program must ask users for two important pieces of information:
The price that they are willing to pay for the item, given in dollars and cents.
The quantity of that item that they want to bid on. This quantity must be at least one, and it must be a whole number its not possible to buy fractional parts of an item. Your program should validate the user input for both quantities. To do so, take the following steps:
Price of items
1. Ask the user to type the number of items
2. Read this value into a string 3. Write a routine that will examine the string to verify that it contains a number that can be a legal amount of money. This string must contain:
Some number of integers (possibly zero)
the number of dollars An optional decimal point
Some number of integers (possibly zero)
- the number of cents
There must be at least one digit in the number. Thus, 12.34, 12, and .34, are all valid prices, but 12,34 and . are not. To examine all of the characters in the string, you can the charAt(i) method from the string class. You can check each character in the string to see that it is either a decimal or an integer. You should also check to make sure that there are not multiple decimal points. This routine should return a Boolean value that is true if the string is a legitimate price and false otherwise.
4. If the value provided is not legitimate, print an error message.
5. If the value is legitimate, convert it into a float by using Float f = Float.parseFloat(s); //if s is the string that the user typed.
Number of items: This will be similar to the price, but you must simply check for whole numbers no decimals allowed. The quantity must be greater than or equal to one. You will convert the result to an int (using Integer.parseInt(s)), not a float.
An interactive loop: put these two checks in a loop that will ask for both values, check both to see if they are valid, and then repeat requests for any values that are not valid. The easiest way to do this is probably to have two Boolean values, one for each input quantity. These values will represent the validity of the input quantities. You will stay in an input loop as long as at least one of them is false. When this is the case, you will then check the values to see which is false (i.e., invalid). If a value is not valid, you will repeat the prompt and validate the response. This will continue until both are valid.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
