http://en.wikipedia.org/wiki/Hyper_operator integralElem :: (Integral b) => [a] -> b -> a
hyper' :: (Integral a) => a -> (a -> a -> a)
hyper :: (Integral a) => a -> a -> a -> a
integralElem a b = a !! fromIntegral b
hyper' 0 = (+) . flip (^) 0
hyper' 1 = (+)
hyper' 2 = (*)
hyper' 3 = (^)
hyper' 4 = integralElem . (hyper4list)
where hyper4list a = 1 : (zipWith (^) [a,a..] (hyper4list a))
hyper' n = integralElem . (hyperlist n)
where hyperlist n a = 1 : (zipWith (hyper' (n-1)) [a,a..] (hyperlist n a))
hyper a n b = (hyper' n) a b
improvements to the above are welcome.
Name:
Anonymous2009-02-06 18:28
I need help converting from a double to an int or at least i need the values in amount paid to customer to be in the form xx.xx instead of xx.xxxxxxxxxxxxx(etc.)
/*
* CurrencyDollarConverter.java
* Author: MEMEMEMEMEMEMEMEME
* Last edited: 02/06/2009
*
* Purpose: CurrencyDollarConverter.java will display
* the details of a customer’s currency exchange transaction,
* as well as the amount of US Dollars and exact change paid
* to the customer after the currency exchange transaction has been made.
*
* Statement of Academic Honesty:
*
* The following code represents my own work. I have neither
* received nor given inappropriate assistance. I have not copied
* or modified code from any source other than the course webpage
* or the course textbook. I recognize that any unauthorized
* assistance or plagiarism will be handled in accordance with
* the University of Georgia's Academic Honesty Policy and the
* policies of this course.
*/
/* I would prefer calling the variable EXCHANGE_RATE as the 1.2% is a fixed rate
* but the .pdf file says to label it as EXCHANGE_FEE. This would also prevent
* confusion between the EXCHANGE_FEE and the later variable exchangeFee
*/
public static final double EXCHANGE_FEE = 0.012;
public static void main(String[] args) {
import java.util.Scanner;
import java.text.DecimalFormat;
public class CurrencyDollarConverter {
//I would prefer leaving this variable as EXCHANGE_FEE because it shows the proportion of a transaction which is taken as fees and has nothing to do with the exchange rate
private static final double EXCHANGE_FEE = 0.012;
private static final String[] lines = {"Please enter your first name","Please enter your last name","Please enter a currency type","Please enter currency exchange rate","Please enter amount of currency"};
private static final int[] notes = {2000,1000,500,25,10,5,1}; //value of denominations in cents
private static final String[] names = {"Twenty","Ten","Five","Quarters","Dimes","Nickels","Pennies"};
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
DecimalFormat nF = new DecimalFormat(".00");
String[] inputs = new String[lines.length];
for(int i=0; i<lines.length; i++) {
System.out.print(lines[i]+": ");
inputs[i] = scan.nextLine();
}
double amount = Double.parseDouble(inputs[4]);
double rate = Double.parseDouble(inputs[3]);
double USAmount = amount*rate;
double fee = USAmount*EXCHANGE_FEE;
double endAmount = USAmount-fee;
System.out.println("Currency Transaction Summary:");
System.out.println("Customer: "+inputs[1]+", "+inputs[0]);
System.out.println("Currency Amount: "+nF.format(amount)+" ("+inputs[2]+")");
System.out.println("Currency Exchange Rate: "+rate+" US dollars per "+inputs[2]);
System.out.println("US dollar amount: $"+nF.format(amount*rate));
System.out.println("Exchange fee ("+EXCHANGE_FEE*100+"%: $"+nF.format(fee)+")");
System.out.println("Total US dollars: $"+nF.format(endAmount)+"\n");
int dedAmount = (int)(endAmount*100); //convert to cents
for(int i=0; i<notes.length; i++) {
int tempAmt = dedAmount/notes[i];
if(tempAmt==0) continue;
String pad = notes[i]>100?" Dollar Bills":"";
System.out.println(tempAmt+" "+names[i]+pad);
dedAmount = dedAmount % notes[i];
}
}
}