vault backup: 2024-04-12 09:39:31
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
|
||||
/**
|
||||
* Class LibraryUser to create a user of a library.
|
||||
*
|
||||
* @George Wilkinson
|
||||
* @2.3
|
||||
*/
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Forms field variables in a desired format, prints
|
||||
* to the PrintWriter, and flush to the file.
|
||||
* Takes Parameter
|
||||
* PrintWriter @writer
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the fields with details from the scanner
|
||||
* Takes Parameters
|
||||
* Scanner @detailScanner
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user