Advertisement
Guest User

Final Part 2 12/12/17

a guest
Dec 12th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Final {
  3. static Scanner scan = new Scanner(System.in);
  4.  
  5.  
  6. public static void main(String args[]) {
  7.  
  8. System.out.println("Input your first number: ");
  9. double number = scan.nextDouble();
  10. System.out.println("Input your second number: ");
  11. double number2 = scan.nextDouble();
  12.  
  13. //System.out.println(number);
  14.  
  15. System.out.println("What function would you want to do?");
  16. String userFunction = scan.next();
  17.  
  18. userInput(number, number2, userFunction);
  19. }
  20.  
  21.  
  22. public static void userInput(double a, double b, String func){
  23.  
  24. System.out.println("Your answer will be: ");
  25. // System.out.println(add(a, b));
  26.  
  27. if (func.equals("add")){
  28. System.out.println(add(a, b));
  29. } else if (func.equals("subtract")){
  30. System.out.println(subtract(a, b));
  31. } else if (func.equals("multiply")){
  32. System.out.println(multiply(a, b));
  33. }else if (func.equals("divide")){
  34. System.out.println(divide(a, b));
  35. }
  36.  
  37. System.out.println(simpleInterest());
  38. System.out.println(CompoundInterest());
  39. }
  40.  
  41. public static double add(double firstNumber, double secondNumber) {
  42. return firstNumber + secondNumber;
  43. }
  44.  
  45. public static double subtract(double firstNumber, double secondNumber) {
  46. return firstNumber - secondNumber;
  47. }
  48.  
  49. public static double multiply(double firstNumber, double secondNumber) {
  50. return firstNumber * secondNumber;
  51. }
  52.  
  53. public static double divide(double firstNumber, double secondNumber) {
  54. return firstNumber / secondNumber;
  55. }
  56.  
  57. public static double simpleInterest(){
  58. float p, r, t;
  59. Scanner s = new Scanner(System.in);
  60. System.out.print("Enter the Principal : ");
  61. p = s.nextFloat();
  62. System.out.print("Enter the Rate of interest : ");
  63. r = s.nextFloat();
  64. System.out.print("Enter the Time period : ");
  65. t = s.nextFloat();
  66. float si;
  67. si = (r * t * p) / 100;
  68. System.out.print("The Simple Interest is : " + si);
  69. return si;
  70. }
  71.  
  72. public static double CompoundInterest() {
  73. Scanner input = new Scanner(System.in);
  74.  
  75. double principal = 0;
  76. double rate = 0;
  77. double time = 0;
  78.  
  79. double compoundInterest = 0;
  80.  
  81. System.out.print("Enter the Principal amount : ");
  82. principal = input.nextDouble();
  83.  
  84. System.out.print("Enter the Rate : ");
  85. rate = input.nextDouble();
  86.  
  87. System.out.print("Enter the Time : ");
  88. time = input.nextDouble();
  89.  
  90. compoundInterest = principal * Math.pow((1 + rate/100),time);
  91.  
  92. System.out.println("");
  93. System.out.println("The Compound Interest is : "
  94. + compoundInterest);
  95.  
  96. return compoundInterest;
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement