Can pleas help with this
dfgdfg
[6 byte] By [
chasey1] at [2007-11-11 8:32:34]

# 1 Re: Can pleas help with this
Where are you needing help - with the equals method?
If you are going to do this "right", you need to override the signature of the equals method of java.lang.Object. That method takes an Object as an argument and returns a boolean. Here is some pseudocode for your method.
public boolean equals( Object test )
{
boolean result = false
if ( test is an instanceOf Buyer )
if this.name.equals( test.name ) AND
if this.address.equals( test.address )
result = true
return result
}
nspils at 2007-11-11 22:35:12 >

# 2 Re: Can pleas help with this
hi
i need help with following
This value has a significant influence on the price discount the car dealership will offer the buyer. The class Buyer has an abstract method calculateDiscount (integer carsToBePurchased) and all the classes inheriting from this class must override this method.
how do i do this?
thank u
# 3 Re: Can pleas help with this
In your base class, you will declare the method, including an indication that it is abstract, but not define it.
Then, in any class which extends your parent class, you will have to implement the class - you will declare it, again (but not as an abstract method) with the same signature as in the base class. Now define the method to implement your process - I'd guess that for a certain number of cars, you'll get a certain amount of discount. Good place for a "switch" structure, using the value you've stored in the previousPurchases field, which would be a good argument to your method.
nspils at 2007-11-11 22:37:10 >

# 4 Re: Can pleas help with this
HI
Thank for your help
# 5 Re: Can pleas help with this
Can give some pseudocode for this? , i not 2 sure how to do it
# 6 Re: Can pleas help with this
What is your formula for calculating the discount?
nspils at 2007-11-11 22:40:07 >

# 7 Re: Can pleas help with this
public abstract class buyer{
// ... your code from above
public abstract double calculateDiscount(int carsToBePurchased);
}
this will define your abstract base class. the method calculateDiscount is declared abstract and therefore may not have any code. and a class containing an abstract method has itself to be an abstract class.
to concretize your base class you define eg. a friendly buyer:
public class friendlybuyer extends buyer{
public double calculateDiscount(int carsToBePurchased){
// a car costs 10.000, the freindly one will only pay 90% per car
return carsToBePurchased*10000*0.9;
}
}
all mehtods and attributes from buyer are inherited in this class. the only additional method to be defined is the abstract one.
public class suckingbuyer extends buyer{
public double calculateDiscount(int carsToBePurchased){
// a car costs 10.000, the sucking one will pay 110% per car
return carsToBePurchased*10000*1.1;
}
}
# 8 Re: Can pleas help with this
hi thank for thjat , can help with final bit
here it is
PrivateBuyer inherits from Buyer and represents an individual buyer. It is assumed that this type of buyer purchases one car at a time and so the method buy() has no argument. This type of buyer will get a 10 percent discount if they have previously purchased one or more cars from the dealership.
PrivateBuyer
attributes:
methods:
PrivateBuyer (name, address)
buy()
calculateDiscount(integer carsToBePurchased): integer discount
# 9 Re: Can pleas help with this
So I would expect your implementation of this method in PrivateBuyer could be something like this (depending on your business rules for the discount calculation)...
private int calculateDiscount ()
{
int discount = 100;
// previously purchased 5 or more cars, get 20% discount
if this.previousPurchases >= 5
discount = 80;
// previously purchased 1 to 4 cars, get 10% discount
else if this.previousPurchases < 5 && this.previousPurchases > 0
discount = 90;
return discount;
}
The returned value, when mulitplied by the non-discounted purchase price of the new car and that product is divided by 100, will give the discounted purchase price.
nspils at 2007-11-11 22:43:11 >
