-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvestment.java
More file actions
58 lines (48 loc) · 1.67 KB
/
Investment.java
File metadata and controls
58 lines (48 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
//This program asks the user for their bank account balance and determines the interest rate the individual wants to invest for a certain amount of time.
public class Investment {
private String name;
private double Balance;
private double interest;
private double numTime;
private int time;
public Investment(double myBalance, String myName) {
Balance = myBalance;
name = myName;
}
public double getBalance(){
return Balance;
}
public String getName(){
return name;
}
public void determineBalance(){
if(Balance >= 1000) {
Scanner myInput = new Scanner(System.in);
System.out.println("Determine your interest rate: ");
double myInterest = myInput.nextDouble();
myInterest = myInterest/100;
System.out.println("Determine how many times you want to compound interest with respect to time: ");
double mynumTime = myInput.nextDouble();
System.out.println("Determine how long do you want to invest: ");
int myTime = myInput.nextInt();
interest = myInterest;
numTime = mynumTime;
time = myTime;
double newBalance = Math.pow((Balance*(1+(interest/numTime))),numTime*time);
newBalance = newBalance/1000;
System.out.println("My new balance is $"+newBalance);
} else {
System.out.println("Sorry, you don't have the required funds to invest yet");
}
}
public static void main(String[] args) {
Scanner myInput = new Scanner(System.in);
System.out.println("What is your name?");
String myName = myInput.nextLine();
System.out.println("What is your bank balance?");
double myBalance = myInput.nextDouble();
Investment user = new Investment(myBalance, myName);
user.determineBalance();
}
}