Assignment 2
NAME: NISHA SHAILESHBHAI VARMA
ENROLLMENT NO:21SE02IT064
COURSE: B.Tech IT
SEMESTER: SECOND
SUB CODE: SEIT1030
SUB NAME: OBJECT ORIENTED PROGRAMMING WITH JAVA
ASSIGNMENT NO:02
PROGRAMME NO:1
DEFINITION: create a class named ‘student’ with string ‘name’
and integer ‘roll_no ’. assign the value of roll_no as’101’ and that
of name as ‘java’ by creating object of the class.
Input:
Output:
PROGRAM NO :2
DEFINITION: write a program to print the area and perimeter of triangle
having side of 3,4,5units by creating a class named ‘triangle’ without any
parameter in its constructor.
Input:
Output:
PROGRAM NO :3
DEFINITION: develop minimum 4 program based on variation in method
i.e. passing by value, passing by reference, returning value and returning
object from methods.
Input:
Output:
PROGRAM NO :4
DEFINITION : Write a static block which will be executed before main()
method in a class.
Input:
Output:
PROGRAM NO:5
DEFINITION: Write a program in java to demonstrate the use of various
access modifiers in java.
Input:
Output:
PROGRAM NO:6
DEFINITION: Write a program to check whether inputted number is
Armstrong or not using method. (hint: example number (153)=1^3=1,
5^3=125 and 3^3=27 and (1+125+27)=153.)
Input:
Output:
PROGRAM NO:7
DEFINITION: write a java program to find area of square, rectangle and
circle using method overloading.
Input:
Output:
PROGRAM NO:8
DEFINITION: Write a program to demonstrate the use of constructor
overloading.
Input:
OUTPUT:
PROGRAM NO:9
DEFINITION: Write a java program to demonstrate the working of a
banking-system where we deposit and withdraw amount from our account.
Input:
import java.util.*;
class bank
{
int acc_no;
String name;
float amount;
void insert(int a,String nm,float amt)
{
acc_no=a;
name=nm;
amount=amt;
}
void deposit(float amt)
{
amount=amount+amt;
System.out.println(amt+" deposited");
}
void withdraw(float amt)
{
if(amount<amt)
{
System.out.println("Insufficient Balance");
}
else
{
amount=amount-amt;
System.out.println(amt+" withdrawn");
}
}
void checkBalance()
{
System.out.println("Balance is: "+amount);
}
void display ()
{
System.out.println(acc_no+" "+name+" "+amount);
}
}
class A209
{
public static void main (String [] args)
{
Scanner sc=new Scanner (System.in);
int acc_no;
float amt;
float deposit_amt, withdraw_amt;
System.out.print("Enter Customer Account Number:");
acc_no=sc.nextInt();
System.out.print("Enter Customer Name: ");
String n=sc.next();
System.out.print("Enter Opening Amount: ");
amt = sc.nextFloat();
System.out.print("Enter amount to deposit: ");
deposit_amt=sc.nextFloat();
System.out.print("Enter amount to withdraw: ");
withdraw_amt=sc.nextFloat();
bank a1=new bank();
a1.insert(acc_no,n,amt);
a1.display();
a1.checkBalance();
a1.deposit(deposit_amt);
a1.checkBalance();
a1.withdraw(withdraw_amt);
a1.checkBalance();
}
output: