Still can not call my Subclass method returns. J2EE - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 5 FirstFirst 12345 LastLast
Results 16 to 30 of 69

Thread: Still can not call my Subclass method returns. J2EE

  1. #16
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    Hello Norm,

    I have decided to start fresh as I was getting to jumbled on this..... I will include what I have so far as I don't know where to go from here. On my Business class that extends the InfoClass, there should be a return of fName but I cant get anything to return anything.... I will need to add it to an ArrayList of some kind until the user is all done... I will also have to recall all data either (either kind of contact).. Any direction will greatly be appreciated.

    Code:
    package contacts2;
    
    //import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.ArrayList;
    
    /**
     *
     * @author Drew
     */
    public class Contacts2 {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {
            //Instantiates the Scanner Class
            Scanner in = new Scanner(System.in);
            
            //Asks user which kinda of contact 1)Business or 2) Personal
            System.out.println("Please enter B for a business contact or P for a personal contact: ");
            
           
            String cont = in.next();
             
           
            
              if(cont.equals("B"))
              {
                   
                  
                    Business fno = new Business();
                    Business lno = new Business();
                    Business ado = new Business();
                    Business pno = new Business();
                    Business emo = new Business();
                    Business poso = new Business();
                    Business orgo = new Business();
                   fno.firstName();
           
          
              }
             // else
              //{
                //  System.out.print("You chose else: ");
              //}
           
            
        }
    }
    Code:
    package contacts2;
    
    import java.util.Scanner;
    import java.util.ArrayList;
    
    /**
     *
     * @author Drew
     */
    
    
    
      public  class Business extends ContactInfo 
    {
        Scanner in = new Scanner(System.in);
       ArrayList<Business> busContact = new ArrayList<Business>();
       
          
          
         
          
       public String firstName()
       {
          System.out.println("What is your Fisrt Name: ");
          String fName = in.next();      
           //return fName;
          //System.out.println("This is some txt!!" + fName);
          return fName;
       }
       
       
      
    }

  2. #17
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    I cant get anything to return anything

    Can you be more specific? What method is being called? What is it supposed to return? When the method is called, what does the caller do with what the method returns?
    Norm

  3. #18
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    When the program runs...(for this example) should ask for first name and return the inputed data to the busContact arraylist..... It does not so now I am lost on how to get this in the arratlist.

  4. #19
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    how to get this in the arratlist.
    Use the ArrayList class's add() method to put objects in the list.
    Norm

  5. #20
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    I had it in my Business class but it could not locate it...

    busContact.add(fName);

  6. #21
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    busContact is an ArrayList that holds Business objects, not Strings. You need to create a new Business object and add that to the arraylist.
    Norm

  7. #22
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    run:
    Please enter B for a business contact or P for a personal contact:
    B
    What is your Fisrt Name:
    Drew
    BUILD SUCCESSFUL (total time: 8 seconds)

    I do not get an error when I run the code,.... I just can't get the name Drew to add to the ArrayList.....I am not too sure where to put
    busContact.add(fno);
    If I put in main class, I am told that it could not find "busContact"......when put in the Business Class, I am told that the complier can not find the fno object.
    Last edited by BigDadd215; March 6th, 2014 at 08:58 AM.

  8. #23
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    Where is there a place in the code where both variables are in scope?
    Are either of the variables defined in the wrong place?
    Could a method be added that could be called with the value to be added to the arraylist?
    Norm

  9. #24
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    I am lost on your first sentence......

    I am sure that I have an issue somewhere, but I have no idea where... That is what I have trying to do...... In the Business class, it receives an input for the First Name..... From there, I can not find an acceptable solution to put the name...

    What I am trying to accomplish is is make a contact that stores the First Name, Last Name, Address, Email, etc in an arrayList. I can get it to the point where it asks and it receives the data, but from there... I can not get anything to work... Once the user enters the in the from the last question the program ends.

  10. #25
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    The arraylist of Business objects should be somewhere that it is accessible to whatever classes and methods need to have access.

    Somewhere the code should gather the data needed to build a Business object, then create the Business object and add it to the arraylist.
    Later some methods will need access to the arraylist to build reports etc using the data in the Business objects stored in the arraylist.
    Norm

  11. #26
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    Would it make sense for me to make a class that is designed to make the arraylist from the objects that the Business class creates?

    Kinda like the main called the business class to ask questions and the List Class will store the input into an array?

  12. #27
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    The Main class could contain the arraylist of Business objects.
    Somewhere there could be a method that gets the data to go in the Business class object, create the Business class object and store that object in the arraylist.

    How is the contents of the arraylist supposed to be used after it has been filled with Business class objects?
    Norm

  13. #28
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    I will need to call, for example, all the business contacts.... It should print out all First Names, Last Names, Addresses, etc..


    {Bob, Sims, 123 Test Dr, etc}
    {Karen, Jones, 115 South St, etc}
    Last edited by BigDadd215; March 6th, 2014 at 08:58 AM.

  14. #29
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,450

    Re: Still can not call my Subclass method returns. J2EE

    How does the program get the data that goes into a Business class object?
    When does the program create a Business class object using that data?
    When does the program put that newly created Business object into the arraylist?
    Norm

  15. #30
    Join Date
    Dec 2013
    Posts
    46

    Re: Still can not call my Subclass method returns. J2EE

    The main class looks builds the objects of business class, from there it passes to the business class to ask the questions..... From there is where I wanted to build the ArrayList.....

Page 2 of 5 FirstFirst 12345 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center