Java Lab Examination 2021
Java Lab Examination 2021
Java Lab Examination 2021
1. Write a program using class to take fixed deposit at 8.5% rate of annual interest for 1 year and print the name, address, account number,
deposit and matured amount.
2. Write a Program to declare a class ICSE with three data members name, index number, marks in physics, Chemistry, Biology, and a
member function to assign grades as per given table
90 % and above - A
75 % -89 % - B
60% to 74 % - C
35% to 59 % - D
34 % and less – E
3. Write a Program to calculate volume of Box using Class and object.
4. Write a program to take two integer value and perform addition, subtraction, division using Class and object.
5. Create a class Big and define two-member function. One function will take two integer data item from the input and by use of another
member function will calculate the biggest out of two and display the result.
6. An electricity board charges the following rates to domestic users to discourage large consumption of energy :
1
Answer of the assignment:
4.
class compu
{
int a;
int b;
void add()
{
int s=a+b;
void sub()
{
int d=a-b;
System.out.println("Substraction is :"+d);
void multi()
{
int m=a*b;
System.out.println("Multiplication is :"+m);
}
2
void div()
{
int f=a/b;
System.out.println("Division is :"+f);
c.a=10;
c.b=5;
c.add();
c.sub();
c.multi();
c.div();
}
Output :
3
5.
import java.util.Scanner;
class big
int a;
int b;
big(int x, int y)
{
a=x;
b=y;
void max()
{
if(a>b)
{
System.out.println("value of A is big");
}
else
{
System.out.println("value of B is big");
}
}
}
4
public class ass12 {
Output :
6.
import java.util.Scanner;
class elect
5
{
int total_units;
String name;
elect(int x, String y)
{
total_units=x;
name=y;
void compute()
{
double min_charge=100.00,charge=00.0;
if(total_units <=100)
charge=min_charge+(total_units*.40);
if(total_units<=300)
charge=min_charge+(100*.40)+((total_units-100)*.50);
if(total_units>=300)
charge=min_charge+(100*.40)+(200*.5)+((total_units-300)*.6);
if(charge>250.00)
charge=charge+charge*.15;
6
}
System.out.println("Enter Name");
String n=sc.nextLine();
int p=sc.nextInt();
e1.compute();
1.
7
import java.util.Scanner;
class Bank
{
float balance;
float rate;
Bank(float x, float y)
{
balance=x;
rate=y;
}
void deposit()
{
float amt;
amt=sc1.nextFloat();
balance+=amt;
System.out.println("Your Current Balance is :"+balance);
}
void withdraw()
{
float amt;
System.out.println("How much you want to Withdraw:");
8
amt=sc1.nextFloat();
if(amt<=balance)
{
balance-=amt;
System.out.println("Withdraw Balance is :"+amt);
System.out.println("Current Balance is :"+balance);
}
else
{
9
System.out.println("3->compound");
System.out.println("4->getbalance");
float f=sc.nextFloat();
System.out.println("Enter Interest Rate");
float m=sc.nextFloat();
int ch;
b1.menu();
ch=sc.nextInt();
switch(ch)
10
{
case 1 :
b1.deposit();
break;
case 2 :
b1.withdraw();
break;
case 3 :
b1.compound();
break;
case 4 :
b1.getbalance();
break;
default :
System.out.println("Wrong choice :");
break;
Output :
11
2.
import java.util.Scanner;
int m;
Scanner sc=new Scanner(System.in);
System.out.println("Enter marks");
m=sc.nextInt();
if(m>=90)
{
System.out.println("The Grade is O");
}
else
if(m>=80)
12
{
System.out.println("The grade is E");
}
else
if(m>=70)
{
System.out.println("A");
}
else
if(m>=60)
{
System.out.println("B");
}
else
{
System.out.println("fail");
}
}
}
Output
13