Create a program in c# named Auction that allows a user to enter an amount bid o
ID: 3753241 • 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
// C# Solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Auction
{
class Program
{
static void Main(string[] args)
{
//set bid amount
string bidamount = "10dollars";
//Check bidamount
//call valid method
if (valid(bidamount))
Console.WriteLine("Bid amount is acceptable.");
else
Console.WriteLine("Bid amount is not in acceptable format.");
Console.ReadKey();
}
//Overload method that takes an integer value
public static bool valid(int bidamount)
{
if (bidamount > 10)
return false;
else
return true;
}
//Overload method that takes an double value
public static bool valid(double bidamount)
{
if (bidamount > 10)
return false;
else
return true;
}
//Overload method that takes string value and check of valid format
//If format is valid then returns true otherwise returns false
public static bool valid(string bidamount)
{
if (bidamount[0] == '$' && Convert.ToInt32(bidamount.Substring(1)) >= 10)
return true;
else if ((Convert.ToInt32(bidamount.Substring(0,2))>=10)
&&(bidamount.Substring(2).Equals("dollars")))
return true;
else
return false;
}//end of valid
}//end of main
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.