473,465 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Java Inheritance woes

5 New Member
Hello All,
Still new to Java but got pass the messing around phase and am actually starting on a Project. What I'm trying to do is build a Application that will let me keep track of my flights (I'm a pilot). My background, I had a similar system in MS Access but i'm trying to get away from Microsoft all together. I am fairly knowledgeable in Database, which might be think of ideas that aren't really possible with Java, well atleast not without extensive coding.

Anyways on to the question.

What I itend to do is have a class called Aircraft_Type or such which would have a String for the name of the type and a double for the hourly pay rate for that type. and possbile other things about it, but thats all I can think of for the moment.

Then I would have another class lets say called Aircraft which would I guess would be a subclass of Aircraft_Type which it would have an actual Aircraft Name and then it would have an Aircraft_type with it.

So I would have two types of Aircraft

Type A which pays 10.00 to fly
and
Type B which pays 12.50 to fly

Then lets say I have
Airplane_X which is Type A
Airplane_Y which is Type A
Airplane_W which is Type_B

so when I create Airplane_X and tell its Type_A will it automactically fill attach all the descriptors of aircraft_type A to it? Or is that something that I would have to write in the constructor to search the Aircraft Types then copy them over. Which I would think would be cumbersome when writing to the File since all i would really want to write for each flight is that its Airplane_x not Airplane_x which is type_a which pays 10.00 etc.

Thoughs on how to best do this?
Casey
Sep 30 '10 #1

✓ answered by pbrockway2

It sounds like an Aircraft instance HAS-An AircraftType rather than IS-An AircraftType. In that case the type would most natuarally be an instance variable of the aircraft (rather than being a parent class of it.)

Expand|Select|Wrap|Line Numbers
  1. class Aircraft {
  2.     private AircraftType type;
  3.     private String name;
  4.  
  5.     public Aircraft(String name, AircraftType type) {
  6.         // etc
  7. }
As for AircraftType: if there are a small number of these (each with their own name and hourly rate) you might want to consider an enum.

Enum types in Oracle's Tutorial gives a couple of examples. The second (the Planet enum) is rather like your AircraftType in that there are a handful of different planets each having a mass and radius just as your aircraft types each have a name and cost.

2 1502
pbrockway2
151 Recognized Expert New Member
It sounds like an Aircraft instance HAS-An AircraftType rather than IS-An AircraftType. In that case the type would most natuarally be an instance variable of the aircraft (rather than being a parent class of it.)

Expand|Select|Wrap|Line Numbers
  1. class Aircraft {
  2.     private AircraftType type;
  3.     private String name;
  4.  
  5.     public Aircraft(String name, AircraftType type) {
  6.         // etc
  7. }
As for AircraftType: if there are a small number of these (each with their own name and hourly rate) you might want to consider an enum.

Enum types in Oracle's Tutorial gives a couple of examples. The second (the Planet enum) is rather like your AircraftType in that there are a handful of different planets each having a mass and radius just as your aircraft types each have a name and cost.
Oct 1 '10 #2
Casey Daniels
5 New Member
Thank you for pointing me in the right direction!!!
Oct 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Jerry | last post by:
What are the advantages and disadvantages of using Object Oriented PHP vs Java?
1
by: Matt Newcomb | last post by:
G'day, Hi, I've got a java class called ChannelIteratorAlgorithm which extends SampledChannelGroupIteratorAlgorithm. SampledChannelGroupIteratorAlgorithm has a stub method...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
5
by: rkozlin | last post by:
Running into an issue where the compiler will throw an error... "The type '<BaseClass>' is defined in an assembly that is not referenced. You must add a reference to assembly '<BaseClass>'." ...
5
by: relient | last post by:
This is rediculous. It is said when you override a method in a derived class that's implemented in the base class, you "override the base class methods" implementation, correct? but in my test,...
0
by: raghu1 | last post by:
I am btrying to have a base page as a common repository for a set of functions: some business logic, set-reset session variables. Can never get to run the aspx. Here is my agony: basePage.cs...
3
by: SteveCriscuoli | last post by:
I originally posted this in microsoft.public.xml ... my apologies to those to who read both groups ... Someone please tell me if I'm missing something here. The XML Comment generator in VS2005...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: r035198x | last post by:
Inheritance We have already covered one important concept of object-oriented programming, namely encapsulation, in the previous article. These articles are not articles on object oriented...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.