Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

Getting a Member's data

Now we have created a Member data object, we need to be able to create an instance to store.

 

 

 

The Member data member.

 

 

 

 

See what I mean, this is bad code - you can do better. We use a StringTokenizer to split a String into fields.

But suppose the Member's name is Mary Jo O Sullivan?

It ain't going to work.

 

Very lazy way to deal with problems!

Need to get the Member into another Class

These should be added

 

Getting hold of Member data and creating the instance

Uses the IBIO classes to work from the console - ugly and dirty!

/**
* Gets Member details from console and creates an instance of Member
*
* @author Richard
* @version 20071029
*/

public class MemberConsole
{
  private Member m;
  /**
  * Constructor for objects of class MemberConsole
  */
 
 public MemberConsole()
  {
    // initialise instance variables
    this.m = getMember();
  }
  public Member getMember()
  {
    try
    {
      output("input record details: code first last true/false");
      String s = input().trim();
      java.util.StringTokenizer st = new java.util.StringTokenizer(s, " ");
      int code = Integer.parseInt(st.nextToken().trim());
      String first = st.nextToken().trim();
      String last = st.nextToken().trim();
      boolean paid = Boolean.parseBoolean(st.nextToken().trim());
      Member m = new Member(code, first, last, paid);
      return m;
     }
     catch(Exception e)
     {
       output("Some error getting member record");
       return null;
     }
   }
   public Member getMemberConsole(){ return this.m; }

/**
* IBIO methods, (c) International Baccalaureate 2003
* Computer Science Subject Guide, Appendix 2.
*/

Related: [ Java home | Files home | Previous: Members | Next: The RAF ]

Random Access Files Example

First, getting the data from the console


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: May 31, 2009