0% found this document useful (0 votes)
20 views26 pages

Chapter 6 Programs

programs

Uploaded by

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

Chapter 6 Programs

programs

Uploaded by

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

Programs 1

Define class Rectangle


Data members : l and b
Member methods
findArea- to input the length and breadth .calculate area and print it
define main() method to create two objects and implement the
member method
Programs 2
Define a class student with attributes roll, name,m1 and m2( two
marks)
Member methods:
findAverage()- to input values , find average and to display all details
Define main() method to create two objects and implement the
member methods.
Program 3
Define a class student with attributes roll, name, m1,m2 and avg
Member methods:
getData()- to input values
average()- to calculate average
display() to display all details
Create an object named to represent a student implement the
methods.
Program 4

Define a class Employee


Attributes: code, name, basic
Member methods :
compute()- to input values to calculate and display code, name, basic, da, hra, pf, gs and
net salary of an employee
Calculation : da(dearness allowance) is 15% of basic
hra(house rent allowance) is rs 4000.0
pf(provident fund) is 12% of basic
gs(gross salary) is basic+da+hra
The ns(net salary) is gs-pf
import java.util.Scanner;

class Employee

private int code;

private String name;

private double basic;

private double da;

private double hra = 4000.0;

private double pf;

private double gs;

private double ns;

public void compute()

Scanner sc = new Scanner(System.in);

System.out.print("Enter Employee Code: ");

code = sc.nextInt();

sc.nextLine();

System.out.print("Enter Employee Name: ");

name = sc.nextLine();

System.out.print("Enter Basic Salary: ");

basic = sc.nextDouble();

da = 0.15 * basic;

pf = 0.12 * basic;

gs = basic + da + hra;

ns = gs - pf;

System.out.println("Employee Code: " + code);


Program 5
Define class IncomeTax with attributes names::
msalary(monthly salary)
asalary(annual salary)
itax(income tax)
• Member methods:
• accept() – to accept values from the user.
• Calculate()- to calculate annual salary from income tax .
if annual salary is above 1lakh income tax is 8% of the
annual salary
 above 1.5 lakh then 10%
 above 2 lakh then 15%
• Print() to print the details
• Create an object and implement the methods
import java.util.Scanner;

class IncomeTax

private double msalary;

private double asalary;

private double itax;

String name ;

public void accept()

Scanner sc = new Scanner(System.in);

System.out.print("Enter your name: ");

name = sc.nextLine();

System.out.print("Enter Monthly Salary: ");

msalary = sc.nextDouble();

public void calculate()

asalary = msalary * 12;

if (asalary > 200000) {

itax = asalary * 0.15;

} else if (asalary > 150000) {

itax = asalary * 0.10;

} else if (asalary > 100000) {

itax = asalary * 0.08;

} else {

itax = 0;

}
6::Define a class Security having the following description
Class name: Security
Data members/instance variables
String n : to store name of the security personnel
Int h: to store number of hours for which wages are to be paid
Double r: to store the hourly rate
Double w : to calculate the wages
Member methods:
• Void get() : to accept name .rate ,and number of hours worked
• Void calwage(): claculates the wages of security personnel
• Void display(): displays the details of security personnel
However security personnel are not allowed to work for more than
70 hours a week.
Write a program to compute the wage according to the gicen
condition and display the output as per given format
Number of hours Rate
Up to 40 hrs Rs. 1 r per hour
Up to next 20 hrs Rs 1.5 r per hour
For next 20 hrs Rs 2 r per hour

Output: Name Hours


Wages
NEXT PROGRAMS QUESTIONS
• Write these questions in your note book and leave 2 pages for writing
programs
Program 7
Spong iron company announces an increment for their employees on seniority
basis as per the given conditions
Age 56 years and above increment 20% of basic
Above 45 and below 56 years 15% of basic
Upto 45 10% of basic
Write a program to find new basic by using the following class specifications
Class : Increment
Data members/instance variables
String name : name of the employee
double basic: basic pay of the employee
int age: age of the employee
member methods:
void getdata(string n, double b, int a ) : to accept name, basic.age of the employee
void calculate(): to find increment and update basic
void display() to display age and updated basic in the format given below:
Name Age updated basic
Program 8
• Define a class salary described as below :
Data Members: Name, Address, Phone, Subject Specialisation,
Monthly Salary, Income Tax.
Member methods:
(i) To accept the details of a teacher including the monthly salary.
(ii) To display the details of the teacher.
(iii) To compute the annual Income Tax as 5% of the annual salary
above Rs. 1,75,000/-.
Write a main method to create object of a class and call the above
member method.
Constructor programs
Non parameterized
Program 1
• Define a class Box with constructor . data members l,b,h with size
15.0 cm,10.0 cm and 6.5 cm respectively.
• Member method:
printDetails() to find the containing capacity of each box and print the
details . create two boxes.
Program 2
• Define a class Student
Attributes roll, name ,m1,m2 and grade
Member methods:
Student() – constructor to initialize given values to attributes 21, Annet,
97.2 ,78 and A
Display() – to display the details
Write a main method to create an object and implement the method
Program 3
Write a program using non parameterized constructor with default null
values.
• Classname –student
Attributes – roll, name , m1, m2 and grade(A/B/C)
• Member methods-
getData() to input values
display()- to display all the details
Write the main() also to create an object and implement the methods.
Parameterized constructor
Program 1
Write a program using a class with parameterized constructor
Class name :Student
Data members::
Roll,name, m1 and m2
Values 24,sahil, 100.0 , 98.5 and 25, shane,99.0,98.5
Member methods:: display() to display details along with average.
Create two objects by passing literals
Program 2
• Write a program using a class with parameterized constructor of default
null values
Class name- Student
Data members: roll,name,m1,m2
• Member methods::
• Student(): to receive and initialize default null values.
• getData()- to input values
• displayRe()- to display details along with average . Create two objects by
passing literals(A literal is a fixed value written directly in the code, such
as numbers, strings, or characters.)
Program 3
• Write a program using a class with parameterized constructor
• Class name : student
• Data members : roll,name,m1&m2
• Values: 1,Adithya,45.0,50.0
• Member methods:
• Student()- to receive and initialize with parameters
• Display()- to display details along with average . Create object by
passing literals.

You might also like