passing variables into a new object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • whitep8
    New Member
    • Oct 2009
    • 65

    #1

    passing variables into a new object

    Hi,

    I have a class which asks user to input information using scanner.

    e.g.
    Code:
     System.out.println("Please enter your post code: ");
            String postCode = myScanner.nextLine();
    
            System.out.println("Please enter your telephone (+44): ");
            long telNumber = myScanner.nextLong();
    now at present, after the input request i call a new object, but rather that the current static information, i want it to be these variables

    currently
    Code:
     Personal[] personalList = new Personal[1];
                   personalList[0] = new Personal("Paul "," White ", 74078L , "my address", "my town", "my county", 7383383838L);
    bet i want to pass in the actual variable value of the scanned item.

    within the object class Personal, the constructor looks like this
    Code:
      public Personal(String forename, String surname, long dob, String add1, String add2, String county, long telNumber)
        {
        	this.forename = forename;
            this.surname = surname;
            this.dob = dob;
            this.add1 = add1;
            this.add2 = add2;
            this.county = county;
            this.telNumber = telNumber;
    
         }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Code:
     Person p = new Person(forename,surname, dob, ...

    Comment

    Working...