107 lines
2.4 KiB
Java
107 lines
2.4 KiB
Java
|
|
/**
|
|
* Class LibraryUser to create a user of a library.
|
|
*
|
|
* @George Wilkinson
|
|
* @1.0
|
|
*/
|
|
|
|
import java.util.Scanner;
|
|
import java.io.PrintWriter;
|
|
|
|
public class LibraryUser
|
|
{
|
|
// instance variables
|
|
private String userID, surname, firstName, otherInitials, title;
|
|
|
|
/**
|
|
* Constructor for objects of class LibraryUser
|
|
*/
|
|
public LibraryUser(){}
|
|
|
|
/*
|
|
* Accessor start - return values of corresponding variables.
|
|
*/
|
|
public String getUserID(){
|
|
return userID;
|
|
}
|
|
|
|
public String getSurname(){
|
|
return surname;
|
|
}
|
|
|
|
public String getFirstName(){
|
|
return firstName;
|
|
}
|
|
|
|
public String getOtherInitials(){
|
|
return otherInitials;
|
|
}
|
|
|
|
public String getTitle(){
|
|
return title;
|
|
}
|
|
|
|
/*
|
|
* Accessor End
|
|
* Mutator Start - Set value of corresponding variables
|
|
*/
|
|
|
|
public void setUserID( String userID ){
|
|
this.userID = userID;
|
|
}
|
|
|
|
public void setSurname( String surname ){
|
|
this.surname = surname;
|
|
}
|
|
|
|
public void setFirstName( String firstName ){
|
|
this.firstName = firstName;
|
|
}
|
|
|
|
public void setOtherInitials( String otherInitials ){
|
|
this.otherInitials = otherInitials;
|
|
}
|
|
|
|
public void setTitle( String title ){
|
|
this.title = title;
|
|
}
|
|
|
|
/*
|
|
* Mutator End
|
|
*/
|
|
|
|
/*
|
|
* Passed a PrintWriter, append field variables in a set format, and flush the buffer.
|
|
*/
|
|
public void writeData( PrintWriter writer )
|
|
{
|
|
writer.print(userID + ", " + surname + ", " + firstName + ", " + otherInitials + ", " + title + "\n");
|
|
writer.flush();
|
|
}
|
|
|
|
/*
|
|
* Print to terminal, all relevant fields.
|
|
*/
|
|
public void printDetails()
|
|
{
|
|
System.out.println( "ID: " + userID +
|
|
"\nName: " + title + " " + firstName + " " + otherInitials + " " + surname );
|
|
}
|
|
|
|
/*
|
|
* Passed a scanner object, assign relevant values to field variables.
|
|
*/
|
|
public void readData( Scanner detailScanner )
|
|
{
|
|
if ( detailScanner != null ) {
|
|
this.userID = detailScanner.next().trim();
|
|
this.surname = detailScanner.next().trim();
|
|
this.firstName = detailScanner.next().trim();
|
|
this.otherInitials = detailScanner.next().trim();
|
|
this.title = detailScanner.next().trim();
|
|
}
|
|
}
|
|
|
|
}
|