0% found this document useful (0 votes)
141 views

Experimen Inter Net

The document describes two programming experiments: 1. A program to print employee information by creating an Employee class with name, year of joining, and address attributes. Three Employee objects are created and their display() method is called to output the information. 2. A banking program with deposit() and withdraw() methods. The main() uses a switch case to allow the user to choose deposit or withdraw, and calls the appropriate method, outputting the new balance.

Uploaded by

Reshu Duggal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Experimen Inter Net

The document describes two programming experiments: 1. A program to print employee information by creating an Employee class with name, year of joining, and address attributes. Three Employee objects are created and their display() method is called to output the information. 2. A banking program with deposit() and withdraw() methods. The main() uses a switch case to allow the user to choose deposit or withdraw, and calls the appropriate method, outputting the new balance.

Uploaded by

Reshu Duggal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Experimen -1

Student Name: Raghav kumar UID: 19bca1469


duggal
Branch: BCA Section/Group: 19BCA2/b
Semester: 4th Date of Performance: 26 Feb 2021
Subject Name: Internet Programming Lab Subject Code: CAP-256

A.1. Aim/Overview of the practical: Write a program that would print the
information (name, year of joining, salary, address) of three employees by creating a
class named 'Employee'. The output should be as follows:
Name Year of joining Address
Robert 1994 64C- WallsStreat
Sam 2000 68D- WallsStreat
John 1999 26B- WallsStreat

A.2.Algorithm:

i. Open a File with the Name Exp1.java.


ii. Create class Exp1, under which define main function.
iii. Create another class Employee, declare variable.
iv. Define Constructor which assigns value to variable.
v. Define a display function.
vi. In main function, Create Object for Employee and pass value.
vii. Display the value using display function.

` A.3.Code for experiment/practical:


import java.util.*; class Employee
{
String name; int year; String addr;
Employee(String n,int y,String a)
{
name=n;

year=y; addr=a;
}
void display()
{
System.out.println(name+"\t\t"+year+"\t\t"+addr);
}
};
class Exp1
{
public static void main(String[] args) { System.out.println("Name"+"\t\t"+"Year of Joining"+"\t\t"+"Address");
Employee e1=new Employee("Robert",1994,"64C-WallsStreat"); Employee e2=new Employee("Sam",2000,"68D-
WallsStreat"); Employee e3=new Employee("John",1999,"26B-WallsStreat");

e1.display();
e2.display();
e3.display();
}
}
A.4.Result/Output/Writing Summary:
B.1. Aim/Overview of the practical: Write a program to demonstrate the working of a banking
system where we deposit and withdraw amount from our account. Create function which
performs deposit transactions and one which perform withdraw transactions.
B.2.Algorithm:

i. Open a File with the name Exp2.java.


ii. Create class Exp2, under which define main function.
iii. Define deposit, display and withdraw function under Exp2 class.
iv. In main function, use switch to give option for function.

B.3.Code for experiment/practical:


import java.util.Scanner;

public class Bank

int balance=0;

public void deposit(int amount)

balance=balance+amount;

System.out.println("\nAmount is deposit in your account: "+amount);

System.out.println("\nNew balance of your acount is: "+balance);

public void withdraw(int amount)

if(amount<balance)

balance=balance-amount;

System.out.println(amount + " is withdraw from your acount");

System.out.println("Total balance is " + balance);


}

else

System.out.println("insufficent balance: " + balance);

public static void main(String[]args)

int choice=0;

Bank bank =new Bank();

System.out.println("Thanku for visting for our bank");

while(choice<3)

Scanner obj = new Scanner(System.in);

System.out.print("\npress 1. Enter the amount");

System.out.print("\npress 2.Widraw amount\n");

choice= obj.nextInt();

switch(choice)

case 1:

System.out.print("\nEnter the amount to deposite: ");

int depositeAmount= obj.nextInt();

bank.deposit(depositeAmount);

break;

case 2:

System.out.print("\nEnter the amount to withdraw: ");

int withdrawAmount = obj.nextInt();


bank.withdraw(withdrawAmount);

break;

B.4.Result/Output/Writing Summary:
Learning Outcomes:
i. I got to know about Java and its Syntax.
ii. About Java Class.
iii. About Scanner Package.
iv. Switch Case Implementation in Java.

You might also like