Am i doing this right?

Hey

Here is the scenario, to Design simple classes that give a model of an e-auction.

At the moment i have user, item and auction. I seem to be having problem with my Auction class which includes the following:

package Auction;

public class Auction {

private User seller;

private String highBidder;//highest bidder will enter bid

private int bid;

private int reservePrice;

private long itemNo;

private Item itemName;

/** Creates a new instance of Auction */

public Auction(User seller, int bid, int reservePrice, long itemNo, Item itemName, String highBidder) {

this.seller = seller;

this.highBidder = highBidder;

this.bid = bid;

this.itemNo = itemNo;

this.itemName = itemName;

reservePrice = 0;

}

//Get seller

public User getSeller()

{

return seller;

}

//Return Bidder

public String gethighBidder()

{

return highBidder;

}

//Return Value of bid

public int getBid()

{

return bid;

}

//Return Item Description

public Item getItemName()

{

return itemName;

}

//Return itemNo

public long getItemNo()

{

return itemNo;

}

//Set Reserve Price

public void setreservePrice()

{

this.reservePrice = reservePrice;

}

public void createBid(String highBidder, int bid)

{

I have tried writing an If statement after public void but i cant seem to get it done. Can any one please help?

Thanks

[1597 byte] By [Mohsina] at [2007-10-2 5:24:18]
# 1

public void createBid(String highBidder, int bid){ // begin method

if ( boolean expression ) {// begin if

// do something...

} // end if

}// end createBid method

you just write your logic with in the braces ( scope ) of the method...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

thanks for the reply, i tried writing this but kept getting "int cannot be dereferenced;

if((bid.getBid() == null) || (bid.getBid() < bid) || (bid.getBid() < reservePrice())) {

setNewBid(new Bid(highBidder, bid));

Can you explain a bit more on how i could use the boolean?

Mohsina at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

looking at your method parameters...

public void createBid(String highBidder, int bid)

you have an int called "bid"...

but you are doing this with the int...

bid.getBid()

so you are trying to treat an int like an object when it's a primative type which gives you that error...

i also see that you have an int declared in your class...

private int bid;

yes you have this code...

new Bid(highBidder, bid)

so what is bid supposed be, a primative type int or an object of class Bid ?

btw, using meaningful variable names will help...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
hi max, i dont have a Bid class, i think there is an error in my class regarding Bid. Basically the "highBidder" which is the person who makes the bid will make a bid, if its higher than the previous bid a new bid amount is printed (which would be int he AuctionTest).
Mohsina at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

regarding " int bid "... is a primative type and does not have methods... you can only assign values use values from it...

example of assignment

private int bid;

// then somewhere in code

bid = 0;

// later in code

int x = 5;

bid = x * 10;

since "bid" is not a class, then where did the method getBid() come from ?

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6
>Here is the scenario, to Design simple classes that give a model of an >e-auction.>At the moment i have user, item and auctionso you have the seller, the item and the auction house... but no buyer...- MaxxDmg...- ' He who never sleeps... '
MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7

Here is what i have at the moment:

A User Class:

public class User {

private String userName;

private String email;

/** Creates a new instance of User */

public User(String UserName, String Email) {

this.userName = UserName;

this.email = Email;

}

//methods

public void setUN(String UserName)

{

this.userName = UserName;

}

public String getUserName()

{

return userName;

}

public void setEM(String Email)

{

this.email = Email;

}

public String getEmail()

{

return email;

}

public String toString()

{

return userName + "@" + email;

}

}

Item class:

public class Item {

private String itemName;

private String itemDescription;

/** Creates a new instance of Item */

public Item(String itemName, String itemDescription) {

itemName = itemName;

itemDescription = itemDescription;

}

public void setItem(String itemName)

{

itemName = itemName;

}

public void setItemDescription(String itemDescription)

{

itemDescription = itemDescription;

}

}

Mohsina at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8
any one spot any problems?
Mohsina at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 9

looking at the code...

itemName = itemName;

itemDescription = itemDescription;

it only reassigns it to the same local variable...

need to add this to assign it to the instance variables...

this.itemName = itemName;

this.itemDescription = itemDescription;

need some getter methods for your Item class...

variable names should have the first letter lower case as good coding style...

though looking at your Auction class method getItemName()

//Return Item Description

public Item getItemName()

{

return itemName;

}

it returns the Item object and not the name as the method denotes... if it's supposed to return a description then you probably want to return a String instead and rename it like getItemDescription use the a getter method in Item class to return the description...

i.e.

public String getItemDescription()

{

return itemName.getDescription();

}

and probably want to do the same with getItemName() method in Auction class...

//Return Item Name

public Item getItemName()

{

return itemName.getName();

}

and you would have to add those getter methods to your Item class...

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 10

oops... lol... that last method declaration should return a String too...

//Return Item name

public String getItemName()

{

return itemName.getName();

}

too funny... :-p

- MaxxDmg...

- ' He who never sleeps... '

MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 11
Hey Max. Thanks for the reply. Do you have an email address? I have compiled an Item Class, User Class and Auction Class. But im not sure whether iv done it right. Do you have an email address or shall i post the code here?
Mohsina at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 12
just post the relevent code snippets that you are having issues with...and you probably need to create a buyer class for the auction... :-p- MaxxDmg...- ' He who never sleeps... '
MaxxDmga at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 13
yes.
vikasgirionlinea at 2007-7-16 1:26:09 > top of Java-index,Java HotSpot Virtual Machine,Specifications...