Define a class Employee to accept emp_id, emp _name, basic_salary from the user and display the gross_salary.

Write a program to define a class Employee to accept emp_id, emp _name, basic_salary from the user and display the gross_salary. import java.lang.*; import java.io.*; class Employee { int emp_id; String emp_name; float basic_salary; Employee(int id, String name, float sal) { emp_id=id; emp_name=name; basic_salary=sal; } void display() { float da=basic_salary*15/100; float hra=basic_salary*10/100; float gross_sal=basic_salary+da+hra; System.out.println […]

Java Class Fraction Operations / Numerator and Denominator / Initialize Objects using Constructors

Write a program to define a class Fraction having data members numerator and denominator. Initialize three objects using different constructors and display its fractional value. import java.lang.*; import java.io.*; class Fraction { double numerator,denominator,fraction; Fraction (int a, double b) { numerator=a; denominator=b; fraction=numerator/denominator; System.out.println (“Fraction1 = “+fraction); } Fraction (int x, int y) { numerator=x; […]

Student Class / Data Members / Initialize / Display Data Values and Calculate Students Marks

Write a program to define a class student with four data members such as name, roll no., sub1, and sub2. Define appropriate methods to initialize and display the values of data members. Also, calculate total Marks and percentage scored by the student. import java.lang.*; import java.io.*; class student { String name; int roll_no; int sub1,sub2; […]

JAVA class with a 3 digit number data member and it’s initialize to display reverse

Write a program to define a class having one 3-digit number, a ‘num’ as a data member. Initialize and display reverse of that number. import java.lang.*; class q1Reverse { int num,r=0,s=0; q1Reverse(int n) { num = n; } void Reverse() { while(num>0) { r=num%10; s=(s*10)+r; num=num/10; } System.out.println(“Reverse of number =”+s); } public static void main(String […]