Create a program in c# named Auction that allows a user to enter an amount bid o
ID: 3733848 • Letter: C
Question
Create a program in c# 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.
Explanation / Answer
using System;
namespace Rextester
{
public class Program
{
public static void fxn(int bid)
{
try{
if( bid <= 10 )
Console.Write("Bid not high enough");
else
Console.Write("Bid accepted");
}
// in case of exception
catch(Exception e)
{
Console.Write("Bid was not in correct format");
}
}
public static void fxn(double bid)
{
try{
if( bid <= 10.0 )
Console.Write("Bid not high enough");
else
Console.Write("Bid accepted");
}
// in case of exception
catch(Exception e)
{
Console.Write("Bid was not in correct format");
}
}
public static void fxn(string bid)
{
try{
// convert string to double
double x = Convert.ToDouble(bid);
if( x <= 10.0 )
Console.Write("Bid not high enough");
else
Console.Write("Bid accepted");
}
// in case of exception
catch(Exception e)
{
Console.Write("Bid was not in correct format");
}
}
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Enter your bid : ");
// read double
double bid = Convert.ToDouble(Console.ReadLine());
fxn(bid);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.