Write a Java program to calculate a simple interest. This program must be focused on an object oriented approach.
N.B. : Java source code is case sensitive
Source code: java_simple_interest . java
package java_simple_interest;
//class
class simple_interest
{
//instance variable
float principal_amount;
float year_of_interest;
float rate_of_interest;
//method with arguments and return type
float si(float pa, float yi, float ri)
{
return pa*yi*ri;
}
}
Source Code: calculate_simple_interest . java
(Source code under action button ( jButton1 ))
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//create object
simple_interest si =new simple_interest();
//instance variable getting value from text box
si.year_of_interest=Float.parseFloat(yoi.getText());
si.rate_of_interest=Float.parseFloat(roi.getText());
si.principal_amount=Float.parseFloat(pa.getText());
//method si called by object si
jLabel4.setText ("Your Payable interest is: " + si.si(si.year_of_interest,si.rate_of_interest ,si.principal_amount ));
}
video tutorial link: video
N.B. : Java source code is case sensitive
Source code: java_simple_interest . java
package java_simple_interest;
//class
class simple_interest
{
//instance variable
float principal_amount;
float year_of_interest;
float rate_of_interest;
//method with arguments and return type
float si(float pa, float yi, float ri)
{
return pa*yi*ri;
}
}
Source Code: calculate_simple_interest . java
(Source code under action button ( jButton1 ))
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//create object
simple_interest si =new simple_interest();
//instance variable getting value from text box
si.year_of_interest=Float.parseFloat(yoi.getText());
si.rate_of_interest=Float.parseFloat(roi.getText());
si.principal_amount=Float.parseFloat(pa.getText());
//method si called by object si
jLabel4.setText ("Your Payable interest is: " + si.si(si.year_of_interest,si.rate_of_interest ,si.principal_amount ));
}
great
ReplyDelete