Advertisement
Majin_Baghul

Untitled

Nov 19th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. /*
  2. * Majin Baghul
  3. * Credit goes to David Barnes @ http://steamcommunity.com/id/slender_mann
  4. * Feel free to modify and redistribute as you wish
  5. * This program is not to be sold for money
  6. */
  7.  
  8. /* Note:
  9. * I left in my outputs as comments in the toscrap and toref functions.
  10. * Since it's sort of tedious to type them out again, I'm leaving them in
  11. * for the convenience of myself in the future and anyone modifying this.
  12. */
  13.  
  14. /*
  15. * When entering the price per key, consider refined to be 1.00,
  16. * reclaimed to be 0.33, scrap to be 0.11, and weapons to be 0.055.
  17. */
  18.  
  19. /*
  20. * I did not bother adding verification for the numbers to make sure they're
  21. * all actually numbers and not letters. It is not my intention to make this
  22. * with the preconcepton that five year olds will be using this. If you cannot
  23. * figure out that you have to enter in a number, I'm not sure you should
  24. * be trading.
  25. */
  26. package keycalc;
  27.  
  28. import java.util.Scanner;
  29. import java.math.BigDecimal;
  30. import java.io.*;
  31.  
  32. public class KeyCalc {
  33.  
  34.  
  35. public static void main(String[] args) throws IOException {
  36.  
  37. double keyprice, metal, scrapval;
  38. Scanner input = new Scanner(System.in);
  39.  
  40. System.out.println("How much per key in refined metal?" +
  41. "\nFor example: 2.44, 2.55, 2.66");
  42. keyprice = input.nextDouble();
  43.  
  44. System.out.println("\nHow many keys are you buying at that price?");
  45. int keyquant = input.nextInt();
  46.  
  47. scrapval = toscrap(keyprice);
  48.  
  49. metal = toref(scrapval * keyquant);
  50.  
  51.  
  52.  
  53.  
  54.  
  55. System.out.println("\n" + keyquant + " keys at " + keyprice + " each: " +
  56. round(metal, 2) + " Refined Metal");
  57.  
  58. System.out.println("Press enter to quit");
  59. System.in.read();
  60.  
  61.  
  62.  
  63. }
  64.  
  65. public static double toscrap(double ref) {
  66. double scrap = 0;
  67.  
  68. while (ref >= 1) {
  69. ref--;
  70. scrap += 9;
  71. //System.out.println(scrap);
  72. }
  73. while (ref >= 0.3) {
  74. ref -= 0.33;
  75. scrap += 3;
  76. //System.out.println(scrap);
  77. }
  78. while (ref >= 0.1) {
  79. ref -= 0.11;
  80. scrap++;
  81. //System.out.println(scrap);
  82. //System.out.println(ref);
  83. }
  84. while (ref >= 0.05) {
  85. ref -= 0.55;
  86. scrap += 0.5;
  87. //System.out.println(scrap);
  88. }
  89. return scrap;
  90. }
  91.  
  92. public static double toref(double scrap) {
  93. double ref = 0.00;
  94.  
  95. while (scrap >= 9) {
  96. ref++;
  97. scrap -= 9;
  98. //System.out.println(ref);
  99. }
  100. while (scrap >= 3) {
  101. ref += 0.33;
  102. scrap -= 3;
  103. //System.out.println(ref);
  104. }
  105. while (scrap >= 1) {
  106. ref += 0.11;
  107. scrap -= 1;
  108. //System.out.println(ref);
  109. }
  110. while (scrap >= 0.5) {
  111. ref += 0.055;
  112. scrap -= .5;
  113. //System.out.println(ref);
  114. }
  115. return ref;
  116. }
  117.  
  118. public static double round(double d, int decimalPlace) {
  119. BigDecimal bd = new BigDecimal(d);
  120.  
  121. bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP);
  122.  
  123. return bd.doubleValue();
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement