📄 clubmember.java
字号:
package com.nearhills;
import java.sql.SQLException;
import java.util.*;
import com.nearhills.*;
public class ClubMember {
private String firstName;
private String lastName;
private String middleName;
private String phoneNumber;
private String ability;
private int id;
public ClubMember()
{
super();
}
public String getAbility() {
return ability;
}
public String getFirstName() {
return firstName;
}
public int getId() {
return id;
}
public String getLastName() {
return lastName;
}
public String getMiddleName() {
return middleName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setAbility( String ability)
{
this.ability=ability;
}
public void setFirstName( String firstName )
throws BadDataException
{
if ( firstName.length() == 0 ) {
throw new BadDataException
( "You must supply a first name." );
}
this.firstName=firstName;
}
public void setId(int id) {
this.id = id;
}
public void setLastName( String lastName )
throws BadDataException
{
if ( lastName.length() == 0 ) {
throw new BadDataException
( "You must supply a last name." );
};
this.lastName=lastName;
}
public void setMiddleName( String middleName)
{
if ( middleName == null ) {
middleName = "";
}
this.middleName=middleName;
}
public void setPhoneNumber( String phoneNumber)
throws BadDataException
{
phoneNumber = phoneNumber.trim();
if ( ( phoneNumber.length() != 10 ) &&
( phoneNumber.length() != 7 ) ) {
throw new BadDataException(
"Phone number must be 7 or 10 digits " +
"you supplied " + phoneNumber.length() +
" characters." );
}
try {
long number = Long.parseLong ( phoneNumber );
this.phoneNumber=phoneNumber;
} catch ( NumberFormatException e ) {
throw new BadDataException (
"Phone number must be 7 or 10 digits." );
}
}
public synchronized void store() throws BadDataException,
SQLException, DBopException
{
if ( id == 0 ) {
setId( SkiClubDB.getNextId() );
} else {
throw new BadDataException(
"Your ID must be a positive integer.");
}
checkDuplicateName();
SkiClubDB.addMember(this);
}
private void checkDuplicateName()
throws BadDataException, DBopException, SQLException
{
ClubMember other = SkiClubDB.getMemberByName(
getFirstName(), getLastName() );
if ( ( other != null ) &&
( other.getId() != getId() ) ) {
throw new BadDataException (
"Duplicate member name not allowed: " +
getFirstName() + " " + getLastName() );
}
}
public void update()
throws DBopException,SQLException,BadDataException
{
checkDuplicateName();
SkiClubDB.updateMember(this);
}
public Vector getBookedTrips() throws DBopException
{
return SkiClubDB.retrieveBookings( id );
}
public int[] getTripStatus()
throws DBopException
{
Vector allTrips = SkiTrip.getAllTrips();
int []tripStatus = new int[allTrips.size()];
for ( int i = 0; i < tripStatus.length; i++ ) {
tripStatus[i] = SkiTrip.FULL;
if ( ( (SkiTrip) allTrips.elementAt(i) ).
getCapacity() == 0 ) {
tripStatus[i] = SkiTrip.NOTRIP;
} else if ( ( (SkiTrip) allTrips.elementAt(i) ).
isAvailable() ) {
tripStatus[i] = SkiTrip.AVAILABLE;
}
}
Enumeration cursor = getBookedTrips().elements();
while ( cursor.hasMoreElements() ) {
tripStatus[ ( (Integer) cursor.nextElement() ).
intValue() - 1 ] = SkiTrip.BOOKED;
}
return tripStatus;
}
public void book( int tripId )
throws DBopException, SQLException, BadDataException
{ try {
Booking booking = new Booking( id, tripId );
booking.add();
} catch( BookingException e ) {
throw new BadDataException( e.getMessage() );
}
return;
}
public void cancel( int tripId )
throws DBopException, SQLException, BadDataException
{
try {
Booking booking = new Booking( id, tripId );
booking.drop();
} catch( BookingException e ) {
throw new BadDataException( e.getMessage() );
}
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -