
/*
	CostofItemsForSale
	extends class ItemsForSale
	sets quantities (this is done randomly)
        
	asks for type for shipping
	UPS Next Day, UPS Ground, or USPS
        shipping costs are fixed at: $10, $5, $3.50;

	asks for California Resident (Adds Sales Tax)

*/

import java.math.*;  //use for static method double Math.random 0.0 - 1.0;

public class CostOfItemsForSale extends ItemsForSale {

private int i = 0;
private boolean caResident = false;

public CostOfItemsForSale( ){ super( 0 ); }
        
public double calculateCost( ) {
	double cost = 0.0;
	for( i = 0; i < numItems() ; ++i )
		cost += getCost(i) * getQuantities(i);
	return (cost + (caResident? cost*0.0775 : 0.0) );
	}
        
private void setQuantities( ) {
  
  for( i=0; i < numItems(); ++i )
    set( i, (int)(Math.random( )*10) );
}

protected void print( ) {
          super.print( );
          System.out.println( "Subtotal is " + calculateCost() );
        }

private char read( String prompt ) {
  
    System.out.println( prompt );
    return SavitchIn.readLineNonwhiteChar( );
  }
  

public static void main( String[] args ) {

	CostOfItemsForSale bill = new CostOfItemsForSale( );

	bill.print();
        bill.set( 1, 2 ); //No set in derived class
        bill.print();
        bill.caResident = ( bill.read( "Enter Y if California Resident" ) == 'Y' ? true : false );
        bill.setQuantities( );
        bill.print();
	}
} //End class CostOfItemsForSale