Advertisement
angrymasteryoda

person example

Apr 2nd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. /*
  2. so i gotta write a program to read in names, ages, and phone numbers for ten people; group the data into a class and create an array to store the info. any suggestions?
  3. */
  4.  
  5.  
  6. public class Person(){
  7.     private String name;
  8.     private int age;
  9.     private String phone;//remember you want to interpet the phone as a string
  10.  
  11.     public Person(String n, int a, String p){
  12.         name = s;
  13.         age = a;
  14.         phone = p;
  15.     }
  16. }
  17. public class workingClass(){
  18.     public static void main(String[] args){
  19.         Scanner in = new Scanner(System.in);
  20.         int numberOfTimes = 10;
  21.         Person[] people = new Person[numberOfTimes];
  22.        
  23.        
  24.         for(int i = 0; i < numberOfTimes; i++}(
  25.             String name ="", phone="";
  26.             int age=0;
  27.             System.out.println("enter a name");
  28.             name = in.nextLine();
  29.             System.out.println("enter age");
  30.             age= in.nextInt();
  31.             System.out.println("enter phone");
  32.             phone= in.nextLine();
  33.  
  34.             people[i] = new Person(name, age, phone);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement