10.7k views
2 votes
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.

2 Answers

4 votes

Final answer:

To create the program Auction, we define three overloaded methods that handle different types of bids and check if they meet the minimum acceptable bid criteria.

Step-by-step explanation:

To create the program Auction, we need to define three overloaded methods: one that accepts an int, another that accepts a double, and a third that accepts a string bid. In each method, we check if the bid is greater than the minimum acceptable bid of $10. If it is, we display 'Bid accepted.' If it's less than $10, we display 'Bid not high enough.' If the bid is a string, we check if it meets the required format: numeric and preceded with a dollar sign, or numeric and followed by the word 'dollars.' If it doesn't meet these conditions, we display 'Bid was not in correct format.'

User Vincent Agnus
by
5.2k points
2 votes

Answer:

Code implemented on C# below

Step-by-step 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<min)

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

else

Console.WriteLine("Bid accepted");

}

public static void AcceptBid(double bid, int min)

{

if(bid<min)

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))<min)

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())<min)

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

else

Console.WriteLine("Bid accepted");

}

}

}

}

User Erman Belegu
by
4.9k points