📄 skitrip.java
字号:
package com.nearhills;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.*;
import java.util.*;
public class SkiTrip {
public static final int AVAILABLE = 0;
public static final int BOOKED = 1;
public static final int FULL = 2;
public static final int NOTRIP = 3;
private int id;
private Date date;
private String resort;
private int capacity;
private int booked;
static private Vector AllTrips = null;
public SkiTrip() {}
public static Vector getAllTrips()
throws DBopException
{
if ( AllTrips == null ) {
AllTrips = SkiClubDB.retrieveTrips();
}
return AllTrips;
}
public static SkiTrip getTrip( int id )
throws DBopException
{
Enumeration e = getAllTrips().elements();
while ( e.hasMoreElements() ) {
SkiTrip trip = ( SkiTrip ) e.nextElement();
if ( trip.getId() == id ) {
return trip;
}
}
return null;
}
void setId( int id ) {
this.id = id;
}
public int getId( ) {
return id;
}
void setDate( Date date ) {
this.date = date;
}
public Date getDate( ) {
return date;
}
void setResort( String resort) {
this.resort = resort;
}
public String getResort() {
return resort;
}
void setCapacity( int capacity ) {
this.capacity = capacity;
}
public int getCapacity( ) {
return capacity;
}
void setBooked( int booked ) {
this.booked = booked;
}
public String toString ()
{
DateFormat df = DateFormat.getDateInstance(
DateFormat.SHORT);
String printable = "Ski on " ;
printable += df.format(date) + " ";
while ( printable.length() < 16 ) {
printable += " ";
}
printable += "at " + resort;
return printable;
}
public int getBooked( ) {
return booked;
}
public boolean isAvailable() {
return ( getCapacity() > getBooked() );
}
public void addBooking() throws BookingException {
if ( isAvailable() ) {
setBooked( getBooked() + 1 );
} else {
throw new BookingException (
"Trip full, cannot add booking." );
}
}
public void dropBooking() throws BookingException {
if ( getBooked() > 0 ) {
setBooked( getBooked() - 1 );
} else {
throw new BookingException (
"Trip not booked, cannot drop booking." );
}
}
public static Vector getTrips( int skierID )
{
Vector trips = null;
try {
trips = SkiClubDB.getSkierTrips( skierID);
} catch ( Exception e ) {
System.out.println ( e.getMessage() );
}
return trips;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -