/*
* Majin Baghul
* Credit goes to David Barnes @ http://steamcommunity.com/id/slender_mann
* Feel free to modify and redistribute as you wish
* This program is not to be sold for money
*/
/* Note:
* I left in my outputs as comments in the toscrap and toref functions.
* Since it's sort of tedious to type them out again, I'm leaving them in
* for the convenience of myself in the future and anyone modifying this.
*/
/*
* When entering the price per key, consider refined to be 1.00,
* reclaimed to be 0.33, scrap to be 0.11, and weapons to be 0.055.
*/
/*
* I did not bother adding verification for the numbers to make sure they're
* all actually numbers and not letters. It is not my intention to make this
* with the preconcepton that five year olds will be using this. If you cannot
* figure out that you have to enter in a number, I'm not sure you should
* be trading.
*/
package keycalc;
import java.util.Scanner;
import java.math.BigDecimal;
import java.io.*;
public class KeyCalc {
public static void main(String[] args) throws IOException {
double keyprice, metal, scrapval;
Scanner input = new Scanner(System.in);
System.out.println("How much per key in refined metal?" +
"\nFor example: 2.44, 2.55, 2.66");
keyprice = input.nextDouble();
System.out.println("\nHow many keys are you buying at that price?");
int keyquant = input.nextInt();
scrapval = toscrap(keyprice);
metal = toref(scrapval * keyquant);
System.out.println("\n" + keyquant + " keys at " + keyprice + " each: " +
round(metal, 2) + " Refined Metal");
System.out.println("Press enter to quit");
System.in.read();
}
public static double toscrap(double ref) {
double scrap = 0;
while (ref >= 1) {
ref--;
scrap += 9;
//System.out.println(scrap);
}
while (ref >= 0.3) {
ref -= 0.33;
scrap += 3;
//System.out.println(scrap);
}
while (ref >= 0.1) {
ref -= 0.11;
scrap++;
//System.out.println(scrap);
//System.out.println(ref);
}
while (ref >= 0.05) {
ref -= 0.55;
scrap += 0.5;
//System.out.println(scrap);
}
return scrap;
}
public static double toref(double scrap) {
double ref = 0.00;
while (scrap >= 9) {
ref++;
scrap -= 9;
//System.out.println(ref);
}
while (scrap >= 3) {
ref += 0.33;
scrap -= 3;
//System.out.println(ref);
}
while (scrap >= 1) {
ref += 0.11;
scrap -= 1;
//System.out.println(ref);
}
while (scrap >= 0.5) {
ref += 0.055;
scrap -= .5;
//System.out.println(ref);
}
return ref;
}
public static double round(double d, int decimalPlace) {
BigDecimal bd = new BigDecimal(d);
bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
return bd.doubleValue();
}
}