2
\$\begingroup\$

An exam requires me to create a program for an interactive board for an auction:

An auction company has an interactive auction board at their sale rooms, which allows buyers to place bids at any time during the auction. Before the auction starts, the sellers place their items in the sale room with a unique number attached to each item (item number). The following details about each item need to be set up on the interactive auction board system: item number, number of bids, description and reserve price. The number of bids is initially set to zero. During the auction, buyers can look at the items in the sale room and then place a bid on the interactive auction board at the sale room. Each buyer is given a unique number for identification (buyer number). All the buyer needs to do is enter their buyer number, the item number and their bid. Their bid must be greater than any existing bids. At the end of the auction, the company checks all the items and marks those that have bids greater than the reserve as sold. Any items sold will incur a fee of 10% of the final bid to be paid to the auction company. Write and test a program or programs for the auction company.

  • Your program or programs must include appropriate prompts for the entry of data, data must be validated on entry.
  • Error messages and other output need to be set out clearly and understandably.
  • All variables, constants and other identifiers must have meaningful names.

You will need to complete these three tasks. Each task must be fully tested.

Task 1 – Auction set up.

For every item in the auction the item number, description and the reserve price should be recorded. The number of bids is set to zero. There must be at least 10 items in the auction.

Task 2 – Buyer bids.

A buyer should be able to find an item and view the item number, description and the current highest bid. A buyer can then enter their buyer number and bid, which must be higher than any previously recorded bids. Every time a new bid is recorded the number of bids for that item is increased by one. Buyers can bid for an item many times and they can bid for many items.

Task 3 – At the end of the auction.

Using the results from TASK 2, identify items that have reached their reserve price, mark them as sold, calculate 10% of the final bid as the auction company fee and add this to the total fee for all sold items. Display this total fee. Display the item number and final bid for all the items with bids that have not reached their reserve price. Display the item number of any items that have received no bids. Display the number of items sold, the number of items that did not meet the reserve price and the number of items with no bids.

Here's my solution in VB.net console. How could I have done it better?

'Task 1'
Dim enteries, d As Integer
d = 1

Console.WriteLine("How many total entries?")
enteries = Console.ReadLine
While enteries < 10
    Console.WriteLine("Number of enteries should be greater than 10, please try again")
    enteries = Console.ReadLine
End While
Dim item_num(enteries), num_bids(enteries) As Integer
Dim reserve_price(enteries) As Single
Dim description(enteries) As String
For c = 1 To enteries
    Console.WriteLine("Enter item description")
    description(c) = Console.ReadLine
    Console.WriteLine("Enter the item number")
    item_num(c) = Console.ReadLine
    Console.WriteLine("Enter reserve price") 'The reserve price is the minimum amount the seller is willing to accept' 
    reserve_price(c) = Console.ReadLine
    num_bids(c) = 0
Next
For c = 1 To enteries
    For d = 1 To enteries - 1
        If item_num(d) = item_num(d + 1) Then
            While item_num(d) = item_num(d + 1)
                Console.Write("Value " & d + 1)
                Console.WriteLine(" Is duplicate, enter a new value")
                item_num(d + 1) = Console.ReadLine
            End While
        End If
    Next
Next
'Task 2'
Dim buyer_num(enteries) As Integer
Dim bid(enteries), highest(enteries) As Single
Dim extra_bids As String
For c = 1 To enteries
    Console.WriteLine("Enter number of the item from 1-" & enteries)
    d = Console.ReadLine
    Console.WriteLine("Product is: " & description(d))
    Console.WriteLine("Item number is: " & item_num(d))
    Console.WriteLine("Current highest bid: " & bid(d))
    Console.WriteLine("Enter buyer number")
    buyer_num(d) = Console.ReadLine
    Console.WriteLine("Enter your bid")
    bid(d) = Console.ReadLine
    If bid(d) > highest(d) Then
        highest(d) = bid(d)
    End If
    num_bids(d) = num_bids(d) + 1
    Console.WriteLine("Make more bids? Enter Yes/No")
    extra_bids = Console.ReadLine
    While extra_bids = "Yes"
        Console.WriteLine("Current highest bid is " & highest(c))
        Console.WriteLine("Enter bid")
        bid(d) = Console.ReadLine
        If bid(d) > highest(d) Then
            highest(d) = bid(d)
        Else
            While bid(d) < highest(d)
                Console.WriteLine("Bid cannot be less than the previous bid, please enter a higher value")
                bid(d) = Console.ReadLine
            End While
            highest(d) = bid(d)
        End If
        Console.WriteLine("Make more bids? Enter Yes/No")
        extra_bids = Console.ReadLine
    End While
Next
'Task 3'
Dim final_price(enteries), comp_fee(enteries), total_fee As Single
Dim items_sold, not_sold, no_bids As Integer
Dim sold_status(enteries) As String
For c = 1 To enteries
    If highest(c) >= reserve_price(c) Then
        sold_status(enteries) = "Sold"
        comp_fee(c) = 10 / 100 * highest(c)
        final_price(c) = highest(c) + comp_fee(c)
        total_fee = total_fee + final_price(c)
        items_sold = items_sold + 1

    Else
        not_sold = not_sold + 1
        Console.WriteLine(item_num(c) & " Did not reach reserve price")
        Console.WriteLine("Their final bid was " & highest(c))
    End If
    If num_bids(c) = 0 Then
        Console.WriteLine(item_num(c) & "recieved no bids")
        no_bids = no_bids + 1
    End If
Next
Console.WriteLine("Total fee for all sold items is " & total_fee)
Console.WriteLine("Number of items sold = " & items_sold)
Console.WriteLine("Number of items not sold = " & not_sold)
Console.WriteLine("Number of items with no bids = " & no_bids)
Console.ReadKey()
\$\endgroup\$
2
\$\begingroup\$

Okay, so I'll admit I am a little bit rusty right now on some best practices, but I'm doing this anyway.

First, this whole thing needs to be wrapped in a sub I assume.

Second, when I read the description of what you need to create, it screams at me "objects!" - what I mean is that you have an interactive app that needs to keep track of auction items. Each item has several attributes. Sounds like the basis for some object-oriented design doesn't it? e.g.

Public Class AuctionItem
    Public Property description As String
    Public Property reservePrice As Integer
    Public Property numberOfBids As Integer
    Public Property currentBid As Integer
    Public Property currentBidder As Integer
End Class

So right out of the gate, now you have a structure for the items at the auction, before doing anything else. And each item has properties. And now you just handle a list of the room you're talking about

Dim firstRoom As New List(Of AuctionItem)

Ignoring the minimum entry requirement, you could simply create your auction on the fly -

    Dim firstRoom As New List(Of AuctionItem)
    Dim numberOfEntries As Integer
    Console.WriteLine("How many total entries?")
    numberOfEntries = Console.ReadLine
    For i As Integer = 1 To numberOfEntries
        firstRoom.Add(New AuctionItem)
        Console.WriteLine("Enter item description")
        firstRoom(i).description = Console.ReadLine
        Console.WriteLine("Enter reserve price") 'The reserve price is the minimum amount the seller is willing to accept' 
        firstRoom(i).reservePrice = Console.ReadLine
    Next

See what I mean? Now you assign the item number and when a bidder wants to bid on it, you just access that object and get what you need.

Another small thing I noted is that you aren't type checking entries - say I want to say my item number is "two" - the program throws an unhandled error and crashes. You expect an integer, so you need to check you receive an integer.

Sorry, that's all I got right now.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.