import java.util.*; /** Student holds data about a student Note the use of the StringTokenizer to parse the student's name into First, Last and Middle names. @author Amitabha Mukerjee @version October 2008 */ public class Student { private String rollNum; private String firstName; private String midName; private String lastName; private int hostelNum; private char wing; private int roomNum; private Date birthDate; private Course[] courseList; private char grade; private double marks; public static final byte MAX_COURSES=8; public static final byte MAX_NAMES=6; // Default constructor public Student() { // initialise instance variables birthDate = new Date(); courseList = new Course[MAX_COURSES]; } /** Constructor with roll number */ public Student(String roll) { rollNum = roll; birthDate = new Date(); courseList = new Course[MAX_COURSES]; } /** Converts this object to String. Invoked by java as default whenever a string version is needed for this object. @return String with name, rollNum, and marks */ public String toString () { String s = ""; s += " NAME: " + firstName + " " + lastName ; s += " ROLL: " + rollNum; s += " MARKS: " + marks; return s; } public static void main (String arg[]) { int[] rollNum= {6016, 6024, 6078}; double[] midsemMarks = {61.7, 54 , 74.2 }; String[] name = {"Abhishek Murthy", "Abhishek Singh", "Ankit Mukund"}; Student [] batch = new Student[3]; for (int i=0; i marksMax) { index=i; marksMax = batch[i].marks; } } System.out.println ("HIGHEST MARKS:"); System.out.println (batch[index]); } /** set roll number */ public void setRollNum(String roll) { rollNum = roll; } /** set birthdate */ public void setBirthDate(Date d) { birthDate = d; } /** set first, mid and last names - use tokenizer @param fullName - single string containing full name */ public void setNames(String fullName) { String[] names=new String[MAX_NAMES]; int n = 0; StringTokenizer tokenizer = new StringTokenizer(fullName); while (tokenizer.hasMoreTokens()) { names[n]= tokenizer.nextToken(); n++; } lastName = names[n-1]; if (n>0) firstName = names[0]; if (n>1) { midName = names[1]; for (int j=2; j< n-1; j++) midName += " " + names[j]; } } /** access roll number */ public String getRollNum() { return rollNum; } }