JAVA PRACTICLE FILE Yatin
JAVA PRACTICLE FILE Yatin
07211402020
BPIBS
BCA-4TH SEM
INDEX
2
Write a program to calculate simple
interest and input should be by the user
3
Write a program to find the average and
sum of n numbers using command line
argument.
4
Write a program to find the number of
arguments provided at command line.
5
Write a program to find GCD of a number
input by the user.
6
Write a program to create a simple class to
find out the area and perimeter of
rectangle
7
Write a program to find sum of elements of
a one-dimensional array entered
dynamically by the user
8
Write a program to find multiplication of
two 3X3 matrices. Data should be entered
by user
9
Write a program to demonstrate type
casting.
10
WAP to create the Person class. Create
some objects of this class
11
Assume that a bank maintains two kinds
account for its customers
2
Yatinder singh rawat
07211402020
Programs
3
Yatinder singh rawat
07211402020
4
Yatinder singh rawat
07211402020
5
Yatinder singh rawat
07211402020
6
Yatinder singh rawat
07211402020
class gcdClass
{
}
public gcdClass(int a, int b)
{
num1 = a;
num2 = b;
}
7
Yatinder singh rawat
07211402020
break;
}
}
System.out.println("GCD of " + num1 + " and " + num2 + " =
" + gcd);
}
}
8
Yatinder singh rawat
07211402020
Output:
9
Yatinder singh rawat
07211402020
class Rectangle
{
private double length;
private double breadth;
}
class Practical_6
{
public static void main(String args[])
{
10
Yatinder singh rawat
07211402020
}
}
Output:
11
Yatinder singh rawat
07211402020
12
Yatinder singh rawat
07211402020
{
for(int i = 0; i<arr.length; i++)
{
System.out.print(arr[i] + " ");
}
System.out.println();
}
public void add()
{
int addition = 0;
for(int i = 0;i<arr.length;i++)
{
addition += arr[i];
}
System.out.println("Addition = "+addition);
}
}
Output:
13
Yatinder singh rawat
07211402020
public matrix()
{
}
public matrix(matrix b)
{
arr1 = b.arr1;
}
void getValues()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
14
Yatinder singh rawat
07211402020
void show()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
System.out.print(arr1[i][j] + "\t");
}
System.out.println();
}
matrix multiplication_of_matrix(matrix b)
{
matrix c = new matrix();
System.out.println();
System.out.println("Multiplication Of Two Matrices : ");
for (int i = 0; i <3; i++)
{
int sum =0;
for (int j = 0; j <3; j++)
{
sum = 0;
for (int k = 0; k <3; k++)
{
sum = sum + arr1[i][k] * b.arr1[k][j];
}
c.arr1[i][j] = sum;
}
}
return c;
}
15
Yatinder singh rawat
07211402020
}
public class Practical_8
{
public static void main(String[] args) {
matrix obj=new matrix();
obj.getValues();
obj.show();
matrix obj2 = new matrix();
obj2.getValues();
obj2.show();
matrix obj3 = new matrix();
obj3 = obj.multiplication_of_matrix(obj2);
System.out.println("After multiplication: ");
obj3.show();
}
}
Output: 1)
16
Yatinder singh rawat
07211402020
2)
17
Yatinder singh rawat
07211402020
18
Yatinder singh rawat
07211402020
class Person
{
private String name;
private int age;
public void setName(String a)
{
name = a;
}
public void setAge(int a)
{
age = a;
}
19
Yatinder singh rawat
07211402020
}
class Student extends Person
{
private int rollNo;
}
class Teacher extends Person
{
private int id;
20
Yatinder singh rawat
07211402020
int rollNo;
System.out.print("Enter roll no : ");
rollNo = input.nextInt();
s1.setRollNo(rollNo);
21
Yatinder singh rawat
07211402020
Person ptr;
ptr = s1;
ptr.showData();
int id;
ptr = t1;
ptr.showData();
}
}
22
Yatinder singh rawat
07211402020
Output:
23
Yatinder singh rawat
07211402020
11. Assume that a bank maintains two kinds account for its
customers. one called savings account and the other current
account. The savings account provides compound interest and
withdrawal facilities but no cheque book facility. The current
account provides cheque book facility but no interest. Current
account holders should also maintain a minimum balance and
if the balance falls below this level, a service charge is
imposed. Create a class Account that stores customer name,
account number and type of account, from this derive the
classes Curr-acct and Sav-acct to make them more specific to
their requirements. Include the necessary methods in order to
achieve the following tasks: a) Accept deposit from a
customer and update the balance. b) Display the balance. c)
Compute and deposit interest. (d) Permit withdrawal and
update the balance. (c) Check for the minimum balance,
impose penalty, if necessary, and update the balance. Use
constructors to initialize the class members.
Code:
import java.util.Scanner;
class Account {
public static int min = 500;
static int sInterest = 5;
static int cInterest = 5;
String name;
long Account_num;
float Amount;
boolean cheque;
Scanner sc = new Scanner(System.in);
void get_info() {
System.out.println("Enter Name:");
name = sc.nextLine();
System.out.println("Enter Account Number:");
Account_num = sc.nextLong();
24
Yatinder singh rawat
07211402020
void show_info() {
System.out.println("");
System.out.println("Name - " + name);
System.out.println("Account_Number - " + Account_num);
System.out.println("Amount - " + Amount);
System.out.println();
}
void chequeFacility()
{
if(cheque==true)
{System.out.println("Cheque Facility Availabel.");
}
else System.out.println("Facility No Available.");
}
}
{cheque=false;}
void deposit() {
System.out.println("Enter Amount to be Deposited");
deposit = sc.nextFloat();
Amount += deposit;
25
Yatinder singh rawat
07211402020
void withdraw() {
System.out.println("Enter Amount to Withdraw");
withdraw = sc.nextFloat();
void compute_interest() {
interest = (Amount * 2) / 100;
Amount += interest;
void deposit() {
System.out.printf("Enter Amount to be Deposited = ");
deposit = sc.nextFloat();
26
Yatinder singh rawat
07211402020
Amount += deposit;
void withdraw() {
System.out.printf("Enter Amount to Withdraw = ");
withdraw = sc.nextFloat();
penalty();
}
else
{
System.out.println("After Withdrawl Your Balance is =
" + Amount);
}
}
void penalty() {
if (Amount < min) {
if(cInterest == 1)
{
System.out.println("Your Balance is Less than 500 After
withdrwal = "+ Amount);
System.out.println("You have to pay Penalty of 150
Ruppee");
27
Yatinder singh rawat
07211402020
Amount -= 15011111;
System.out.println("Your Total Balance After Paying
Penalty = " + Amount);
cInterest = 5;
}
else {
System.out.println("Time Remaining.");
cInterest--;
}
}
}
}
if (ch=='s' || ch == 'S') {
sv.get_info();
while (count != 5) {
System.out.println();
System.out.println();
28
Yatinder singh rawat
07211402020
System.out.println("1.Display\n2.Deposit\n3.Withdraw\n4.Inte
rest\n5.Cheque Faciity\n6.Exit....");
System.out.printf("Enter Choice -");
int choice = sc.nextInt();
switch (choice) {
case 1:
sv.show_info();
break;
case 2:
sv.deposit();
break;
case 3:
sv.withdraw();
break;
case 4:
sv.compute_interest();
break;
case 5:
sv.chequeFacility();
break;
case 6:
System.exit(0);
break;
default:
System.out.println("Invalid Choice");
}
}
29
Yatinder singh rawat
07211402020
while (count != 4) {
System.out.println();
System.out.println("\n1.Display\n2.Deposit\n3.Withdraw\n4.C
heque Facility\n5.Exit");
System.out.printf("Enter Choice -");
int choice = sc.nextInt();
switch (choice) {
case 1:
cu.show_info();
break;
case 2:
cu.deposit();
break;
case 3:
cu.withdraw();
break;
case 5:
System.exit(0);
break;
case 4:
cu.chequeFacility();
break;
default:
System.out.println("Invalid Choice");
}
}
} else {
System.out.println("Wrong choice!");
}
30
Yatinder singh rawat
07211402020
}
Output:
1)
2)
31
Yatinder singh rawat
07211402020
3)
4)
5)
32
Yatinder singh rawat
07211402020
6)
7)
33