Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

here is the question C# cengage mindtap reate a program named Auction that allows a user to enter an amount bid on an online auction

here is the question C# cengage mindtap

reate a program named Auctionthat 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 or equal to $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.

here's my code it says I'm wrong

using System;

//solution class for the program

class Solution {

// Method overloading below

public static void Auction(int val){ //method with int parameter

//check conditions for bid

if (val >= 10){

Console.WriteLine("Bid accepted.");

}

else{

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

}

}

public static void Auction(double val){ //method with double parameter

//check conditions for bid

if (val >= 10.00){

Console.WriteLine("Bid accepted.");

}

else{

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

}

}

public static void Auction(string val){ //method with string parameter

//check for numeric value in string

bool isNumber1=isNumeric(val.Substring(1));

bool isNumber2=isNumeric(val.Substring(0,val.Length-1));

//check conditions for bid

if ((val.StartsWith("$") && isNumber1) || (val.EndsWith("$") && isNumber2)){

Console.WriteLine("Bid accepted.");

}

else{

Console.WriteLine("Bid was not in correct format.");

}

}

//function to check if string in numeric

public static bool isNumeric(string str){

//check each character of string

foreach (char ch in str){

if ( !Char.IsNumber(ch) ){

return false;

}

}

return true;

}

//main method implementation for testing purpose

public static void Main() {

//create all possible values of Bid

int bid1=12, bid2=9;

double bid3=17.5, bid4=9.99;

string bid5="$15", bid6="15$", bid7="bid15";

//make all the function calls for testing purpose

Auction(bid1);

Auction(bid2);

Auction(bid3);

Auction(bid4);

Auction(bid5);

Auction(bid6);

Auction(bid7);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago