/*

  This class handles a student's name & ID.

  It is contained by class Student and accessed by findAStudent() from class ManyStudents thru

  class Student.

 

  Author: Ahmad Mobasseri

*/

import java.util.Scanner;

 

public class StudentInfo

{

// Data

      private String name = "";  // change from String with null ptr to String pointing to an object

      private String id = "";    // of no value, as pointer used in display method     

 

// Constructor

//    public StudentInfo()    // no need to write constructor, if is empty

//    {     }

     

// Accessor

      public String getName()

      {     return name;      }

     

// Enter name and id for a student

      public void enterName()

      {

            System.out.println("Enter student's name. Enter 'n' to bypass.");

            Scanner scanner = new Scanner(System.in).useDelimiter("\\s*\n\\s*");  

                                                    // changes Scanner tokenizer from 'space' to 'enter'

            String tempName = scanner.next();

            if( ! tempName.equals("n"))              

            {    

                  name = tempName;

            }

            System.out.println("Enter student's ID. Enter 'n' to bypass. ");

            String tempID = scanner.next();

            if( ! tempID.equals("n"))

                  id = tempID;

//          scanner.close();                  // Can't do this, because in-parm to Scanner is System.in

      }

/*** 

    ***  This is to hit 'Enter' key, to go to next promp.  ***  

      System.out.println("Enter student's name. Hit 'Enter' key to bypass.");

      Scanner scanner = new Scanner(System.in).useDelimiter("\n");   

                                              // changes Scanner tokenizer from 'space' to 'enter'

      String tempName = scanner.next();

//    if( tempName.equals("\n")) System.out.println("you typed empty string"); // didn't work

      if( ! tempName.equals("\n"))          // Since "\n" didn't work above line, => this is not good         

      {    

//      Now tempName has one byte \n at last byte => we have to REMOVE it,

//      otherwise on printing 'name', it will jump one line.   %%

            name = tempName; 

      }

***/

     

// Displays name and id far of student grade/s display     

      public void displayName()

      {

            Object arrayTemp[]; arrayTemp = new Object[2]; 

            arrayTemp[0] = new String(name);

            arrayTemp[1] = new String(id);

            System.out.format("%12s | %8s |", arrayTemp);  

           

/***      the way of having 2 arrays.          

            Object arrayname[]; arrayname = new Object[1];  arrayname[0] = new String(name);

            Object arrayid[]; arrayid = new Object[1];      arrayid[0] = new String(id);

            System.out.format("%12s ", arrayname);  

            System.out.format("%10s", arrayid);

           

            To format a printout line

            Write a method to get a string of 3, when passed one digit.

            It should be, static utility method.

***/

      }

}