Computer Science, asked by surdiya83, 8 months ago

6. Write a class program in Java with the following specifications:
Class name: Pay
Data members : String name, address, city
float salary
Member functions:
pay(string n string add,string cy, float s ): parameterized constructor to initialize
the data members
void outputdata(): to display initialized values.
void calculate() : to find and print the following
da = 15% of salary
hra = 10% of salary
pf = 12% of salary
gross = salary + da + hra
net = gross - pf
void display(): to display the complete information
T
with the following
if​

Answers

Answered by Rajdeep11111
8

HELLO THERE!

Here's the code:

import java.util.*;

class Pay

{

String name, address, city;

float salary;

Pay(String n, String add, String cy, float s)

{

name = n;

address = add;

city = cy;

salary = s;

}

void outputdata()

{

System.out.println("Name: " + name);

System.out.println("Address: " + address);

System.out.println("City: " + city);

System.out.println("Salary = Rs. " + salary);

}

void calculate()

{

float da, hra, pf, gross, net;

da = 0.15 * salary;

hra = 0.1 * salary;

pf = 0.12 * salary;

gross = salary + da + hra;

net = gross - pf;

System.out.println("DA = Rs. " + da + "\nHRA = Rs. " + hra + "\nPF = Rs. " + pf + "\nGross salary = Rs. " + gross + "\nNet salary = Rs. " + net);

}

void display()

{

System.out.println("Complete details: ");

outputdata();

}

public static void main (String args[])

{

Scanner sc = new Scanner (System.in);

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

String name1 = sc.nextLine();

System.out.print("Enter the address: ");

String add1 = sc.nextLine();

System.out.print("Enter the city: ");

String city1 = sc.next();

System.out.print("Enter the salary: ");

float sal = sc.nextFloat();

Pay obj = new Pay(name1, add1, city1, sal);

obj.calculate();

obj.display();

}

}

Thanks!

Answered by Anonymous
5

Question:

Write a class program in Java with the following specifications:

Class name: Pay

Data members : String name, address, city

float salary

Member functions:

pay(string n string add,string cy, float s ): parameterized constructor to initialize  the data members

void outputdata(): to display initialized values.

void calculate() : to find and print the following

da = 15% of salary

hra = 10% of salary

pf = 12% of salary

gross = salary + da + hra

net = gross - pf

void display(): to display the complete information

T

with the following

if​

 

Answer:

import java.util.*;

public class Pay

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

String "name", "address", "city";

float da, hra,pf, gross,  net, salary, pay;

System.out.println("Enter the name of the person"+name);

name=in.nextString();

System.out.println("Enter the address of the person"+address);

address= in.nextString();

System.out.println("Enter the name of the city"+city);

city= in.nextString();

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

Salary= in.nextFloat();

da=(salary*15/100);

hra=(salary*10/100);

pf=(salary*12/100);

gross=(salary+da+hra);

net=gross-pf;

pay = (salary+da+hra+pf+gross+net);

System.out.println("The pay is="+pay);

}

}

For more java programmings follow the given links as I have solved earlier:

brainly.in/question/14335606

brainly.in/question/14323927

brainly.in/question/14370842

brainly.in/question/14395545

brainly.in/question/14809512

brainly.in/question/14809885

brainly.in/question/14840551

brainly.in/question/15125968

https://brainly.in/question/15584326

Similar questions