Advertisement
Guest User

ASSIGNMENT 1

a guest
Sep 29th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. ***************ASSIGNMENT 1
  2. /*
  3. This is Question #1 for Assignment #1, Circuit Board Profit Assignment
  4. Mary Arienne Nabong, 62:160
  5. Wednesday Lab
  6. */
  7.  
  8. import java.util.*; //import Scanner class for input
  9.  
  10. public class CircuitBoardProfit
  11. {
  12. public static void main(String[] args)
  13. {
  14. double price;//entered price of circuit board
  15.  
  16. //Create Scanner object to read input
  17. Scanner keyboard = new Scanner(System.in);
  18.  
  19. //Get price of circuit board
  20. System.out.print("Enter price of circuit board. $");
  21. price = keyboard.nextInt();
  22.  
  23. //Calculate profit
  24. double profit = (price * 0.4);
  25.  
  26. //Display proft
  27. System.out.println("The profit from this circuit board is $" + (profit));
  28. }
  29. }
  30. ***************ASSIGNMENT 2
  31. /* This is Question #2 from Assignment #1, String Manipulator
  32. Mary Arienne Nabong, 62:160
  33. Wednesday Lab
  34. */
  35.  
  36. import java.util.*; //import Scanner class for input
  37.  
  38. public class StringManipulator
  39. {
  40. public static void main(String[] args)
  41. {
  42.  
  43. Scanner keyboard = new Scanner(System.in);
  44.  
  45. String cityName;
  46.  
  47. //Get city name
  48. System.out.print("Enter your favorite city: ");
  49. cityName = keyboard.nextLine();
  50.  
  51. //Manipulations
  52. //Number of characters in city name
  53. int numberChars = cityName.length();
  54.  
  55. //City name in all capitals
  56. String allCaps = cityName.toUpperCase();
  57.  
  58. //City name in all lowercase
  59. String allLower = cityName.toLowerCase();
  60.  
  61. //First letter in city name
  62. char firstLetter = cityName.charAt(0);
  63.  
  64. //Display manipulations
  65. System.out.println((numberChars) + "\n"
  66. + (allCaps) + "\n"
  67. + (allLower) + "\n"
  68. + (firstLetter));
  69. }
  70. }
  71. ***************ASSIGNMENT 3
  72. /* This is Question #3 from Assignment #1, Converter
  73. Mary Arienne Nabong, 62:160
  74. Wednesday Lab
  75. */
  76.  
  77. import java.util.*; //import Scanner class for input
  78.  
  79. public class Converter
  80. {
  81. public static void main(String[] args)
  82. {
  83. double amount; //entered amount of money
  84.  
  85. //Create Scanner object to read input
  86. Scanner keyboard = new Scanner(System.in);
  87.  
  88. //Get entered money
  89. System.out.print("Enter dollar amount. $");
  90. amount = keyboard.nextDouble();
  91.  
  92. //multiply by 100 to receive number without decimal
  93. double amountTimesHundred = (amount * 100);
  94.  
  95. //divide amount 100 to find amount of dollars // -,
  96. double dollars = Math.floor((amountTimesHundred) / 100); // -' DOLLARS
  97.  
  98. //mod amount times hundred for cents
  99. double cents = amountTimesHundred % 100;
  100. //find floor of cents to find tens place of cents
  101. double tensOfCents = Math.floor(cents);
  102.  
  103. //divide tensOfCents by 25 to find amount of quarters // -,
  104. double quarters = Math.floor((tensOfCents) / 25); // |
  105. //to find cents remaining after quarters // |
  106. double centsPostQuarters = (tensOfCents) - (quarters * 25); // -' QUARTERS
  107.  
  108. //to find amount of dimes // -,
  109. double dimes = Math.floor((centsPostQuarters) / 10); // |
  110. //to find amount remaining after dimes // |
  111. double centsPostDimes = (centsPostQuarters) - (dimes * 10); // -' DIMES
  112.  
  113. //to find amount of nickels // -,
  114. double nickels = Math.floor((centsPostDimes) / 5); // -' NICKELS
  115.  
  116. //to find amount of pennies // -,
  117. double pennies = Math.floor(centsPostQuarters % 5); // -' PENNIES
  118.  
  119. //cast to integers for smoother reading
  120. int intDollars = (int) dollars;
  121. int intQuarters = (int) quarters;
  122. int intDimes = (int) dimes;
  123. int intNickels = (int) nickels;
  124. int intPennies = (int) pennies;
  125.  
  126. //incase the amounts of each coin didn't need to be an integer
  127. /*System.out.println("$" + (amount) + " is equivalent to " + (dollars)
  128. + " dollars, "
  129. + (quarters) + " quarters, "
  130. + (dimes) + " dimes, "
  131. + (nickels) + " nickels, and "
  132. + (pennies) + " pennies." + (I)); */
  133.  
  134. System.out.println("$" + (amount) + " is equivalent to " + (intDollars)
  135. + " dollars, "
  136. + (intQuarters) + " quarters, "
  137. + (intDimes) + " dimes, "
  138. + (intNickels) + " nickels, and "
  139. + (intPennies) + " pennies.");
  140.  
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement