Write a program to understand concept of packages.
/*
Aim : Write a program to understand concept of packages.
*/
first of all create folder MyPack (case sensitive ). in that folder create balance.java file with following code
package MyPack;
import java.io.*;
public class balance
{
String name,address,mob;
double bal;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
/*public balance()
{
System.out.println("\tPlease Create your account ...");
}
public balance(String n,double b)
{
name=n;
bal=b;
}*/
public void init() throws Exception
{
System.out.print("\n\tEnter name : ");
name=br.readLine();
System.out.print("\n\tEnter Address : ");
address=br.readLine();
System.out.print("\n\tEnter Mobile no : ");
mob=br.readLine();
System.out.print("\n\tEnter Ammount for initialization of account : ");
bal=Double.parseDouble(br.readLine());
}
public void show()
{
if(bal<0)
System.out.println("\t -->");
else
System.out.println("\t"+name + " : $"+bal);
}
}
now compile above file and make sure that .class file is created in folder MyPack
after that write following file pr_5.java outside MyPack folder
Program :
import MyPack.*;
class pr_5
{
public static void main(String argv[]) throws Exception
{
balance test = new balance();
System.out.println("********Creation of Account************");
test.init();
System.out.println("\n\n********Display Balance ***************\n");
test.show();
}
}
/* OUTPUT
prashant@prashant-OptiPlex-755:~$ javac pr_4.java
prashant@prashant-OptiPlex-755:~$ java pr_4
********Creation of Account************
Enter name : prashant
Enter Address : Sangamner,Ahmed Nagar
Enter Mobile no : 9921074899
Enter Ammount for initialization of account : 100
********Display Balance ***************
prashant : $100.0
prashant@prashant-OptiPlex-755:~$
*/
0 comments:
Post a Comment