develop a class named interest with non-static variables p, n, r. make a parameterized constructor to initialize variables. not make a method simple interest() to calculate simple interest. now test the class interest
Answers
Answered by
0
8stodig8tdihdgsehsstedgkgtdlbhdhpuf
Answered by
0
A program to calculate interest with a parameterized constructor is written as follows:
import java.util.*;
public class interest
{
private int p; //The declaration of non-static variables
private int n;
private int r;
public interest (int p1, int n1, int r1) //Parameterized constructor to initialize the variables
{
p = p1;
n = n1;
r = r1;
}
int interest() //Method to calculate the interest
{
double si;
si = (p*r*n)/100;
return si;
}
static void main() //Main function to display the interest
{
interest ob = new interest();
int inte = ob.interest();
System.out.println("The simple interest is: "+inte);
}
}
Similar questions