/* java program : implementation of packges...
Import a package in a class and use it. */
/*
First.java
*/
package pack;
public class First
{
static double amt,sim,comp,princ = 1000,rate = 0.09;
static int n=2;
public First()
{
System.out.println("\n...Welcome to First Class\n");
}
public static void DisplayData()
{
System.out.println("Principle Amount\t:"+princ+"\nRate Of Interest\t:"+rate*100+"%");
System.out.println("Term\t\t\t:"+n);
}
public static void SimpleInterest()
{
System.out.println("\nDisplaying Simple Interest...");
try
{
Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
sim = (princ*n*rate);
System.out.println("\tInterest\t: "+sim);
}
public static void CompInterest()
{
System.out.println("\nDisplaying Compound Interest...");
try
{
Thread.sleep(1000); // do nothing for 1000 miliseconds (1 second)
}
catch(InterruptedException e)
{
e.printStackTrace();
}
double ans = princ*(1+rate/n);
comp = Math.pow(ans,(double)n*4.0);
System.out.println("\tInterest\t: "+comp);
}
/* public static void main(String []args)
{
First f= new First();
f.DisplayData();
f.SimpleInterest();
f.CompInterest();
}*/
}
/* The socond file imports the first file and calculates the interst*/
/*Second.java*/
import pack.First;
class Second
{
public static void main(String[] args)
{
System.out.println("Running Class Second..");
First first = new First();
first.DisplayData();
first.SimpleInterest();
first.CompInterest();
}
}
/* Output
* Running Class Second..
*
* ...Welcome to First Class
*
* Principle Amount :1000.0
* Rate Of Interest :9.0%
* Term :2
*
* Displaying Simple Interest...
* Interest : 180.0
* Displaying Compound Interest...
* Interest : 1.4221006128366082E24
*/
Labels: Core Java
Subscribe to:
Post Comments (Atom)
Rather nice place you've got here. Thanks the author for it. I like such themes and everything that is connected to this matter. BTW, try to add some images :).
Soon i will write something on packages
Just check it, its simple
}}}}}}}}}}}}>>>>>>>>>
http://mu-engineering-semester-2.blogspot.in/