-
Can pleas help with this
Last edited by chasey1; 05-08-2006 at 05:23 AM.
-
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.
Code:
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
}
Last edited by nspils; 04-24-2006 at 09:57 AM.
-
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
-
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.
-
-
Can give some pseudocode for this? , i not 2 sure how to do it
-
What is your formula for calculating the discount?
-
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;
}
}
-
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
-
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)...
Code:
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.
Similar Threads
-
By luv2fwu in forum Mobile
Replies: 1
Last Post: 04-21-2005, 07:06 PM
-
By Marck in forum Enterprise
Replies: 2
Last Post: 11-26-2001, 02:00 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks