import java.util.Scanner;

/**************************************
 *  describe this class here
 *
 * @author - Nancy Harris
 * @version - V1 - 10/06/2013 
 *************************************/
public class CSCard 
{
    // add any needed constants here
    private final double INTEREST_RATE = .02;
    private final double MIN_PERCENT = .2;

   /********************************************
    * createStatement does the work of producing the
    * CC statement
    *
    * @param args Unused in this application
    ********************************************/
   public void createStatement()
   {
   
     // variables
      Scanner keyboard;
      
      double priorBalance;
      double addtlCharges;
      double interest;
      double newBalance;
      double minPayment;
   
      // add any needed variables here
      
      keyboard = new Scanner(System.in);
      
      priorBalance = readData(keyboard, "Type the balance: ", 0);
                        
      addtlCharges = readData(keyboard, "Type the new charge amount: ", 0);

      // Perform the calculation of interest, new balance and minimum payment
      interest = calculateInterest(priorBalance, addtlCharges);
      
      newBalance = priorBalance + addtlCharges + interest;
      
      minPayment = calculateMinPayment(newBalance);
      
      // Output the resulting statement (do not change)
      System.out.println("\n\nCS CARD International Statement");
      System.out.println("===============================");
      System.out.printf("Previous balance:   $%,8.2f\n", priorBalance);
      System.out.printf("Additional charges: $%,8.2f\n", addtlCharges);
      System.out.printf("Interest:           $%,8.2f\n\n", interest);
      System.out.printf("New balance:        $%,8.2f\n\n", newBalance);
      System.out.printf("Minimum payment:    $%,8.2f\n", minPayment);
   
   }
   
   /**
    *  calculateInterest - This method will take in the previous balance
    *  and additional charges and compute the amount of interest. 
    *  If the priorBalance is 0 or less, the interest is 0. 
    *  If there was a priorBalance, the interest is 2% of the priorBalance 
    *  plus the additional charges. 
    *
    * @param priorBalance The balance before the new charges are added
    * @param additionalCharges The charges added this month
    *
    * @return The amount of interest to charge
    */
    public double calculateInterest(double priorBalance, double additionalCharges)
    {
    	double interest;
    	
    	if (priorBalance > 0)
      	  interest = (priorBalance + additionalCharges) * INTEREST_RATE;
        else
      	  interest = 0;
    	
    	return interest;
    }
    
    /**
    *  calculateMinPayment - This method will take in the previous balance
    *  and additional charges and compute the minimum payment.
    *  
    *       $0.00             for a new balance less than $0
    *    new balance          for a new balance between $0 and $49.99 (inclusive)
    *      $50.00             for a new balance between $50 and $300 (inclusive)
    * 20% of the new balance  for a new balance over $300
    *
    * @param balance The balance after interest and charges are added
    *
    * @return The minimum payment amount
    */
    public double calculateMinPayment(double balance)
    {
    	double minPayment;
    	
    	if(balance <= 0)
      	  minPayment = 0;
        else if (balance < 50.00)
      	  minPayment = balance;
        else if (balance <= 300)
      	  minPayment = 50.00;
        else 
      	  minPayment = balance * MIN_PERCENT;
    	
    	return minPayment;
    }
    
    /**
     * readData - this method prompts for the amount required and checks
     * to see if it is valid. If so, it returns it, if not it returns the
     * default value
     * 
     * @param keyboard The keyboard to use
     * @param prompt The prompt to use for this read
     * @param defaultValue The default value to use
     */
     public double readData(Scanner keyboard, String prompt, double defaultValue)
     {
    	 double amount;
    	 
    	 System.out.print(prompt);
    	 if (keyboard.hasNextDouble())
       	    amount = keyboard.nextDouble();
         else
         {
       	  	keyboard.nextLine(); // remove the offending text
       	    amount = defaultValue;
         }   
    	 return amount;
     }

}