Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In java Write a program that will be used to submit bid on items from an online

ID: 3880616 • Letter: I

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 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 – it’s 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.

Explanation / Answer

Import java.util.*

public class biditem

{

public static void main()

            {

            Scanner s=new scanner(System.in);

            Int no_of_item;

            String item_name,price;

            do

            {

System.out.println(“Menu”);

System.out.println(“1=Enter number of Items:”);

System.out.println(“2=Enter name of Items:”);

System.out.println(“3=Enter price of Items:”);

System.out.println(“4=Display ”);

System.out.println(“5=Quit:”);

System.out.println(“What is your Input:”);

int input=s.next();

switch(input)

{

case 1:

no_o_item=s.nextInt();

break;

case 2:

item_name=s.next();

break ;

case 3:

            {

price=s.next();

for(int i=0;i<=10;)

{

if(s.charat(i)==’,’)

{

System.out.println(“Invalid Price Entered.Enter Again”);

break;

}

else

i++;

}

case 4:

System.out.println(“Name=” +item_name+”Price=”+price+);

break;

case 5;

break;

}

while(input!=5);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote