Assignments Pooja Gaikwad
Assignments Pooja Gaikwad
Batch-5
Exercise 1:
java program to illustrate the use of rectangle triangle class which has length and width data
members
Output:
Type 2: Using Object calling method & variables
class Rectangle2
{
int width=5;
int height=10;
void Area_rect()
{
System.out.println("Width is: "+width);
System.out.println("Height is: "+height);
int Area=width*height;
System.out.println("Area of Rectangle: "+Area);
}
public static void main(String args[])
{
Rectangle2 R1=new Rectangle2();
R1.Area_rect();
}
}
Output:
Type 3: Using two classes calling method & variables (Without Arguments)
class Rect
{
int width;
int height;
void Area_rect() //Without Arguments
{
System.out.println("Width is: "+width);
System.out.println("Height is: "+height);
int Area=width*height;
System.out.println("Area of Rectangle: "+Area);
}
}
class Rectangle3
{
public static void main(String args[])
{
Rect R1=new Rect();
Rect R2=new Rect();
R1.width=5;
R1.height=10;
R1.Area_rect();
R2.width=10;
R2.height=6;
R2.Area_rect();
}
}
Output:
Type 3.1: Using two classes calling method & variables(with Arguments)
import java.util.Scanner;
class Rect123
{
int width;
int height;
class Rectscan
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
Output:
Exercise 2:
java program to demonstrate the working of a banking system where we deposit and
withdraw amount from our account. creating an account class which has deposit() and
withdraw() methods.
Type 1: Without Object
class Bank1
{
public static void main(String args[])
{
int AccNo=1001;
float Balance=10000;
float Amount=100;
void Withdraw_Amount()
{
float Withdraw = Balance-Amount;
System.out.println("Amount withdrawal !!... Current Balance is: "+Withdraw);
}
}
class Bank3
{
public static void main(String args[])
{
Bankdetails B1=new Bankdetails();
Bankdetails B2=new Bankdetails();
B1.AccNo=1001;
B1.Balance=10000;
B1.Amount=100;
B1.Deposite_Amount();
B1.Withdraw_Amount();
B1.AccNo=1002;
B1.Balance=20000;
B1.Amount=200;
B1.Deposite_Amount();
B1.Withdraw_Amount();
}
}
Output:
Type 3.1: Using two classes calling method & variables (with Arguments)
import java.util.Scanner;
class Bankdetails123
{
int AccNo;
float Balance;
float Amount;
void Deposite_Amount()
{
float Deposite= Balance+Amount;
System.out.println("Deposited !!... Current Balance is: "+Deposite);
}
void Withdraw_Amount()
{
float Withdraw = Balance-Amount;
System.out.println("Amount withdrawal !!... Current Balance is: "+Withdraw);
}
}
class Bankscan
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
/* In this program I have implement all the classes, Attributes, Method as per given
statements also use this keyword, Super, Parameterized constructor and Scanner for taking
input from user. */
import java.util.Scanner;
class Employee
{
int emp_id;
String empname;
Employee(int emp_id,String empname) //Parameterized constructor
{
this.emp_id=emp_id; //this reference
this.empname=empname;
}
}
class Salary extends Employee
{
String designation;
float monthly_salary;
Salary(int emp_id, String empname, String designation, float monthly_salary)
//Parameterized constructor
{
super(emp_id,empname); //Super keyword
this.designation=designation;
this.monthly_salary=monthly_salary;
}
void display()
{
if(monthly_salary>20000)
{
System.out.println("Employee ID is: "+emp_id);
System.out.println("Employee Name is: "+empname);
System.out.println("Employee designation is: "+designation);
System.out.println("Employee Salary is: "+monthly_salary);
}
else
{
System.out.println("No Data Found...");
}
}
}
public class Empdata{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter how much employees details you want: ");
int x = sc.nextInt();
for(int i=0;i<x;i++)
{
System.out.println("Enter Employee Id: ");
int emp_id = sc.nextInt();
System.out.println("Enter Employee name: ");
String empname = sc.next();
System.out.println("Enter designation of Employee: ");
String designation = sc.next();
System.out.println("Enter Employee Salary: ");
float monthly_salary = sc.nextFloat();
interface Shape
{
double Area();
double Perimeter();
}
class Square implements Shape
{
double length;