Can pleas help with this


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: Can pleas help with this

  1. #1
    Join Date
    Apr 2006
    Posts
    8

    Can pleas help with this

    dfgdfg
    Last edited by chasey1; 05-08-2006 at 06:23 AM.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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 10:57 AM.

  3. #3
    Join Date
    Apr 2006
    Posts
    8
    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

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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.

  5. #5
    Join Date
    Apr 2006
    Posts
    8
    HI
    Thank for your help

  6. #6
    Join Date
    Apr 2006
    Posts
    8
    Can give some pseudocode for this? , i not 2 sure how to do it

  7. #7
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What is your formula for calculating the discount?

  8. #8
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    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;
    }
    }

  9. #9
    Join Date
    Apr 2006
    Posts
    8
    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

  10. #10
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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

  1. Pleas help me with this!!
    By luv2fwu in forum Mobile
    Replies: 1
    Last Post: 04-21-2005, 08:06 PM
  2. Replies: 2
    Last Post: 11-26-2001, 03: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center