Connecting Tech Pros Worldwide Forums | Help | Site Map

passing variables into a new object

Newbie
 
Join Date: Oct 2009
Posts: 31
#1: 4 Weeks Ago
Hi,

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

e.g.
Expand|Select|Wrap|Line Numbers
  1.  System.out.println("Please enter your post code: ");
  2.         String postCode = myScanner.nextLine();
  3.  
  4.         System.out.println("Please enter your telephone (+44): ");
  5.         long telNumber = myScanner.nextLong();
  6.  
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
Expand|Select|Wrap|Line Numbers
  1.  Personal[] personalList = new Personal[1];
  2.                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
Expand|Select|Wrap|Line Numbers
  1.   public Personal(String forename, String surname, long dob, String add1, String add2, String county, long telNumber)
  2.     {
  3.         this.forename = forename;
  4.         this.surname = surname;
  5.         this.dob = dob;
  6.         this.add1 = add1;
  7.         this.add2 = add2;
  8.         this.county = county;
  9.         this.telNumber = telNumber;
  10.  
  11.      }
  12.  
  13.  

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: 4 Weeks Ago

re: passing variables into a new object


Expand|Select|Wrap|Line Numbers
  1.  Person p = new Person(forename,surname, dob, ...
Reply