Начало кода класса...
Листинг 5.11. Начало кода класса ShippingCalculator и его конструктора (ShippingCalculator.java)
public class ShippingCalculator {
Order order;
public ShippingCalculator( Order setOrder ) {
order = setOrder;
}
public String[] getTypes() {
String[] names = { "FedEx Overnight",
"FedEx 2-Day",
"UPS Overnight",
"UPS 3-Day",
"USPS 2-Day",
"USPS Regular" };
return names;
}
public String getPrice( String name ) {
double weight = order.getTotalItemWeight();
if( name.equals( "FedEx Overnight" ) )
if( weight >
3.0 )
return "$10.99";
else
return "$7.99";
if( name.equals( "FedEx 2-Day" ) )
if( weight >
3.0 )
return "$5.99";
else
return "$3.49";
if( name.equals( "UPS Overnight" ) )
if( weight >
2.0 )
return "$8.99";
else
return "$6.99";
if( name.equals( "UPS 3-Day" ) )
if( weight >
2.5 )
return "$5.99";
else
return "$4.99";
if( name.equals( "USPS 2-Day" ) )
if( weight >
2.5 )
return "$4.99";
else
return "$3.99";
if( name.equals( "USPS Regular" ) )
return "$2.99";
return "0.00";
}
}
Содержание раздела