0% found this document useful (0 votes)
25 views1 page

Coding of File

Code of c + +

Uploaded by

Rushin Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Coding of File

Code of c + +

Uploaded by

Rushin Mehta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Q. 1.

A)
import java.util.*;
class SavingsAccount
{
double annualInterestRate=0;
private double savingsBalance = 0;
SavingsAccount(double num)
{
savingsBalance=num;
}
void calculateMonthlyInterest()
{
savingsBalance += (savingsBalance * annualInterestRate)/12;
}
void modifyInterestRate(double n)
{
annualInterestRate=n;
}
void display()
{
System.out.println("New balance = " +savingsBalance);
}
}
public class saving
{
public static void main(String[] args)
{
SavingsAccount saver1= new SavingsAccount(2000);
SavingsAccount saver2= new SavingsAccount(3000);
saver1.modifyInterestRate(0.04);
saver2.modifyInterestRate(0.04);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.println("Saver 1 :\n");
saver1.display();
System.out.println("Saver 2 :\n");
saver2.display();
saver1.modifyInterestRate(0.05);
saver2.modifyInterestRate(0.05);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.println("Saver 1 :\n");
saver1.display();
System.out.println("Saver 2 :\n");
saver2.display();
}
}

You might also like