REF 6K  Objects and Linked List

public class Node
{
public Student data;
public Node next;

public Node(Student dataItem) 
{
data=dataItem;
next=null;
}

public Node(Student dataItem, Node nodeRef) 
{
data=dataItem;
next=nodeRef;
}
}
//*****************************************************************


import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Student
{
private String name;
private int age;
public Student(String nn, int aa)
{
name=nn;
age=aa;
}
public int getAge()
{
return age;
}
public String getName()
{
return name;
}
}

//*****************************************
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Vector;

public class Application1 
{
public Application1()
{
// create 100 objects off in memory -- not accessable later
//**********************************************************
System.out.println("PART ONE **************************"); 
String name; 
for(int a=1;a<=10;a++)
{
int n1=1+(int) (Math.random()*99);
name="Paul"+a;
Student stu = new Student(name,n1);
System.out.println(stu); // display ther address
}
//*********************************************************
// cteate 10 Student objects and put their address in Array bu
System.out.println("PART TWO **************************"); 
Student[] bu=new Student[10];
for(int a=1;a<=10;a++)
{
int n1=1+(int) (Math.random()*99);
name="Mary"+a;
bu[a-1] = new Student(name,n1);

for(int a=0;a<10;a++)
{
System.out.println(bu[a].getName() + " " + bu[a].getAge() );

//**********************************************************
// cteate 10 Student objects and put their address in Vector vu
Student temp;
System.out.println("PART THREE **************************"); 
Vector vu = new Vector();
for(int a=1;a<=10;a++)
{
int n1=1+(int) (Math.random()*99);
name="Ralph"+a;
vu.add(new Student(name,n1));

for(int a=9;a>=0;a--)
{
temp=(Student)vu.remove(a);
System.out.println(temp.getName() + " " + temp.getAge() );

//***************************************************************
// create 10 objects and put in linked list based on age low to high
System.out.println("PART FOUR **************************"); 
Node head=null;
for(int a=1;a<=10;a++)
{
int n1=1+(int) (Math.random()*99);
name="Larry"+a;
Student test = new Student(name,n1);
if(head==null) 
{
Node newNode = new Node(test);
newNode.next = head;
head = newNode;
continue;
}
if (n1 < head.data.getAge())
{
Node newNode = new Node(test, head);
head=newNode;
continue;
}
Node iterNode = head, trailingNode=head;
while(iterNode != null && (n1 > iterNode.data.getAge()))
{
trailingNode = iterNode;
iterNode = iterNode.next;
}
Node newNode = new Node(test, iterNode);
trailingNode.next = newNode;
} // end of loop to buld linked list for all objects 

// loop thru linked list to print the values of all Student objects 
String out = "";
Node iterNode=head;
while(iterNode !=null) 
{
out += iterNode.data.getName() +" "+iterNode.data.getAge()+"\n";
iterNode=iterNode.next;
}
System.out.println(out);
//**********************************************************


public static void main(String[] args)
{
Application1 app=new Application1();
System.exit(0);
}
}