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

ASSIGNMENT java

The document contains a Java assignment with multiple programming tasks, including creating an ATM machine simulation, defining an Employee class, and implementing a Book class with associated information. It also includes a Salary class with an interface for calculating net salary, a Circle class for area calculation, and a Student class for managing student data. Each task is accompanied by code examples demonstrating the required functionality.

Uploaded by

jsamiksha051
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)
2 views

ASSIGNMENT java

The document contains a Java assignment with multiple programming tasks, including creating an ATM machine simulation, defining an Employee class, and implementing a Book class with associated information. It also includes a Salary class with an interface for calculating net salary, a Circle class for area calculation, and a Student class for managing student data. Each task is accompanied by code examples demonstrating the required functionality.

Uploaded by

jsamiksha051
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/ 8

ASSIGNMENT 2(JAVA)

CHAPTER 1:

Q1) WRITE A PROGRAM WHICH DISPLAYS FUNCTIONING OF ATM MACHINE.

import java.util.*;

class Assignment2
{
public static void main(String args[])
{
int balance=40000;
int deposit,withdraw;
int choice=0;
while(choice!=4)
{
Scanner sc=new Scanner(System.in);
System.out.println("1.WITHDRAW");
System.out.println("2.DEPOSIT");
System.out.println("3.CHECK BALANCE");
System.out.println("4.EXIT");
System.out.println("enter :");
choice=sc.nextInt();
switch(choice)
{
case 1:System.out.println("WITHDRAW");
System.out.println("ENTER THE WITHDRAW AMOUNT:");
withdraw=sc.nextInt();
if(withdraw<=balance)
{
balance=balance-withdraw;
System.out.println("MONEY WITHDRAWED");
}
else
{
System.out.println("INSUFFICIENT BALANCE");
}
break;

case 2: System.out.println("DEPOSIT");
System.out.println("ENTER THE AMOUNT TO BE DEPOSITED:");
deposit=sc.nextInt();
balance=balance+deposit;
System.out.println("AMOUNT DEPOSITED IN THE ACCOUNT !!!");
break;

case 3:System.out.println("CHECK BALANCE");


System.out.println("YOUR BALANCE IS:"+balance);
break;

case 4:
System.out.println("EXIT");
break;

default:
System.out.println("WRONG CHOICE!!");
}
}
}
}

Q2) define a class Employee with data member empid,name and


salary. accept data for object display it .

import java.util.*;
public class Employee
{
int empid,salary;
String name;
Scanner sc=new Scanner(System.in);
void get()
{
System.out.println("enter name of employee:");
name=sc.nextLine();
System.out.println("enter empid:");
empid=sc.nextInt();
System.out.println("enter salary:");
salary=sc.nextInt();
}
void display()
{
System.out.println("name of employee is:"+name);
System.out.println("employee id is:"+empid);
System.out.println("Salary of employee is:"+salary);
}
public static void main(String[] args) {
Employee e=new Employee();
e.get();
e.display();
}
}
Output:

Q3)Develop a program to create a class ‘book’ having data


members author,title and price. drive a class “BookInfo” having
data member stockinfo and method initialize and display the
information for three objects.
import java.util.*;
class book
{
String author,title;
int price;
}
class Bookinfo extends book
{
String stockinfo;
Bookinfo(String author,String title,String stockinfo,int price)
{
this.title=title;
this.author=author;
this.stockinfo=stockinfo;
this.price=price;
}
void display()
{
System.out.println("...............");
System.out.println("TITLE OF BOOK:"+title);
System.out.println("AUTHOR OF BOOK:"+author);
System.out.println("STOCK INFO:"+stockinfo);
System.out.println("PRICE OF BOOK:"+price);
}
}
class Main
{
public static void main(String[] args) {
Bookinfo B=new Bookinfo("MR.RAJ","GLODEN","100",1000);
B.display();
Bookinfo b1=new Bookinfo("mrs.savita","ABC","60",800);
b1.display ();
Bookinfo b2=new Bookinfo("mrs.xyz","sweet","69",900);
b2.display();
}
}
OUTPUT:

Q4) Write a program to create a class Salary with data members


empid,name,basic salary. Write interface Allowance which stores
rate of calculation for da as 90% of basic salary and hra as 10% and
pf as 8.33%.include a method to calculate net salary and display it.

interface allowance
{
double da=0.9*basicsalary;
double hra=0.1*basicsalary;
double pf=0.0833*basicsalary;
void netSalary();

}
class Salary
{ int empid;
String name;
float basicsalary;
Salary(int i, String n, float b)
{
empid=I;
name=n;
basicsalary =b;
}
void display()
{
System.out.println("Empid of Emplyee="+empid);
System.out.println("Name of Employee="+name);
System.out.println("Basic Salary of Employee="+ basicsalary);

}
class net_salary extends salary implements allowance
{
float ta;
net_salary(int i, String n, float b, float t)
{
super(i,n,b);
ta=t;

}
void disp()
{ display();
System.out.println("da of Employee="+da);
}
public void netsalary()
{ double net_sal=basicsalary+ta+hra+da;
System.out.println("netSalary of Employee="+net_sal);

}
class Main
{
public static void main(String[] args) {
net_salary s=new net_salary(11, “abc”, 20000);
s.disp();
s.netsalary();
}
}

Q5) Define a class circle having data members pi and radius.


Initialize and display values of data members also calculate area of
circle and display it.
import java.util.*;
class Circle
{
float pi=3.14f,radius;
float area;
Circle(float radius)
{
this.radius=radius;
}
void area()
{
area=pi*radius*radius;
System.out.println("AREA OF CIRCLE IS:"+area);
}
}
class Main
{
public static void main(String[] args) {
Circle c=new Circle(12.05f);
c.area();
}
}
OUTPUT:

Q6)Define a class student with int id and string name as data


member and a method void setData() . accept and display for 5
object.
import java.util.*;
class student
{
int id;
String name;
Scanner sc=new Scanner(System.in);
void setData()
{
System.out.println("Enter name=");
name=sc.nextLine();
System.out.println("Enter id=");
id=sc.nextInt();
}
void Display()
{
System.out.println("name="+name);
System.out.println("id="+id);
}

public static void main(String args[])


{
student s[]=new student[5];
for(int i=0;i<5;i++)
{
s[i]=new student(); //
s[i].setData();
s[i].Display();
}
}
}

You might also like