I would greatly appreciate any help with my Programming project - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I would greatly appreciate any help with my Programming project

StevesyStevesy Posts: 3Member
http://cs.utsa.edu/~cs1713/projects/project2Fall10.pdf

That is my project that I've just started. I would like to thank anyone in advance for any help.

I'm still on part 1 right now. my first question is about the Vehicle class. I'm supposed to include the method [b]public abstract String getType();[/b]
--since it's an abstract method, the Vehicle class would have to abstract itself, correct? if the Vehicle class is abstract, then how can I instantiate Vehicle object in the VehicleTester class? I thought you were allowed to instantiate objects from abstract classes, yet the instructions include "[italic]test the Vehicle and Car classes by constructing several instances of
vehicles and cars, and printing enough information to test the accessor and toString
methods of these classes."[/italic]

My second question is about the method [b]public int compareMakeTo(Vehicle other)[/b] which compares two vehicles on the alphabetic order of their makes. I'm not exactly sure how I'm supposed to compare the strings. right now i return [italic]getMake().compareTo(other.getMake());[/italic], though I really don't know if that's right...

Again, thanks for any help. I might have a few more questions in the future.

Comments

  • exile_acexile_ac Posts: 7Member
    Straight from java's website: If a class includes abstract methods, the class itself must be declared abstract, as in:
    [code]
    public abstract class GraphicObject {
    // declare fields
    // declare non-abstract methods
    abstract void draw();
    }[/code]

    Since the vehicle class is abstract, when creating a new vehicle simply extend the new vehicle class as an vehicle, ex:
    [code]
    public class Toyota extends Vehicle
    {
    ...code
    }[/code]
    In your testing code you wouldnt instantiate the vehicle class directly, you would instantiate toyota, honda, etc.


    Now as for the compare method you could do something like:
    [code]
    public bool compareMake(Vehicle make)
    {
    //assuming getMake() returns a string value
    if(this.getMake().equals(make.getMake())
    return true;
    else
    return false;
    }[/code]
  • StevesyStevesy Posts: 3Member
    Thank you fine sir!
Sign In or Register to comment.