Saturday, November 9, 2019

Java Plan To Calculate Uncomplicated Involvement - Homework Exercise

How to calculate uncomplicated involvement inwards Java or Write a Java programme to calculate Simple involvement is a pop Java programming exercise people operate inwards Java course of educational activity inwards schoolhouse as well as college. So if y'all induce got of late got an homework exercise well-nigh calculating Simple involvement inwards Java as well as wondering How to write Java programme than this tutorial tin assistance you, provided y'all know What is uncomplicated involvement as well as What is formula of uncomplicated interest. If y'all are completely novel inwards Java programming than I would propose to seek HelloWorld Example inwards Java as well as sympathise What is Path as well as Classpath inwards Java. IF y'all induce got been doing Java programming as well as looking for around skilful coding exercise than y'all tin likewise come across our before programs e.g. calculating Fibonacci serial using recursion, checking if release is palindrome as well as How to reverse String inwards Java using recursion.



How to calculate Simple Interest inwards Java

Here is total code example of Java programme to calculate Simple Interest inwards Java. This is an interactive Java programme which accept Input from User using java.util.Scanner class. By the agency simpleInterest() method is reusable method as well as I induce got made it static as well as therefore that I tin telephone band it from main method inwards Java without creating object of this class. Its skilful Java practise to brand utility method static.


How to calculate uncomplicated involvement inwards Java or Write a Java programme to calculate Simple inter Java programme to calculate Simple Interest - homework exercise/**
 *
 * Java programme to calculate Simple Interest inwards Java.
 * Input to programme is principle, charge per unit of measurement as well as fourth dimension as well as output is uncomplicated interest
 * @author
 */

public class SimpleInterestTest{

 
    public static void main(String args[]) {
     
        //creating scanner to induce got principle, charge per unit of measurement as well as fourth dimension input shape user
        Scanner scanner = new Scanner(System.in);
        System.out.println("Welcome inwards Java programme to calculate Simple interest");
     
        System.err.println("Please move into regulation sum :");
        float sum = scanner.nextFloat();
     
        System.err.println("Enter fourth dimension inwards years : ");
        float fourth dimension = scanner.nextFloat();
     
        System.out.println("Enter charge per unit of measurement annually : ");
        float charge per unit of measurement = scanner.nextFloat();
     
        float involvement = simpleInterest(amount, rate, time);
     
        System.out.println("Simple interested calculate past times programme is : " + interest);
    }
 
    public static float simpleInterest(float principle, float rate, float time){
        float involvement = (principle*rate*time)/100;
        return interest;
    }
}

Output:
Welcome inwards Java programme to calculate Simple interest
Please move into regulation sum :
1000
Enter fourth dimension inwards years :
1
Enter charge per unit of measurement annually :
7
Simple interested calculate past times programme is : 70.0


So nosotros saw nosotros induce got do a static method to calculate uncomplicated involvement for given amount, charge per unit of measurement as well as time. By the agency this Java programme is non validating input e.g. fourth dimension must hold upwards greater than zero, charge per unit of measurement should hold upwards to a greater extent than than zero, sum tin non hold upwards zippo or negative, which volition hold upwards demand if y'all are writing production code.

Further Learning
Data Structures as well as Algorithms: Deep Dive Using Java
Write a Java programme to calculate GCD of 2 numbers inwards Java

No comments:

Post a Comment