Java Lab Examination 2021

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Dumkal Institute of Engineering & Technology

Laboratory Examination -2021

Paper Name :Programming Lab with Java , Code: BCAN-492

Stream – BCA, Sem -4th , Full marks-60.

Attempt any three (20x3=60)

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 :

For the first 100 units - 40p /unit


For the next 200 units - 50p /unit
Above 300 units - 60p /unit
All users are charged a minimum of Rs. 100/-. If the total cost is more than Rs. 250/- then an additional surcharge @15% is added.
Write a program to read the names of users and numbers of units consumed and print out the charges with names.

1
Answer of the assignment:
4.
class compu
{
int a;
int b;

void add()
{

int s=a+b;

System.out.println("Addition of Two Numbers is :"+s);

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);

public class ass1 {

public static void main(String[] args) {

compu c=new compu();

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 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("enter value for a");


int m=sc.nextInt();

System.out.println("enter value for b");


int n=sc.nextInt();

big b1=new big(m,n);


b1.max();
}

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;

System.out.println("The charge is :" +charge);

6
}

public class ass15 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("Enter Name");

String n=sc.nextLine();

System.out.println("Enter total units");

int p=sc.nextInt();

elect e1=new elect(p,n);

e1.compute();

1.
7
import java.util.Scanner;

class Bank
{
float balance;
float rate;

Scanner sc1=new Scanner(System.in);

Bank(float x, float y)
{

balance=x;
rate=y;
}

void deposit()
{
float amt;

System.out.println("Enter the amount");

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
{

System.out.println("You have not Enough Balance :");


}
}
void compound()
{
float interest;
interest=balance*rate;
balance+=interest;
System.out.println("Interest amount :="+interest);
System.out.println("Total Amount :="+balance);
}
void getbalance()
{
System.out.println("Current Balance:"+balance);
}
void menu()
{
System.out.println("Welcome to Our Bank:");
System.out.println("...................");
System.out.println("1->deposit");
System.out.println("2->withdraw");

9
System.out.println("3->compound");
System.out.println("4->getbalance");

public class ass16 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.println("Enter Initial Balance");

float f=sc.nextFloat();
System.out.println("Enter Interest Rate");
float m=sc.nextFloat();

Bank b1=new Bank(f,m);

int ch;

b1.menu();

System.out.println("Choose your option");

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;

// TODO Auto-generated method stub

Output :

11
2.
import java.util.Scanner;

public class grade {

public static void main(String[] args) {


// TODO Auto-generated method stub

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

You might also like