Advertisements

Aatul Palandurkar

Posts Tagged ‘Java trainer in Nagpur

Starting a series of some Java programs as many students were asking to share the programs. Here is the first program of the series.

Objectives:

  • Write a Program that calculates and prints the simple interest using the formula : Simple Interest = PTR/100
  • How to calculate Simple Interest in Java?
  • Write a program to calculate Simple Interest in Java.
  • Write a Java program that calculates and prints the simple interest using the formula : “SimpleInterest = PTR/100” and input values P, T, R should be accepted as command line.
  • How to use Command Line Arguments in Java?
  • How to pass values from command line in Java?
  • How to take input in Java from console?

 

This particular program can be written in various ways, we will try to write the solution program in different ways here and one can try to understand the difference between them.

Method 1 :

import java.util.Scanner;

public class SimpleInterestExample {

    public static void main(String[] args) {

        int p,t,r, result;

        Scanner sc = new Scanner(System.in);

        System.out.println("Enter the Value of P : ");
        p = sc.nextInt();

        System.out.println("Enter the Value of T : ");
        t = sc.nextInt();

        System.out.println("Enter the Value of R : ");
        r = sc.nextInt();

        result = (p*t*r)/100;
        System.out.println("Interest is : " + result);
    }
}

This one is the simplest way to write the program to find simple interest in Java. Here we have simply created the object of Scanner class for taking input. Scanner class was introduced in Java 6. To use Scanner class we will have to import the class from java.util package.

Method 2:

Now we will write a Java program that calculates and prints the simple interest using the Scanner class again but with object oriented programming approach.

import java.util.Scanner;

public class SimpleInterestExample
{
		double principalAmount = 0;
        double interestRate = 0;
        double term = 0;
		double simpleInterest = 0; 

    public void calculateSimpleInterest()
	{
		Scanner input = new Scanner(System.in);

		System.out.print("Enter the Principal amount : ");
		principalAmount = input.nextDouble();

		System.out.print("Enter the Rate As a decimal : ");
		interestRate = input.nextDouble();

		System.out.print("Enter the amount of time in years : ");
		term = input.nextDouble();

		simpleInterest = (principalAmount * interestRate * term) / 100;
	}

    public void displaySimpleInterest()
	{
		System.out.println("The Simple Interest is : " + simpleInterest);
    }
}

Mock Test Program for above code so that we can test the code. keep both the classes in same package and run the Mock Test Program or MockTestProgram.java

public class MockTestProgram{

    public static void main(String[]args);
	{
		SimpleInterestExample simpleInt = new SimpleInterestExample();
		simpleInt.calculateSimpleInterest();
		simpleInt.displaySimpleInterest();
	}
}

Method 3:

Now we will write a Java program that calculates and prints the simple interest using the formula : “SimpleInterest = PTR/100” and input values P, T, R should be accepted as command line.

import java.util.Scanner;

public class SimpleInterestExample {

    public static void main(String[] args) {
		double p,t,r, result;

		p = Double.parseDouble(args[0]);
		t = Double.parseDouble(args[1]);
		r = Double.parseDouble(args[2]);

		Scanner sc = new Scanner(System.in);

		System.out.println("Enter the Value of P : ");
		p = sc.nextDouble();

		System.out.println("Enter the Value of T : ");
		t = sc.nextDouble();

		System.out.println("Enter the Value of R : ");
		r = sc.nextDouble();

		result = (p*t*r)/100;
		System.out.println("Interest is : " + result);
    }
}

 

I will be sharing more programs soon as many students were asking for programs which were carried out during Java training and were asked in assignments after Java training. By the time enjoy coding in Java and use NetBeans, it will ease your life.

Advertisements

What is Java User Group, Nagpur

 Java User Group Nagpur is a forum for collaboration and creative interaction for all interested in Java and new technologies revolving around Java.

 

JUG Nagpur
Abbreviation for Java User Group and Nagpur is the name of city where this group is located. This group provides opportunities for group meetings, one to one expert sessions and presentations.

 

Project Page
http://java.net/projects/jugnagpur/
Project page is a link to the Java.net web site. This is the entry through which we will be listing our group in Java User Groups Community.

 

Mailing List
http://groups.google.com/group/jugnagpur
The mailing list is the most important collaboration tool we use. All the transactions and knowledge sharing happens through this mailing list.

 

Wiki
http://jugnagpur.wikispaces.com/
Group wiki make the space available to all the group members to contribute creatively. The content getting matured on the wiki will be selectively shifted to the web site.

 

Group Blog
http://jugnagpur.blogspot.com
Blog where all group members can write their experiences and news about the JUG events.

 

JUG Meetup : March 27, 2011

Time : 2pm – 4pm

Venue :

Atul Palandurkar,

125, “SHARDA”,

Parvati Nagar,

Rameshwari Road,

Nagpur – 440027.

Tushar Joshi, Atul Palandurkar, Shwetal Bahadure, Harshal Potliya, Rahul Raja

Attendees of JUG Meetup on 27-03-2011

Attendees :

(From Left to Right)

  1. Tushar Joshi
  2. Atul Palandurkar
  3. Shwetal Bahadure
  4. Harshal Potliya
  5. Rahul Raja

 

Today’s meeting was very important for all of us, mainly Shwetal Bahadure & Harshal Potliya who are about to join the group very soon.

 

Sir & we discussed about various important thing & tasks to be done via JUG Nagpur likewise what is open source project? How to create a open source projects & finish it? Ways to spread the JUG Nagpur to more people of Nagpur, and how to make world know about JUG Nagpur? Even we discussed our view about being a member of the group, opportunities we may found while being in JUG Nagpur, exchange of ideas & the things we can learn from each other while being together in this group.

 

We planned to have 17 & possibly more different YANPAs (Yet Another NetBeans Platform Application) in accordance with the NetBeans User Group, Nagpur. Here we are not planning for something great but just to make it for the first time & later on will come back with something really exciting & useful for everyone!

 

We also planned to spread the JUG Nagpur to each & every professional & student of Nagpur who is interested in Java & its technologies.

 

Here at the meeting we also discussed about managing the website & wiki of JUG Nagpur, and to manage the FAQ pages & other pages & then to change the role after sometime so that everyone can learn how to do the particular task?

 


Advertisements

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13,201 other followers

Tweets

YouTube

Archives

Advertisements
%d bloggers like this: