I want to shorten my method, but when doing so some of my variables don't work. Should I do something with the parameters? My user at the bottom auction.makeBid(user, value); is the one that doesn't work.
This is my new method to shorten out the other at the bottom
private User checkUser() {
System.out.println("Enter the name of the user>");
String nameUser = inputToString();
User user = null;
for (User userName : users) {
if (userName.getName().equalsIgnoreCase(nameUser)) {
user = userName;
return user;
}
}
System.out.println("Error: no such user");
return null;
This is where I want to implement the code. At the bottom im supposed to have the variable user.
private void makeBid() {
User u = checkUser();
System.out.println("Enter the name of the dog");
String nameDog = inputToString();
Dog dogsname = null;
for (Dog dogsName : registerDog) {
if (dogsName.getName().equalsIgnoreCase(nameDog)) {
dogsname = dogsName;
break;
}
}
if (dogsname == null) {
System.out.println("Error: this dog is not up for auction");
return;
}
Auction auction = null;
for (Auction auctionsMany : auctions) {
if (auctionsMany.getDog().equals(dogsname)) {
auction = auctionsMany;
break;
}
}
if (auction == null) {
System.out.println("Error no auction");
return;
}
Bid b = auction.getHighestBid();
int min;
if (b == null) {
min = 1;
} else {
min = b.getAmountBid() + 1;
}
int value = 0;
do {
System.out.println("Enter a bid");
value = input.nextInt();
input.nextLine();
if (value < min) {
System.out.println("Error to low bid");
}
} while (value < min);
auction.makeBid(user, value);
System.out.println("Bid made");
}