// Arup Guha
// 7/18/07
// Example of a few methods for BHCSI class

import java.util.*;

public class methods {
	
	public static void main(String[] args) {
		
		// Test greeting method
		greeting("Arup");
		
		// Testing power - should test more thoroughly.
		System.out.println("2^3 + 5^2 = "+(power(2,3)+power(5,2)));
		
		// Test Random Card Method.
		Random r = new Random();
		for (int i=0; i<10; i++)
			System.out.print(dealRandomCard(r)+" ");
		System.out.println();
		
	}
	
	// Pre-conditions: None
	// Postconditions: A greeting is printed, personalized for the name passed
	//                 in as a parameter.
	public static void greeting(String name) {
		System.out.println("Dear "+name+", which option would you like?");
		System.out.println("1. Go to class.");
		System.out.println("2. Go back to sleep.");
	}
	
	// Pre-conditions: exp is non-negative, and the final answer is less than
	//                 2^31 - 1.
	// Post-conditions: base raised to the power exp is returned.
	public static int power(int base, int exp) {
		
		int ans = 1;
		for (int i=0; i<exp; i++)
			ans = ans*base;
			
		return ans;
	}
	
	// Pre-conditions: principle is positive, intrate is represented as a
	//                 percentage, and numyears is non-negative.
	// Post-conditions: The amount of money in an account which starts with
	//                  principle dollars, invested for numyears under a simple
	//                  interest rate of intrate percent is returned.
	public static double matureMoney(double principle, double intrate, int numyears) {
		
		// Each loop iteration matures the principle for one year.
		for (int i=0; i<numyears; i++)
			principle = principle*(1+intrate/100);
			
		return principle;
	}
	
	// Pre-conditions: None
	// Post-conditions: A String is returned that represents a randomly 
	//                  chosen card. Each card is equally likely to be chosen
	//                  each time the method is called.
	public static String dealRandomCard(Random r) {
		
		// Produce a random integer from 0 to 51.
		int num = r.nextInt(52);
		
		String card;
		
		// The first 13 cards are Clubs
		if (num < 13)
			card = "C";
			
		// The next 13 are Diamonds
		else if (num < 26)
			card = "D";
			
		// Then Hearts...
		else if (num < 39)
			card = "H";
			
		// Or Spades.
		else
			card = "S";
		
		// We'll assign these four cards as Kings.
		if (num%13 == 0)
			card = "K" + card;
			
		// These as Aces.
		else if (num%13 == 1)
			card = "A" + card;
			
		// These as Tens
		else if (num%13 == 10)
			card = "T" + card;
			
		// Jacks
		else if (num%13 == 11)
			card = "J" + card;
			
		// Queens
		else if (num%13 == 12)
			card = "Q" + card;
			
		// This naturally takes care of 2 through 9.
		else
			card = (num%13) + card;
			
		// Return the String we have formed that represents a random card.
		return card;
	}
}