1 Replies - 146 Views - Last Post: 08 April 2019 - 03:03 PM Rate Topic: -----

#1 sjt99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-April 19

Creating an instance of a class in order to retrieve a singular piece

Posted 08 April 2019 - 02:14 PM

Ok so i can get the auctionID through the a.getAuctionID() and it will return the right id. However the a.getStartPrice has a value set to 0. It has to be declared at the top of my main system class which is why it is setting it to 0. I understand that im using userInput partially in my retrieval of the AuctionID, however i need to be able to collect the start price aswell
Any help






public void bid() 
    {
    // TODO Auto-generated method stub

    int userBid;

    System.out.println(userName);
    browseAuction();
    System.out.println("");
    System.out.println("Please enter the id of the auction you would like to place a bid on?");
    auctionID = userInput.nextInt();        
    //if statement to validate the auction exists

    Auction a = new Auction(auctionID, startPrice, reservePrice, closeDate, item, Status, seller, upperIncrement, lowerIncrement);
    //double upperIncrement = (a.getStartPrice()*1.2);
    //double lowerIncrement = (int) (startPrice*1.1);
    //System.out.println("Me" + upperIncrement + lowerIncrement);
    System.out.println("Startprice " + startPrice);
    a.getStartPrice();
    a.getAuctionID();
    a.getLowerIncrement();
    a.getUpperIncrement();
    System.out.println(a.getStartPrice());

    System.out.println("Auction ID " + a.getAuctionID());
    System.out.println("Lower " + a.getLowerIncrement());
    System.out.println("upper " + a.getUpperIncrement());
    if (auctionID == a.getAuctionID())
        {
            System.out.println(Auctions.get(auctionID));
            System.out.println("Please enter a value between " + a.getLowerIncrement() + " and " + a.getUpperIncrement());
            userBid = userInput.nextInt();
            if (userBid <= a.getUpperIncrement() && userBid >= a.getLowerIncrement()) 
                {
                    System.out.println("Bid accepted and placed");
                    //Store to bids list
                    //Auction.bids.add(new Bid(userBid, user, LocalDateTime.now()));

                }
                else
                {
                    System.out.println("Bid does not meet the upper and lower increment requirements");
                }
        }
        else
        {
            System.out.println("Auction ID not recognised");
        }
    }


public class Auction
    {
    public static List <Bid> bids = new LinkedList<Bid>();
    public int auctionID;
    public double startPrice;
    public double reservePrice;
    public char Status;
    Item item;
    Seller seller;
    double upperIncrement;
    double lowerIncrement;
    public static LocalDateTime closeDate;
    public Auction(int auctionID, double startPrice, double reservePrice, LocalDateTime closeDate, Item item, char Status, Seller seller, double upperIncrement, double lowerIncrement)
    {
        this.auctionID = auctionID;
        this.startPrice = startPrice;
        this.reservePrice = reservePrice;
        this.closeDate = closeDate;
        this.Status = Status;
        this.item = item;
        this.seller = seller;
        this.upperIncrement = (double) 1.2;
        this.lowerIncrement = (double) (getStartPrice()*1.1);

    }
    public String toString()
    {
        String result = auctionID + ": " + "" + startPrice + " " + ""+ reservePrice + " " + closeDate + " " + "item Name: "+ item + " "+ "Status: " + Status +" " + 
"Seller: " + seller +"\n";
        return result;
    }
    public static void placeBid(double bid, String buyer, LocalDateTime date) 
    {
        //bids.add(new Bid(bid, buyer, date));
    }
    public void Verify() 
    {

    }
    public static void Close() 
    {
        System.out.println("checking auctions");
        if (closeDate == LocalDateTime.now())
        {
            systemClass.Auctions.clear();
        }

    }
    public int getAuctionID()
    {
        return auctionID;
    }
    public double getStartPrice()
    {
        return startPrice;
    }
    public double getUpperIncrement()
    {
        return upperIncrement;
    }
    public double getLowerIncrement()
    {
        return lowerIncrement;
    }



Is This A Good Question/Topic? 0
  • +

Replies To: Creating an instance of a class in order to retrieve a singular piece

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3627
  • View blog
  • Posts: 16,660
  • Joined: 20-September 08

Re: Creating an instance of a class in order to retrieve a singular piece

Posted 08 April 2019 - 03:02 PM

Well something has to set the starting price, doesn't it?

This post has been edited by g00se: 08 April 2019 - 03:03 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1