Do I need multiple Classes?

I have a question about a project I'm working on. The direction's are:
//Start
Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields.
Next, design a class named Customer, which is derived from the Person class. The Customer class should have a field for a customer number and a boolean field indication whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Demostrate an object of the customer class in a simple program (CustomerDemo).
//End
My question is this, do I need to make 3 different classes? Why does the project require me to make a Person class, and a Customer class? Why not just combine the Person class and Customer class, then make the driver?

CS_Student001 wrote:
Why not just combine the Person class and Customer class, ...?Because not every Person is also a Customer of yours, with a customer number and a boolean that stores whether they want to be on a mailing list.
Imagine an Employee class. An Employee has a name, adress, and a phone number, but not a customer number. Instead, his pay could be stored in the Employee class. Had you combined Person and Customer, youd have to double the Name, adress, phone number parts. As cotton.m suggested, "inheritance" is the key google word here.

Similar Messages

  • I need java decompiler for multiple class

    Hello, i need a java decompiler for multiple class.
    avoiding of decompile one to one.
    Thanks

    Use JAD it has recursive decompiles.

  • Accessing the same object from multiple classes.

    For the life of me I can't workout how I can access things from classes that haven't created them.
    I don't want to have to use "new" multiple times in seperate classes as that would erase manipulated values.
    I want to be able to access and manipulate an array of objects from multiple classes without resetting the array object values. How do I create a new object then be able to use it from all classes rather than re-creating it?
    Also I need my GUI to recognize the changes my buttons are making to data and reload itself so they show up.
    All help is good help!
    regards,
    Luke Grainger

    As long as you have a headquarters it shouldn't be to painfull. You simply keep a refrence to your ShipDataBase and Arsenal and all your irrellevant stuff in Headquarters. So the start of your Headquarters class would look something like:
    public class Headquarters{
      public Arsenal arsenal;
      public ShipDatabase db;
    //constructor
      public Headquarters(){
        arsenal = new Arsenal(this, ....);
        db = new ShipDatabase(...);
    //The Arsenal class:
    public class Arsenal{
      public Headquarter hq;
      public Arsenal(Headquarter hq, ....){
        this.hq = hq;
        .Then in your ShipDatabase you should, as good programing goes, keep the arraylist as a private class variable, and then make simple public methods to access it. Methods like getShipList(), addToShipList(Ship ship)....
    So when you want to add a ship from arsenal you write:
    hq.db.addToShipList(ship);
    .Or you could of course use a more direct refrence:
    ShipDatabase db = hq.db;
    or even
    ShipList = hq.db.getShipList();
    but this requires that the shiplist in the DB is kept public....
    Hope it was comprehensive enough, and that I answered what you where wondering.
    Sjur
    PS: Initialise the array is what you do right here:
    //constructor
    shipList = new Ship[6];
    shipList[0] = new Ship("Sentry", 15, 10, "Scout");
    " " " "etc
    shipList[5] = new Ship("Sentry", 15, 10, "Scout");PPS: To make code snippets etc. more readable please read this article:
    http://forum.java.sun.com/faq.jsp#messageformat

  • How to compile and register a Java CFX tag with multiple class files?

    All-
    If this is the wrong forum for CFX questions, please let me
    know.
    I need to determine how to compile and register a Java CFX
    tag that contains multiple class files. One class file implements
    the CustomTag interface and the other class files implement various
    supporting classes. All of the documentation that I have found
    talks about using a single class file. I am assuming that a JAR
    file will be involved, but I am not sure of the specifics.
    Thanks in advance for your help.
    -Josh

    Yes, it will involve a jar. Use your java IDE (eclipse,
    etcetera ..) to create a jar containing all of the classes. Check
    your ide's documentation for how to create jar files. After you
    have created the jar, place the jar in the CF class path so CF will
    recognize it. For example the {cf_root}/WEB-INF/lib directory. CF
    must be restarted before it will detect the new jar. After
    restarting CF, register the CFX tag in the ColdFusion Administrator
    using the name of the class that implements the CustomTag
    interface.
    Though it is worth noting you can also instantiate java
    classes directly from ColdFusion (ie without using a CFX
    tag).

  • In which case we need a class with all methods defined as abstract ?

    In which case we need : A class with all methods defined as abstract (or should we go for Interface always in this case)

    The concept of interface and abstract class overlaps sometime, but we can have the following thumb rule to use them for our specific need:
    1) Interface: This should be use for code structuring. They standardize your application by providing a specific contract within and outside. If you think abstract class also provide structure, then reconsider as it limits the structure re-usability when there are many super-classes to inherit from. Java allow multiple inheritance by interface and not by Abstract class.
    2) Abstract Class: This should be use for code-reusability. Interface doesn't have any code so can't be used for code-reusability.
    Actually we can use both to provide the best.Taking a refernce to J2EE framework, the "Servlet" is an interface. It laids down the contract/structure for any code to be a servlet.
    But the "GenericServlet" class is an abstract class which provides implementation of some of the methods defined in the "Servlet" interface and leave some method abstract.
    Thus we see that the "Servlet" interface standardise the structure and the "GenericServlet" abstract class gives code re-usability.
    Original Question:
    In which case we need a class with all methods defined as abstract ?To this question, as all methods are abstarct we don't have option for code-reusability. so why not add standard structure concept to your application. So if there is not any restriction on making the field variable(if any) as final, we should go with the interface concept.

  • DrawImage() and multiple classes

    First I should start by saying I am VERY new to Java. I have written a program that uses multiple classes, and i would like to place      boolean b = g.drawImage(cardPics,x2,yPos,50,75),this); in my class. I have passed Graphics g from paint. I am able to use g.drawString, etc, but when I try to drawImage, it will not even compile. I CAN use
    boolean b = g.drawImage(cardPics[i],x2,yPos,50,75),this); in paint outside of the classes, so I believe I have the image array set up right.
    This is what the compilers reads:
    cannot resolve symbol
         boolean b =g.drawImage(cardPics[i],x2,yPos,50,75),this);
    (The symbol that it is referring to is the period between g and drawImage)
    Any help is greatly appreciated.
    Thankyou
    Apryl

    Actually, I did fiigure it out. The problem was that drawImage was being handed an ImageObserver, when infact it didn't need one. But drawImage needs an imageObserver as a parameter, so instead using 'this' you replace it with null.
    Thanks for all of the help

  • I need to host a Shared PDF on SharePoint. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time.

    I need to host a Shared PDF on SharePoint 2010. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time. Is this possible?

    try here:
    http://www.bbb.org
    File a complaint with them. Verizon will call you to fix the blunder.
    But remember it is always up to the customer to insure what they are getting and what it costs. Don't trust the word of a sales person who makes their living on getting that sale. Lies, deceit or false promises will be and have been used by sales people for thousands of years.
    Good Luck

  • How to create a .java file with multiple classes

    I have all the below classes declared in a file say ABC.java under
    a common package called somepackage
    Abstract class A
    Void abstract metod1();
    Void metod2();
    Class B
    void method3();
    Void method4();
    Class C
    void method1();
    Void method2();
    In Client.Java
    On compiling the Client.Java I get errors
    Import somepackag.*;
    Class Samp extents A
    void Method1()
    Public class Client
    A a1 =new Samp(); //error undeclared class A
    B b1 = new B1();//error undeclared class B
    C c1 = new C1();//error undeclared class C
    is it possible to have all the class declared in one file ( i dont need mutiple classes, as this file will be autogenerated , i need all classes in one file) and use the classes inside this in the some client app
    regards
    MP

    Peetzore wrote:
    As long as you have only one public class and your .java file is named after it you shouldn't have any problem.I did exactly that, but still i get the same error "Cannot find symbol"
    i have used the import command on top as import somepackage.*;
    Edited by: mpjava on Jun 2, 2009 1:29 AM
    Edited by: mpjava on Jun 2, 2009 1:30 AM

  • How to put multiple classes in a single file?

    Hello,
    I'd like to put mutliple classes in a single file. (This
    would be useful for grouping children that are minor extensions of
    parent classes or helper classes that are used by one class only).
    When I tried to put two classes in one file, I got this error
    message:
    5006: An ActionScript file can not have more than one
    externally visible definition: Notation.editField,
    Notation.labelField1
    This is the structure I used. Thanks in advance for your
    help.

    You can declare multiple classes in a single file, but only
    one can be
    within the package declaration. All class declarations
    outside the package
    are invisible to code outside the file.
    package sample
    public class SampleClass
    class SampleClassHelper
    class SampleClassHelper2

  • Multiple classes in the same source file

    I'm not sure what this is called, having multiple classes in the same source file. At first I thought it ws called subclassing but then I googled it and found that subclasses are just derived classes. Here's an example of what I'm talking about.
    public class A {
    class B {
    class C {
    }So first of all, what is having multiple classes in the same source file called?
    Secondly, what are the advantages/disadvantages of this?
    Thirdly, can you have a class completely WITHIN a class (same source file but inside the class not outside) and what are the advantages/disadvantages of this?

    Advantage: You can reduce the number of source files specialy when your secondry classes are used only in the public class of the file.
    Disadvantage: Normaly it make things more clear if we have one-to-one correspondance of class and source files. This make things easy when you want to find the java file of a perticuler class file. Also If you later wanted to create a seperate public class with a same name as one of those secondry classes you got lots of changes to do.
    You can avoid this by creating them as nested classes
    ex:-
    public class MyPublicClass{
       private static class MyInnerClass{
    }this way the inner class will create a class file with name "MyPublicClass$MyInnerClass.class" instead of just "MyInnerClass.class"
    And also if you declare the inner class as public you can access them from out side

  • Why we need Java Class in c++ pof Serialization

    Hi,
    I'm really confused why we need java class which implements PortableObject to support complex objects of c++. If we are not using any queries or entry processors in the application can't we keep the object as serialized byte format and can't we retrieve in from the c++ deserialization.
    Please share your thoughts if there's a way if we can skip any Java implementation.
    regards,
    Sura

    feel both are doing same work. Also can anyone tell me what is teh difference between Serilization and Exgternalization.If you need someone to tell you the difference, (a) how can you possibly 'feel both are doing the same work'? and (b) why don't you look it up in the Javadoc?
    It's not a secret.

  • Multiple classes in one file?

    I would like to do the following
    #import <UIKit/UIKit.h>
    @interface O : NSObject
    @end
    @interface A : O
    - (void) hi;
    @end
    @interface B : O
    - (void) hi;
    @end
    but the compiler complains. I do not want to create (O.h, O.m), (A.h, A.m), and (B.h, B.m) files. Surely one can declare multiple classes in a single file? If so, how. If not, why not?
    -Doug Danforth

    I've done that, should work. What is the compiler complaining about?
    Could it be the missing semicolons after the @end statements?

  • Multiple classes and drawImage

    First I should start by saying I am VERY new to Java. I have written a program that
    uses multiple classes, and i would like to place boolean b =
    g.drawImage(cardPics[j],x2,yPos,50,75),this); in my class. I have passed Graphics g
    from paint. I am able to use g.drawString, etc, but when I try to drawImage, it will
    not even compile. I CAN use
    boolean b = g.drawImage(cardPics[j],x2,yPos,50,75,this); in paint outside of the
    classes, so I believe I have the image array set up right.
    This is what the compilers reads:
    cannot resolve symbol
    boolean b =g.drawImage(cardPics[j],x2,yPos,50,75,this);
    (The symbol that it is referring to is the period between g and drawImage)
    Any help is greatly appreciated.
    Thankyou
    Apryl

    The last argument to drawImage must be an ImageObserver. Therefore, for this line of code to work, it must be placed in a non-static method of a class that implements ImageObserver.

  • How to use multiple classes for each form

    Hi,
    I have created two forms using screen painter and now i want to use different classes for these two forms .
    I have declared the Sbo Connection in main class i.e. Set Application ,Connection Context() but while connecting to other classes
    for executing the code for that form SAP is not connected to that class.How to use multiple classes functionality i don't able to
    do that.Please provide some sample codes for that as it will be more helpful for me to understand.
    Thanks & Regards,
    Amit

    Hi Amit,
    In fact, its more advisable to use separate classes for every form that you use.  Have one common class, say, for eg., clsMain.cs which has all the connection and connectivity to other classes, wherein, the menu event and item event of this main class, will just be calling the menu / item event of other classes.
    The individual functionality of the child classes will be called from the item / menu event of the respective classes.
    Item event in clsMain.cs will be as below.
    private void oApplication_ItemEvent(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)
                SAPbouiCOM.Form oForm;
                BubbleEvent = true;
                try
                    if ((pVal.FormTypeEx == "My_Form1Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm1_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
                    if ((pVal.FormTypeEx == "My_Form2Type") && (pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD))
                        oForm = oApplication.Forms.GetForm("My_FormType", pVal.FormTypeCount);
                        NameSpace.Repots.ClsForm1.ClsForm2_ItemEvent(oApplication, oCompany, oForm, ref pVal, ref BubbleEvent);
    Now, in the individual classes, you can have their respective item events, which will be called from the main class, and the respective functionalities will occur.
    Hope this helps.
    Regards,
    Satish.

  • Multiple classes in one file bad?

    Hello.
    I've been coding a load of elements recently, one of which is HUD elements for a game. I separated each element (joystick, fuel gauge etc) into a separate class but in one file, by that I mean more than one implementation in a file. Is this bad practise? Should I use one class and simply write methods that return an element, or is it ok to split them up?
    To me, in my head ,it makes more sense to split the up. I just wonder if this is bad practise?

    I did some reading and decided not to use multiple classes in one file, and instead use methods.

Maybe you are looking for

  • 2009 MacBook Pro Freezing, Starting Slowly

    So my mid-2009 17" MBP has run as well as the day I got it up until a couple weeks ago, when suddenly it started booting/shutting down slowly, and beach balling randomly for minutes at a time. Does anyone know what might be causing this? Here's my Et

  • Unable to create a follow-up transaction in EP-PCUI - Urgent - Please help

    Dear CRM experts, Here is my EP/PCUI scenario: I have created new PCUI related iviews from the EP. When i create a Follow up activity (Opportunity) from the Leads, it works absolutely fine and takes me to the Opportunity screen. But, when i try to cr

  • Is there a way to NOT delete apps from iPhone?

    I know, odd question. However, sometimes my son gets a hold of my phone, holds his finger on the screen too long, and then he has the ability to delete apps. I can restore them during the sync, but I'm wondering if there is a way to shut this off wit

  • Oracle Apps R12 Installation error on windows

    This new discussion is related to below link as last times discussion is locked ,i dont have idea why that discussion is locked(might be due to attachment link that i provided for log file ) "R12 E-Business suite installation error on Windows XP-SP3"

  • Sroll bars in regions

    Is there anyway to use scroll bars in regions. I noted that when you set the height and width that the region will auto expand if you enter most content than will fit in the region. Is there a way to fix the width and height and use scroll bars inste