DrinkJavaCodeJava
DrinkJavaCodeJava

Reputation: 808

Little lost on how to organize this in an object oriented manner (attempts included.)

I am kind of new to object oriented programming and I am learning the concepts. Right now I only need help on just logically organizing the classes. The parts about the methods, attributes, and constructors I can figure out. I was assigned this following problem.

Holiday Travel Vehicles sells new recreational vehicles and travel trailers. When new vehicles arrive at Holiday Travel Vehicles, a new vehicle record is created. Included in the new vehicle record are a vehicle serial number, name, model, year, manufacturer, and base cost. When a customer arrives at Holiday Travel Vehicles, he or she works with a salesperson to negotiate a vehicle purchase. When a purchase has been agreed upon, a sales invoice is completed by the salesperson. The invoice summarizes the purchase, including full customer information, information on the trade-­‐in vehicle (if any), the trade-­‐in allowance, and information on the purchased vehicle. If the customer requests dealer-­‐installed options, they are listed on the invoice as well. The invoice also summarizes the negotiated price, plus any applicable taxes and license fees. The transaction concludes with a customer signature on the sales invoice.

So far what I have thought of doing is making an invoice superclass with a customer and vehicle subclass since vehicle information and customer information is on the invoice. However since vehicles get records upon arrival to the dealership, I also thought about making vehicle it's own class with the subclass travel trailer and RV since one involves an engine and one does not. However if I am doing vehicle records and vehicle information in an invoice I can't make vehicle both it's own class and a subclass of invoice.(If everything I am saying does not make sense, I am sorry I am just really confused.) So how should I arrange those classes? I am really lost.

Upvotes: 0

Views: 1203

Answers (3)

mmr
mmr

Reputation: 21

Holiday Travel Vehicles sells new recreational vehicles and travel trailers. When new vehicles arrive at Holiday Travel Vehicles, a new vehicle record is created. Included in the new vehicle record is a vehicle serial number, name, model, year, manufacturer, and base cost. When a customer arrives at Holiday Travel Vehicles, he or she works with a salesperson to negotiate a vehicle purchase. When a purchase has been agreed to, a sales invoice is completed by the salesperson. The invoice summarizes the purchase, including full customer information, information on the trade-in vehicle (if any), the trade-in allowance, and information on the purchased vehicle. If the customer requests dealer-installed options, they will be listed on the invoice as well. The invoice also summarizes the final negotiated price, plus any applicable taxes and license fees. The transaction concludes with a customer signature on the sales invoice.

  1. Identify the data entities described in this scenario (you should find six). Customers are assigned a customer ID when they make their first purchase from Holiday Travel Vehicles. Name, address, and phone number are recorded for the customer. The trade-in vehicle is described by a serial number, make, model, and year. Dealer installed options are described by an option code, description, and price.

  2. Develop a list of attributes for each of the entities. Each invoice will list just one customer. A person does not become a customer until he or she purchases a vehicle. Over time, a customer may purchase a number of vehicles from Holiday Travel Vehicles. Every invoice must be filled out by only one salesperson. A new salesperson may not have sold any vehicles, but experienced salespeople have probably sold many vehicles. Each invoice only lists one new vehicle. If a new vehicle in inventory has not been sold, there will be no invoice for it. Once the vehicle sells, there will be just one invoice for it. A customer may decide to have no options added to the vehicle, or may choose to add many options. An option may be listed on no invoices, or it may be listed on many invoices. A customer may trade in no more than one vehicle on a purchase of a new vehicle. The trade-in vehicle may be sold to another customer, who later trades it in on another Holiday Travel vehicle.

  3. Based on these business rules in force at Holiday Travel Vehicles, draw an ERD and document the relationships with the appropriate cardinality and modality

Upvotes: 2

I can give you one tip, always use inheritance when you noticed that some elements share features, although only share one feature, use inheritance. Now you can only see one common feature, but maybe some day you notice that they share more than one.

Another important thing I can say is that you shouldn't build a hierarchy of elements that aren't relationed, for example, you shouldn't build a superclass vehicle and two subclasses car and horse, maybe you think they share some features but they aren't in the same category of elements, a more studied hierarchy is better in that case.

Another important thing relationed with inheritance is the concept of polymorphism and dynamic binding, very useful.

Hope it could be useful for you,

Upvotes: 0

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26078

Making vehicle and customer a sub-class of invoice doesn't make a whole lot of sense. What I think you want is to make a vehicle class and a customer class, then within your invoice class you can hold an instance of the vehicle object and the customer object it dictates.

public class Invoice {
    private Vehicle MyVehicle;
    private Customer MyCustomer;
    //...etc
}

public class Customer {
    private String FirstName;
    //...etc
}

public class Vehicle{
    private String Model;
    //...etc
}

For travel trailer and RV class it makes more sense to sub-class vehicle since they are in essence a vehicle so will share many common variables with vehicles. The question you need to ask yourself is whether something is something else (an RV is a vehicle), or it points to something (an invoice has a reference to a vehicle). I hope that is clear, it is definitely something I remember struggling with as I first learned it.

Upvotes: 1

Related Questions