Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Final {
- static Scanner scan = new Scanner(System.in);
- public static void main(String args[]) {
- System.out.println("Input your first number: ");
- double number = scan.nextDouble();
- System.out.println("Input your second number: ");
- double number2 = scan.nextDouble();
- //System.out.println(number);
- System.out.println("What function would you want to do?");
- String userFunction = scan.next();
- userInput(number, number2, userFunction);
- }
- public static void userInput(double a, double b, String func){
- System.out.println("Your answer will be: ");
- // System.out.println(add(a, b));
- if (func.equals("add")){
- System.out.println(add(a, b));
- } else if (func.equals("subtract")){
- System.out.println(subtract(a, b));
- } else if (func.equals("multiply")){
- System.out.println(multiply(a, b));
- }else if (func.equals("divide")){
- System.out.println(divide(a, b));
- }
- System.out.println(simpleInterest());
- System.out.println(CompoundInterest());
- }
- public static double add(double firstNumber, double secondNumber) {
- return firstNumber + secondNumber;
- }
- public static double subtract(double firstNumber, double secondNumber) {
- return firstNumber - secondNumber;
- }
- public static double multiply(double firstNumber, double secondNumber) {
- return firstNumber * secondNumber;
- }
- public static double divide(double firstNumber, double secondNumber) {
- return firstNumber / secondNumber;
- }
- public static double simpleInterest(){
- float p, r, t;
- Scanner s = new Scanner(System.in);
- System.out.print("Enter the Principal : ");
- p = s.nextFloat();
- System.out.print("Enter the Rate of interest : ");
- r = s.nextFloat();
- System.out.print("Enter the Time period : ");
- t = s.nextFloat();
- float si;
- si = (r * t * p) / 100;
- System.out.print("The Simple Interest is : " + si);
- return si;
- }
- public static double CompoundInterest() {
- Scanner input = new Scanner(System.in);
- double principal = 0;
- double rate = 0;
- double time = 0;
- double compoundInterest = 0;
- System.out.print("Enter the Principal amount : ");
- principal = input.nextDouble();
- System.out.print("Enter the Rate : ");
- rate = input.nextDouble();
- System.out.print("Enter the Time : ");
- time = input.nextDouble();
- compoundInterest = principal * Math.pow((1 + rate/100),time);
- System.out.println("");
- System.out.println("The Compound Interest is : "
- + compoundInterest);
- return compoundInterest;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement