Ask Question

Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that accept an int, double, or string bid. Each method should display the bid and indicate whether it is over the minimum acceptable bid of $10. If the bid is greater than $10, display Bid accepted. If the bid is less than $10, display Bid not high enough. If the bid is a string, accept it only if one of the following is true: It is numeric and preceded with a dollar sign. It is numeric and followed by the word dollars. Otherwise, display a message that says Bid was not in correct format.

+1
Answers (1)
  1. 1 April, 01:53
    0
    Code implemented on C# below

    Explanation:

    using System;

    using static System. Console;

    using System. Text. RegularExpressions;

    public class Auction

    {

    static void Main ()

    {

    int intbid;

    //declare min bid value

    int min=10;

    //scan input and conver to int

    intbid=Convert. ToInt32 (Console. ReadLine ());

    AcceptBid (intbid, min);

    double doublebid;

    //scan input and conver to double

    doublebid=Double. Parse (Console. ReadLine ());

    AcceptBid (doublebid, min);

    string stringbid;

    //scan string

    stringbid=Console. ReadLine ();

    AcceptBid (stringbid, min);

    }

    public static void AcceptBid (int bid, int min)

    {

    if (bid
    Console. WriteLine ("Bid not high enough");

    else

    Console. WriteLine ("Bid accepted");

    }

    public static void AcceptBid (double bid, int min)

    {

    if (bid
    Console. WriteLine ("Bid not high enough");

    else

    Console. WriteLine ("Bid accepted");

    }

    public static void AcceptBid (string bid, int min)

    {

    //using regular expression check if string is starting with $ and rest all are numbers

    if (bid[0]=='$'&&Regex. IsMatch (bid. Substring (1, bid. Length-1), @"^d+$")) {

    //if input string is in required pattern convert string to int and check for min

    if (Convert. ToInt32 (bid. Substring (1, bid. Length-1))
    Console. WriteLine ("Bid not high enough");

    else

    Console. WriteLine ("Bid accepted");

    }

    else{

    string[] temp = bid. Split (' '); / /will split with ' '

    if (Regex. IsMatch (temp[0]. ToString (), @"^d+$") &&Regex. IsMatch (temp[1]. ToString (),"dollars")) {

    //if input string is in required pattern convert string to int and check for min

    if (Convert. ToInt32 (temp[0]. ToString ())
    Console. WriteLine ("Bid not high enough");

    else

    Console. WriteLine ("Bid accepted");

    }

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a program named Auction that allows a user to enter an amount bid on an online auction item. Include three overloaded methods that ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers