19ucap05 - Java Programming Lab Final
19ucap05 - Java Programming Lab Final
1
TO FIND AREA OF SQUARE, RECTANGLE AND CIRCLE USING
Date: METHOD OVERLOADING
AIM
To write a program to find the area of Square, Rectangle and Circle using Method Overloading.
ALGORITHM
Step 1: Start the Program
Step 3: Create valid class name with necessary functions and variables
Step 4: Create method overloading concept with different parameters by using Switch
Statement
Square
Rectangle
Circle
Exit
Result
Thus the above Java program to find area of square, rectangle and circle using method
overloading has been compiled and executed successfully.
Ex. No. 2
TO SORT THE LIST OF NUMBERS USING COMMAND LINE
ARGUMENTS
Date:
AIM
To write a program to sort the list of numbers using command line Arguments
ALGORITHM
Step 1: Start the Program
Step 3: Create valid class name with necessary functions and variables
Step 4: Create the command line arguments for sort the list of numbers
C:\JavaLab>java Sorting 9 6 0 7 5 3 1
Original Order
9,6,0,7,5,3,1
Ascending Order:
0,1,3,5,6,7,9
RESULT
Thus the above Java program to sort the list of numbers using command line arguments
has been compiled and executed successfully.
Ex. No. 3
TO MULTIPLY THE GIVEN TWO MATRICES
Date:
AIM
To write a program to multiply the given two matrices.
ALGORITHM
Step 1: Start the Program
Step 3: Create valid class name with necessary functions and variables
C:\JavaLab>java MatrixMultiplication
RESULT
Thus the above Java program to multiply the given two matrices has been compiled and
executed successfully.
Ex. No. 4
BANKING DETAILS USING CLASS AND OBJECTS
Date:
AIM
To write a program to design a class to represent a bank account by using data members and
methods.
ALGORITHM
Step 1: Start the Program
Data Members: i) Name of the depositor, ii) Account Number iii) Type of Account
amount after checking banking ( Balance), iv) To display the name and balance
Step 4: To write the Java Program by using above mentioned Data members and Methds.
System.out.println("*******************************************************");
System.out.println("Acc No\tName\t\tAccount Type\tBalance");
System.out.println(Acc_Number+"\t"+Cus_Name+"\t\t"+Acc_Type+"\t\t"+balance);
System.out.println("*********************************************************");
}
public void deposit(double amt)
{
balance+=amt;
System.out.println("Your deposit was successful.");
}
public void withdraw(double money)
{
if(balance<money)
{
System.out.println("Insufficient money");
}
else
{
balance-=money;
System.out.println("Your withdraw Rs :"+money+" was successful.");
}
}
}
class banking
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
int Choice;
System.out.println("\t***************************");
System.out.println("\tABC Banking Private Limited");
System.out.println("\t***************************");
System.out.println("Kindly Provide the following informations to create a new
account"
); System.out.println("Enter your name"); String name=dis.readLine();
System.out.println("Enter your account type");
String type=dis.readLine();
System.out.println("What is your initial deposit amount?");
double amount=Double.parseDouble(dis.readLine());
account obj=new account(name,type,amount);
System.out.println();
System.out.println("Thank you "+obj.Cus_Name+" your new account with us has
been created successfully.");
System.out.println();
obj.display();
do
{
System.out.println();
System.out.println("1. To Deposit Money"); System.out.println("2. To Withdraw Money");
System.out.println("3. To Check Account Balance");
System.out.println("4. To Exit");
System.out.println(); System.out.println("Enter your choice");
Choice=Integer.parseInt(dis.readLine()); switch(Choice)
{
case 1:
System.out.println("How many rupees do you want to deposit");
amount=Double.parseDouble(dis.readLine()); obj.deposit(amount);
break; case 2:
System.out.println("How many rupees do you want to withdraw");
amount=Double.parseDouble(dis.readLine()); obj.withdraw(amount);
break; case 3:
obj.display(); break;
case 4:
System.exit(0); default:
System.out.println("Your choice was wrong");
}
}while(Choice<=4);
}
}
OUTPUT:
C:\JavaLab>javac banking.java
Note: banking.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for
details.
C:\JavaLab>java banking
*************************** ABC Banking Private Limited
***************************
Kindly Provide the following information’s to create a new account Enter your name
Kumar
Enter your account type Savings
What is your initial deposit amount? 5000
Thank you Kumar your new account with us has been created successfully.
To Deposit Money
To Withdraw Money
To Check Account Balance
To Exit
To Deposit Money
To Withdraw Money
To Check Account Balance
To Exit
To Deposit Money
To Withdraw Money
To Check Account Balance
To Exit
To Deposit Money
To Withdraw Money
To Check Account Balance
To Exit
Enter your choice
3
************************************************************
Acc No Name Account Type Balance
1000 Kumar Savings 4000.0
************************************************************
To Deposit Money
To Withdraw Money
To Check Account Balance
To Exit
RESULT
Thus the above Java program to design a class to represent a bank account with help of Data
Members and Methods has been compiled and executed successfully
Ex. No. 5
PACKAGE
Date:
AIM
To write a program that import the user defined package and access the member variable of
classes that contained by Package.
ALGORITHM
Step 1: Start the Program
Step 4: To import user defined package and access the member variable of classes that
contained by Package
PackageDemo.java
import java.io.*;
import Calc.Arithmetic;
class PackageDemo
{
public static void main(String args[])throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
int num1,num2,add,sub,mul,div;
Arithmetic obj=new Arithmetic();
System.out.println("\t*********************");
System.out.println("\tPackage Demonstration");
System.out.println("\t*********************");
System.out.println("Enter two integer number");
num1=Integer.parseInt(dis.readLine());
num2=Integer.parseInt(dis.readLine());
add=obj.addition(num1,num2);
sub=obj.subtraction(num1,num2);
mul=obj.multiplication(num1,num2);
div=obj.division(num1,num2);
System.out.println("The Addition is: "+add);
System.out.println("The Subtraction is: "+sub);
System.out.println("The Multiplication is: "+mul); System.out.println("The Division is: "+div);
}
}
OUTPUT
C:\JavaLab>java PackageDemo
********************* Package Demonstration
********************* Enter two integer number
10
5
The Addition is: 15
The Subtraction is: 5
The Multiplication is: 50
The Division is: 2
RESULT
Thus the above Java program to import the user defined package and access the member
variable of classes that contained by package has been compiled and executed successfully
Ex. No. 6
EXCEPTION HANDLING USING TRY AND MULTIPLE CATCH
Date: BLOCKS
AIM
To write a program to handle the Exception using try and multiple catch blocks.
ALGORITHM
Step 1: Start the Program
Step 3: To create Exception handling with multiple try and catch blocks
RESULT
Thus the above Java program to handle the Exception using try and multiple catch blocks
has been compiled and executed successfully
Ex. No. 7
MULTITHREADS
Date:
AIM
To write a program to illustrate the use of Multithreads
ALGORITHM
Step 1: Start the Program
class MultiThread
{
public static void main(String args[])
{
System.out.println("\n\t\t Multithread Programming\n"); Even r=new Even();
Odd b=new Odd(); r.Even();
b.Odd();
}
}
OUTPUT
RESULT
Thus the above Java program to illustrate the use of Multithreads has been compiled and
executed successfully
Ex. No. 8
STUDENT REGISTRATION FORM USING APPLET
Date:
AIM
To write a program to create student registration form using applet with Name, Address, Sex, Class,
Email-id.
ALGORITHM
Step 1: Start the Program
RESULT
Thus the above Java program to Student registration form using Applet has been compiled and
executed successfully
Ex. No. 9
DRAWING VARIOUS SHAPES USING GRAPHICS METHOD
Date:
AIM
To write a program to draw the line, rectangle, oval, text using the graphics method.
ALGORITHM
Step 1: Start the Program
import java.applet.*;
</applet>
*/
g.setColor(Color.green);
g.drawRect(20,20,165,180);
g.setColor(Color.red);
g.drawOval(40,40,120,150);
g.setColor(Color.yellow);
g.drawOval(57,75,30,20);
g.drawOval(110,75,30,20);
g.setColor(Color.black);
g.fillOval(68,81,10,10);
g.fillOval(121,81,10,10);
g.setColor(Color.orange);
g.drawOval(85,100,30,30);
g.setColor(Color.blue);
g.fillArc(60,125,80,40,180,180);
g.setColor(Color.green);
g.drawOval(25,92,15,30);
g.drawOval(160,92,15,30);
}
Output:
RESULT
Thus the above Java program using the graphics has been compiled and executed successfully
Ex. No. 10
SEQUENTIAL FILE
Date:
AIM
To write a program to create a sequential file that could store details about five products.
Details include product code, cost, and number of items available and are provided through the
keyboard. Compute and print the total value of all the five products
ALGORITHM
Step 1: Start the Program
Step 3: To get the details of the product code, cost and number of items available in particular
Store.
import java.util.*;
import java.io.*;
class Inventory
int code=Integer.parseInt(st.nextToken());
System.out.println("Enter No of Items:");
st=new StringTokenizer(din.readLine());
int Items=Integer.parseInt(st.nextToken());
System.out.println("Enter cost:");
st=new StringTokenizer(din.readLine());
des.writeInt(code);
des.writeInt(Items);
des.writeDouble(cost);
des.close();
int totalItem=dis.readInt();
double itemCost=dis.readDouble();
double totalCost=totalItem*itemCost;
dis.close();
System.out.println();
System.out.println("Item cost:"+itemCost);
System.out.println("total Items:"+totalItem);
System.out.println("total cost:"+totalCost);
}
OUTPUT:
123
Enter cost :
100
Total items : 5
RESULT
Thus the above Java program using the sequential file has been compiled and executed
successfully