222k views
2 votes
Create the logic for a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent interest for one year. Create a separate method to do the calculation and return the result to be displayed.

2 Answers

2 votes

Answer:

public class num7 {

/* Interest = (Principal *Rate*Time)/100

Total amount you will have = principal (5000)+Interest

*/

public static void main(String[] args) {

double prinAmount = 5000;

System.out.println("The total amount is "+(calInterest(prinAmount)));

}

static double calInterest(double principal){

int time =1;

double rate = 2.0;

double interest = (principal*rate*time)/100;

double principalPlusInterest = principal+interest;

return principalPlusInterest;

}

}

Step-by-step explanation:

The Logic for this program is:

Interest = (Principal *Rate*Time)/100

Total amount you will have = principal (5000)+Interest

The method calInterest() accepts a double parameter (principal Amount) and uses the logic above to calculate and return the total amount.

The Main Method calls calInterest() and outputs the value calculated in this case since it is hardcoded 5100

User Iba
by
3.4k points
3 votes

Answer:

# main function is defined

# the calculateAmount is called here

def main():

print("The new amount is: ", calculateAmount(), sep="")

# calculateAmount function that calculate the interest

def calculateAmount():

# the value of principal is p

p = 5000

# the value of rate is r

r= 2

# the time is t

t = 1

# the formula for finding interest

interest = (p * r * t) / 100

# the new amount is calculated

amount = p + interest

# the amount is returned

return amount

# a call that make main function begin execution

if __name__ == "__main__":

main()

Step-by-step explanation:

The program is written in Python and it is well commented. A screenshot is attached showing program output

Create the logic for a program that calculates and displays the amount of money you-example-1
User David Schlosnagle
by
3.8k points