Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA I need help, my code doesn't want to run. I have them in 2 files, the first is Lot.java and the second is Auction.java
JAVA
I need help, my code doesn't want to run.
I have them in 2 files, the first is Lot.java and the second is Auction.java
I also tried changing Lot.java to Main.java and it didn't work.
Main.java
import java.util.ArrayList; import java.util.Scanner; class Lot { private static int nextLotNumber = 1001; private int lotNumber; private String description; private int currentBid; private int bidIncrement; private boolean sold; public Lot() { lotNumber = nextLotNumber++; description = "Unknown Item"; currentBid = 0; bidIncrement = 0; sold = false; } public Lot(String description, int startingBid, int bidIncrement) { lotNumber = nextLotNumber++; this.description = description; currentBid = startingBid; this.bidIncrement = bidIncrement; sold = false; } public void markSold() { sold = true; } public boolean isSold() { return sold; } public int getBidIncrement() { return bidIncrement; } public String getDescription() { return description; } public void setCurrentBid(int currentBid) { this.currentBid = currentBid; } public int nextBid() { return currentBid + bidIncrement; } @Override public String toString() { if (sold) { return "Lot " + lotNumber + ". " + description + " was sold for $" + currentBid; } else { return "Lot " + lotNumber + ". " + description + " current bid $" + currentBid + " minimum bid $" + nextBid(); } } }
Auction.java
class Auction { private static ArrayListlots = new ArrayList (); private static Scanner scanner = new Scanner(System.in); public static Lot getNextLot(ArrayList lots) { if (lots.size() > 0) { Lot nextLot = lots.get(0); lots.remove(0); return nextLot; } else { return new Lot(); } } public static void addItem(ArrayList lots) { System.out.print("Enter description: "); String description = scanner.nextLine(); System.out.print("Enter starting bid: "); int startingBid = scanner.nextInt(); System.out.print("Enter bid increment: "); int bidIncrement = scanner.nextInt(); scanner.nextLine(); lots.add(new Lot(description, startingBid, bidIncrement)); } public static void bid(Lot lot) { System.out.print("Enter bid: "); int bid = scanner.nextInt(); scanner.nextLine(); if (bid >= lot.nextBid()) { lot.setCurrentBid(bid); } else { System.out.println("Bid must be at least $" + lot.nextBid()); } } public static void markSold(Lot lot) { }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started