Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Regarding ArrayList

    If I am having a student class and a college class.... now in student class i want to create an ArrayList of phone number and also created a getter setter of that arraylist. Now i want to ask to end user about phone no and want to set back value to arraylist. so how i could have access to arraylist from one class to other

  2. #2
    AnandVijay is offline Member
    Join Date
    Oct 2013
    Posts
    15
    Rep Power
    0

    Default Re: Regarding ArrayList

    Post your code...

  3. #3
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Re: Regarding ArrayList

    public void addStudent()
    {
    if(!albatch.isEmpty())
    {
    System.out.println("Enter how many Student do you want to Add");
    int id=scanner.nextInt();
    for(int i=0;i<id;i++)
    {
    Student student= new Student();
    System.out.println("Enter student Rollno ");
    student.setRollno(scanner.nextInt());

    System.out.println("Enter student Name");
    student.setName(scanner.next());



    System.out.println("HOw many phone no do you want to add");
    int id1=scanner.nextInt();
    for(int j=0;j<id1;j++)
    {



    System.out.println("Enter Phone number");

    student.setPhone_no(scanner.nextInt());
    ph.add(student);

    }



    System.out.println("Enter Batch id ");
    displayBatch();
    int Bid=scanner.nextInt();
    for (int ii=0;ii<albatch.size();ii++)
    {
    Batch b=(Batch)albatch.get(ii);
    if(b.getBid()==Bid)
    {

    student.setBatch(albatch.get(ii));
    }

    }

    alstudent.add(student);
    }

    }



    else

    System.out.println("First you have to add course , faculty , Batch then add Student");



    }

    public void displayStudent()
    {
    System.out.println("Rollno\t\t"+"Name\t\t"+"Phone_ no\t\t"+"Bid\t\t"+"Bname\t\t"+"Fid\t\t"+"Fname\t\t "+"Cid\t\t"+"Cname");
    for (Student student : alstudent)
    {
    System.out.print(student.getRollno());
    System.out.print("\t\t"+student.getName());

    System.out.print("\t\t"+student.getPhone_no());

    Batch batch=student.getBatch();
    System.out.print("\t\t"+batch.getBid());
    System.out.print("\t\t"+batch.getBname());
    System.out.print("\t\t"+batch.getFaculty().getFid( ));
    System.out.print("\t\t"+batch.getFaculty().getFnam e());
    System.out.print("\t\t"+batch.getFaculty().getCour se().getCid());
    System.out.println("\t\t"+batch.getFaculty().getCo urse().getCname());
    // Faculty faculty=batch.getFaculty();
    /*System.out.print("\t\t"+faculty.getFid());
    System.out.print("\t\t"+faculty.getFname());
    System.out.print("\t\t"+faculty.getCourse().getCid ());
    System.out.println("\t\t"+faculty.getCourse().getC name());*/
    }




    }



    and code for student class ======


    package corejavaproject.model;

    import java.util.ArrayList;


    public class Student {
    int rollno;
    String name;
    int phone_no;
    Batch batch;

    public ArrayList mobno=new ArrayList();
    public Batch getBatch() {
    return batch;
    }
    public void setBatch(Batch batch) {
    this.batch = batch;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public int getRollno() {
    return rollno;
    }
    public void setRollno(int rollno) {
    this.rollno = rollno;
    }
    public int getPhone_no() {
    return phone_no;
    }

    public void setPhone_no(int phone_no) {
    this.phone_no = phone_no;
    }
    /*public ArrayList getMobno() {
    return mobno;
    }
    public void setMobno(ArrayList mobno) {
    this.mobno = mobno;
    }*/

    }

  4. #4
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0

    Default Re: Regarding ArrayList

    so now tell me how to add arraylist of phno to student

Similar Threads

  1. Replies: 3
    Last Post: 10-11-2013, 05:18 PM
  2. Replies: 0
    Last Post: 09-20-2013, 11:28 PM
  3. Replies: 12
    Last Post: 07-07-2011, 08:49 PM
  4. Replies: 7
    Last Post: 11-22-2010, 01:26 PM
  5. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

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