203k views
3 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 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. Grading When you have completed your program, click the Submit button to record your score.

User Cyngus
by
3.1k points

1 Answer

1 vote

Answer:

Step-by-step explanation:

The following code is written in Java and creates the overloaded methods as requested. It has been tested and is working without bugs. The test cases are shown in the first red square within the main method and the output results are shown in the bottom red square...

class Auction {

public static void main(String[] args) {

bid(10);

bid(10.00);

bid("10 dollars");

bid("$10");

bid("150 bills");

}

public static void bid(int bid) {

if(bid >= 10) {

System.out.println("Bid Accepted");

} else {

System.out.println("Bid not high enough");

}

}

public static void bid(double bid) {

if(bid >= 10) {

System.out.println("Bid Accepted");

} else {

System.out.println("Bid not high enough");

}

}

public static void bid(String bid) {

if (bid.charAt(0) == '$') {

if (Integer.parseInt(bid.substring(1, bid.length())) > 0) {

System.out.println("Bid Accepted");

return;

} else {

System.out.println("Bid not in correct Format");

return;

}

}

int dollarStartingPoint = 0;

for (int x = 0; x < bid.length(); x++) {

if (bid.charAt(x) == 'd') {

if (bid.substring(x, x + 7).equals("dollars")) {

dollarStartingPoint = x;

} else {

break;

}

}

}

if (dollarStartingPoint > 1) {

if (Integer.parseInt(bid.substring(0, dollarStartingPoint-1)) > 0) {

System.out.println("Bid Accepted");

return;

} else {

System.out.println("Bid not in correct format");

return;

}

} else {

System.out.println("Bid not in correct format");

return;

}

}

}

Create a program named Auction that allows a user to enter an amount bid on an online-example-1
User Ayush Malviya
by
3.2k points