0% found this document useful (0 votes)
5 views3 pages

Slide 14 Class Work

The document contains a Java program that defines classes for Student, Faculty, and Guardian. It demonstrates the creation of a Student and Faculty object, and how they can interact with each other through methods that display lists of their respective counterparts. The program utilizes ArrayLists to manage collections of Student and Faculty objects.

Uploaded by

Arthur Heaves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Slide 14 Class Work

The document contains a Java program that defines classes for Student, Faculty, and Guardian. It demonstrates the creation of a Student and Faculty object, and how they can interact with each other through methods that display lists of their respective counterparts. The program utilizes ArrayLists to manage collections of Student and Faculty objects.

Uploaded by

Arthur Heaves
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class work:

// Online Java Compiler

import java.util.*;
class HelloWorld {
public static void main(String[] args) {
Student s1=new Student("asdf",123,"cse","asd","Father");
Faculty f=new Faculty("zxc",45,"cse");

ArrayList<Student> slist=new ArrayList<Student>();


slist.add(s1);
f.take(slist);

ArrayList<Faculty> tlist=new ArrayList<Faculty>();


tlist.add(f);
s1.take(tlist);

}
}
class Guardian
{
String name, relation;
Guardian(String n, String r)
{
name=n;
relation=r;
}
}

class Student
{
String name, dept;
int id;
Guardian g;
Student(String n,int i,String d, String gn, String r)
{
name=n;
id=i;
dept=d;
g=new Guardian(gn,r);
System.out.println(name+" "+id+" "+dept+" "+gn+" "+r);
}
void take(ArrayList<Faculty> tlist)
{
System.out.println("Faculty list");
for(Faculty t: tlist)
{
System.out.println(t.name);
System.out.println(t.id);
System.out.println(t.dept);
}
}
}
class Faculty
{
String name, dept;
int id;
Faculty(String n,int i,String d)
{
name=n;
id=i;
dept=d;
}

void take(ArrayList<Student> tlist)


{
System.out.println("Student list");
for(Student t: tlist)
{
System.out.println(t.name);
System.out.println(t.id);
System.out.println(t.dept);
}
}
}

You might also like