Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. import java.util.Scanner;
  2. /***
  3. *
  4. * @author Rilind Asllani
  5. * Spring 2020
  6. * Information Systems 4415-090
  7. * Homework 1
  8. * 1/15/2020
  9. */
  10. public class homeworkOne
  11. {
  12. public static void main(String[] args)
  13. {
  14. //Remove commment lines to run specific method.
  15.  
  16. //celsiusToFahrenheit();
  17. //calculateTips();
  18. //sumOfTheDigits();
  19. //compoundValue();
  20. //futureInvestmentValue();
  21.  
  22. }
  23. /**
  24. * Homework Problem 2.1
  25. * Convert Celsius to Fahrenheit
  26. * Celsius written using double value then converting with formula to fahrenheit.
  27. */
  28. public static void celsiusToFahrenheit()
  29. {
  30. Scanner input = new Scanner(System.in); //Reads the console input.
  31. double celsius; // Variable set for celius.
  32. double Fahrenheit; // Variable set of Fahrenheit.
  33.  
  34. System.out.print("Enter a degree in Celsius: "); //asking for Celsius
  35.  
  36. celsius = input.nextDouble(); //reads the input and sets it equal to variable celsius.
  37. Fahrenheit = (9.0/5.0) * celsius + 32; // calculates the fahrenheit and sets it equal to variable fahrenheit.
  38.  
  39. System.out.println(celsius + " Celsius is "+ Fahrenheit + " Fahrenheit."); //prints line with the fahrenheit given some celsius.
  40. }
  41. /**
  42. * Homework Problem 2.5
  43. * Calculate the tip.
  44. */
  45. public static void calculateTips()
  46. {
  47. // Scanner variable and double variables.
  48. Scanner input = new Scanner(System.in);
  49. Double subtotal, gratuity;
  50.  
  51. //Console prompt for two doubles to be used in calculations.
  52. System.out.print("Enter the subtotal and a gratuity rate: ");
  53.  
  54. //Setting the two double values to the variables.
  55. subtotal = input.nextDouble();
  56. gratuity = input.nextDouble();
  57.  
  58. //calculating the gratuity.
  59. gratuity = gratuity/100 * subtotal;
  60.  
  61. //calculating the total
  62. subtotal = gratuity + subtotal;
  63.  
  64. //printing out the total
  65. System.out.println("The gratuity is $" + gratuity + " and the total is $" + subtotal);
  66.  
  67. }
  68. /**
  69. * Homework Problem 2.6
  70. * Sum of the digits between 0 and 1000 not inclusive.
  71. */
  72. public static void sumOfTheDigits()
  73. {
  74. //asking for a number between 0-1000
  75. System.out.print("Enter a number between 0 and 1000: ");
  76.  
  77. //Scanner and setting variable number equal to next int.
  78. Scanner input = new Scanner(System.in);
  79. int number = input.nextInt();
  80.  
  81. // splitting the number into each digit.
  82. int hundreds = number % 1000 /100;
  83. int tens = number % 100 / 10;
  84. int ones = number - (hundreds*100) -(tens*10);
  85.  
  86. //the sum of all the digits
  87. int sum = hundreds + tens + ones;
  88.  
  89. //prints out sum of the digits
  90. System.out.println("The sum of the digits is " + sum);
  91. }
  92. /**
  93. * Homework Problem 2.13
  94. */
  95. public static void compoundValue()
  96. {
  97. //Scanner and asking for savings amount
  98. Scanner input = new Scanner(System.in);
  99. System.out.print("Enter the monthly saving amount: ");
  100.  
  101. // setting variables
  102. double savings = input.nextDouble();
  103. double interest = 0.00417;
  104. double totalSavings = 0;
  105.  
  106. // Just repeated the savings account calculation 5 times
  107. totalSavings += savings+(savings+totalSavings)*interest;
  108. totalSavings += savings+(savings+totalSavings)*interest;
  109. totalSavings += savings+(savings+totalSavings)*interest;
  110. totalSavings += savings+(savings+totalSavings)*interest;
  111. totalSavings += savings+(savings+totalSavings)*interest;
  112. totalSavings += savings+(savings+totalSavings)*interest;
  113.  
  114. //removing the numbers that come after the second digit beyond the decimal. The addition of 0.5 is to round up.
  115. totalSavings = (int)(totalSavings * 100 + 0.5);
  116. // Printing savings after 6 months
  117. System.out.println("After the sixth month, the account value is $" + totalSavings/100);
  118. }
  119. /**
  120. * Homework Problem 2.21
  121. */
  122. public static void futureInvestmentValue()
  123. {
  124. //asking for investment amount
  125. System.out.print("Enter investment amount: ");
  126. Scanner input = new Scanner(System.in);
  127. double investmentAmount = input.nextDouble();
  128.  
  129. //asking for annual rate and changing it to monthly rate while setting it to monthlyPercentage variable.
  130. System.out.print("Enter annual rate in percentage: ");
  131. double monthlyPercentage = ((input.nextDouble()/100)/12);
  132.  
  133. //asking for years and setting the variable for years.
  134. System.out.print("Enter number of years: ");
  135. int years = input.nextInt();
  136.  
  137. //investment formula and removing everything after the 2 decimal place
  138. double futureValue = investmentAmount*Math.pow(1+monthlyPercentage, years*12);
  139. futureValue = (int)(futureValue*100 + 0.5);
  140. System.out.println("Future value is $" + futureValue/100);
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement