-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advanced Level Assignment: Salary System in Java #9
Labels
question
Further information is requested
Comments
package ifelse;
import java.util.Scanner;
public class salary_system {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String name,id ,mounthselect;
int salary, Month, monthDay = 0, year,leaves,Conveyance,Medical,OtherA,Professionalt,PaidD;
float allowance,leavesAmount,Ysalary,CTC,conveyAmount,medicalAmount,otherAmount,mounthallowance,ProfessionalAmount,mounthnetSalary,TotalDeductions,netsalary;
mounthselect="";
System.out.print("Enter the name: ");
name=sc.next();
System.out.print("Enter the Employee id: ");
id=sc.next();
System.out.print("Enter the Current Year: ");
year =sc.nextInt() ;
System.out.print("Enter the Leaves Taken IN this Month: ");
leaves =sc.nextInt() ;
System.out.print("Enter the monthly Salary : ");
salary =sc.nextInt() ;
System.out.print("Enter the Conveyance Allowance in Percentage: ");
Conveyance =sc.nextInt() ;
System.out.print("Enter the Medical Allowance in Percentage: ");
Medical =sc.nextInt() ;
System.out.print("Enter the Other Allowances in Percentage: ");
OtherA =sc.nextInt() ;
System.out.print("Enter the Professional Tax in Percentage: ");
Professionalt =sc.nextInt() ;
System.out.print("Enter the Current Month: ");
Month =sc.nextInt();
switch (Month) {
case 1:
monthDay = 31;
mounthselect = "January";
break;
case 2:
if ((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0))) {
monthDay = 29;
} else monthDay = 28;
mounthselect = "February";
break;
case 3:
monthDay = 31;
mounthselect = "March";
break;
case 4:
monthDay = 30;
mounthselect = "April";
break;
case 5:
monthDay = 31;
mounthselect = "May";
break;
case 6:
monthDay = 30;
mounthselect = "June";
break;
case 7:
monthDay = 31;
mounthselect = "July";
break;
case 8:
monthDay = 31;
mounthselect = "August";
break;
case 9:
monthDay = 30;
mounthselect = "September";
break;
case 10:
monthDay = 31;
mounthselect = "October";
break;
case 11:
monthDay = 30;
mounthselect = "November";
break;
case 12:
monthDay = 31;
mounthselect = "December";
break;
default:
System.out.println("enter Between 1 to 12 ");
}
//calculation
PaidD=monthDay-leaves;
leavesAmount=(float)(salary/monthDay)*(leaves);
Ysalary=salary*12;
conveyAmount=(float) Ysalary*Conveyance/100;
otherAmount=(float) Ysalary*OtherA/100;
medicalAmount=(float) Ysalary*Medical/100;
allowance=conveyAmount+otherAmount+medicalAmount;
mounthallowance=allowance/12 ;
CTC=Ysalary+allowance;
mounthnetSalary=salary-leavesAmount;
ProfessionalAmount=(float) mounthnetSalary*Professionalt/100;
TotalDeductions=leavesAmount+ProfessionalAmount;
netsalary=mounthnetSalary+mounthallowance-TotalDeductions;
System.out.println();
System.out.println();
System.out.println("------Output---------");
System.out.println();
System.out.println();
System.out.println("Employee Name= " +name);
System.out.println("Employee Id ="+ id);
System.out.println("Paid Days = "+ PaidD);
System.out.println("Basic Salary= "+ salary);
System.out.println("Total Working Days = "+ monthDay);
System.out.println("Leaves Amount ="+ leavesAmount);
System.out.println("Conveyance Allowance ="+ conveyAmount);
System.out.println("Other Allowance ="+ otherAmount);
System.out.println("Medical Allowance ="+ medicalAmount);
System.out.println("CTC =" + CTC);
System.out.println("Total Allowance =" +allowance);
System.out.println("Professional Tax = " + ProfessionalAmount);
System.out.println("Total Deductions = "+ TotalDeductions);
System.out.println("Net Salary = " +netsalary);
System.out.println("Month = " +mounthselect+"/"+year);
}
} |
|
import java.util.Scanner;
class Employee{
String name,id,designation,department;
int basic_salary;
float house,dearness,provident;
void employee_detail(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter Your Name: ");
name=sc.nextLine();
System.out.println("Enter Your ID: ");
id=sc.nextLine();
System.out.println("Enter Your Designation: ");
designation=sc.nextLine();
System.out.println("Enter Your Department: ");
department=sc.nextLine();
System.out.println("Enter your Basic salary: ");
basic_salary=sc.nextInt();
System.out.println("Enter House Rent Allowance: ");
house=sc.nextFloat();
System.out.println("Enter Dearness Allowance: ");
dearness=sc.nextFloat();
System.out.println("Enter Provident Fund: ");
provident=sc.nextFloat();
}
void display(){
System.out.println("Employee Salary Details");
System.out.println("........................");
System.out.println("Name: "+name);
System.out.println("ID: "+id);
System.out.println("Designation: "+designation);
System.out.println("Department: "+department);
System.out.println();
System.out.println("Basic Salary: "+basic_salary);
}
float hra(){
float hra=(float)(basic_salary*house)/100;
return hra;
}
float da(){
float da=(float)(basic_salary*dearness)/100;
return da;
}
float ma(){
System.out.print("Medical allowance: ");
return 1500;
}
float pf(){
float pf=(float)(basic_salary*provident)/100;
return pf;
}
float gs(){
float gs=basic_salary+hra()+da()+ma();
return gs;
}
float ns(){
float ns= gs()-pf();
return ns;
}
}
public class Salary {
public static void main(String[] args) {
Employee ob=new Employee();
ob.employee_detail();
System.out.println();
ob.display();
System.out.println("House Rent Allowance: "+(ob.hra()));
System.out.println("Dearness Allowance: "+(ob.da()));
System.out.println(ob.ma());
System.out.println("Provident Fund: "+(ob.pf()));
System.out.println();
System.out.println("Gross Salary: "+(ob.gs()));
System.out.println("Net Salary: "+(ob.ns()));
}
} |
package loop_nested;
import java.util.Scanner;
class salary_system {
int salary,gs,ns;
float HRA,DA,PF,MA=1500;
String name,id,designation,department;
void input(){
Scanner scanner=new Scanner(System.in);
System.out.print("Enter the name: ");
name=scanner.next();
System.out.print("Id: ");
id=scanner.next();
System.out.print("Designation: ");
designation=scanner.next();
System.out.print("Enter the Department: ");
department=scanner.next();
System.out.print("Enter the Salary: ");
salary=scanner.nextInt();
}
float HRA(){
HRA=salary*20/100;
return HRA;
}
float DA(){
DA=salary*10/100;
return DA;
}
float PF(){
PF=salary*12/100;
return PF;
}
int gs(){
gs= (int) (salary+HRA+DA+PF+MA);
return gs;
}
int ns(){
ns=(int)(gs()-PF());
return ns;
}
void Output(){
System.out.println("Employee Salary Details");
System.out.println("-----------------------");
System.out.println("Name: "+name);
System.out.println("ID: "+id);
System.out.println("Designation: "+designation);
System.out.println("Department: "+department);
System.out.println();
System.out.println("Basic Salary: "+salary);
System.out.println("House Rent Allowance (HRA): "+ HRA());
System.out.println("Dearness Allowance (DA): "+DA());
System.out.println("Medical Allowance:"+MA);
System.out.println("Provident Fund (PF): "+PF());
System.out.println();
System.out.println("Gross Salary: "+gs());
System.out.println("Net Salary: "+ns());
}
public static void main(String[] args) {
salary_system ss=new salary_system();
ss.input();
ss.Output();
}
}
|
package Assignment;
import java.util.Scanner;
public class Advance_salary_system {
static String name , id,designation,department;
static int basic_salary , GS,NS;
float hra,da,pf,HRA1,DA,PF,MA;
public static void main(String[] args) {
Advance_salary_system ob = new Advance_salary_system();
ob.input();
ob.output();
}
void input()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter your name:");
name = sc.next();
System.out.print("Enter your ID:");
id = sc.next();
System.out.print("Enter your Basic Salary:");
basic_salary = sc.nextInt();
System.out.print("Enter your Designation:");
designation = sc.next();
System.out.print("Enter your Department:");
department = sc.next();
System.out.print("Enter house rent allowance:");
hra = sc.nextFloat();
System.out.print("Enter dearness allowance:");
da = sc.nextFloat();
System.out.print("Enter provident fund:");
pf = sc.nextFloat();
}
void output()
{
System.out.println("Employee Salary Details");
System.out.println("________________________");
System.out.println("Name: "+name);
System.out.println("ID: "+id);
System.out.println("Designation: "+designation);
System.out.println("Department: "+department);
System.out.println();
System.out.println("Basic Salary: "+basic_salary );
System.out.println("House Rent Allowance "+HRA1() );
System.out.println("Dearness Allowance: "+DA() );
System.out.println("Medical Allowance: "+MA());
System.out.println("Provident Fund: "+PF() );
System.out.println();
System.out.println("Gross Salary: "+GS() );
System.out.println("Net Salary: "+NS() );
}
float HRA1()
{
float HRA1=basic_salary*hra/100;
return HRA1;
}
float DA()
{
float DA=basic_salary*da/100;
return DA;
}
float PF()
{
float PF=basic_salary*pf/100;
return PF;
}
int MA()
{
return 1500;
}
int GS()
{
GS=(int)(basic_salary+HRA1()+DA()+MA()+PF());
return GS;
}
int NS()
{
NS=(int)(GS()-PF());
return NS;
}
} |
package June_22;
import java.util.Scanner;
public class Employee {
String name, id, designation, department;
int salary, med = 1500;
float hra, da, pf, gs, ns;
Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Employee emp = new Employee();
emp.data();
emp.HouseRent();
emp.DA();
emp.PF();
emp.Medical();
emp.grossSalary();
emp.netSalary();
System.out.println();
System.out.println("|----------------------|");
System.out.println("|Employee Salary Detail|");
System.out.println("|----------------------|");
System.out.println();
emp.op();
}
void data() {
while (true) {
System.out.print("Enter Your Name:");
name = sc.nextLine();
if (!name.isEmpty()) {
break;
}
else {
System.out.println("Name cannot be empty");
}
}
System.out.print("Enter Your ID:");
id = sc.next();
System.out.print("Enter your Basic Salary:");
salary = sc.nextInt();
while(salary<0){
System.out.println("Salary must be in positive number");
System.out.print("Enter your Basic Salary:");
salary = sc.nextInt();
}
System.out.print("Enter Your Designation:");
designation = sc.next();
System.out.print("Enter Your Department:");
department = sc.next();
}
float HouseRent(){
hra=(salary*20/100);
return hra;
}
float DA(){
da=(salary*10/100);
return da;
}
float PF(){
pf=(salary*12/100);
return pf;
}
int Medical(){
return med;
}
float grossSalary(){
gs=salary+hra+da+med;
return gs;
}
float netSalary(){
ns=gs-pf;
return ns;
}
void op(){
System.out.println("Name:"+name);
System.out.println("Id:"+id);
System.out.println("Designation:"+designation);
System.out.println("Department:"+department);
System.out.println("Basic Salary:"+salary);
System.out.println("House Rent Allowance (HRA):"+hra);
System.out.println("Dearness Allowance (DA):"+da);
System.out.println("Provident Fund (PF):"+pf);
System.out.println("Medical Allowance:"+med);
System.out.println("Gross Salary:"+gs);
System.out.println("Net Salary:"+ns);
}
} |
import java.util.Scanner;
class Employee {
Scanner sc = new Scanner(System.in);
String name, designation, department;
int id;
int salary;
int hra, dearness, pf, medical;
public void detail() {
System.out.println("enter the name of employee: ");
name = sc.next();
System.out.println("enter the id of employee: ");
id = sc.nextInt();
System.out.println("enter the basic salary of employee: ");
salary = sc.nextInt();
System.out.println("enter the designation of employee: ");
designation = sc.next();
System.out.println("enter the department of employee: ");
department = sc.next();
}
public void salary_compo() {
System.out.println("enter the hra allowance%: ");
hra = sc.nextInt();
System.out.println("enter the dearness allowance %: ");
dearness = sc.nextInt();
System.out.println("enter the provident fund :%: ");
pf = sc.nextInt();
System.out.println("medical allowance amount: ");
medical = sc.nextInt();
System.out.println();
System.out.println();
}
public void display() {
System.out.println("......Employee Salary Details......");
System.out.println("............................................");
System.out.println("Employee Name : " + name);
System.out.println("Employee ID :" + id);
System.out.println("Employee Designation :" + designation);
System.out.println("Employee Department :" + department);
}
int salary_calc1() {
int dearness_amount = (salary * dearness / 100);
return dearness_amount;
}
int salary_calc2() {
int pf_amount = (salary * pf / 100);
return pf_amount;
}
int salary_calculate() {
int hra_amount = (salary * hra / 100);
return hra_amount;
}
public void display1() {
System.out.println();
System.out.println();
System.out.println("Basic Salary :" + salary);
System.out.println("Medical Amount ;" + medical);
}
int gross_salary() {
int gross_salar = salary + salary_calculate() + salary_calc1() + medical;
return gross_salar;
}
int net_salary(){
int net_salar=gross_salary()- salary_calc2();
return net_salar;
}
}
public class Salary_System {
public static void main(String[] args) {
Employee emp = new Employee();
System.out.println("..............Employee Details.....................");
emp.detail();
emp.salary_compo();
emp.display();
System.out.println();
System.out.println();
System.out.println("Employee Basic Salary :" + emp.salary);
System.out.println("House Rent Allowance(HRA) :"+emp.salary_calculate());
System.out.println("Dearness Allowance(DA) :" + emp.salary_calc1());
System.out.println("Provident Fund(PF) :" +emp.salary_calc2());
System.out.println();
System.out.println();
System.out.println("gross_salary: "+emp.gross_salary());
System.out.println("Net salary : "+emp.net_salary());
}
} |
import java.util.Scanner;
public class salary_system {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String name,id,monthselect;
int CTC;
int salary,month,monthDay=0,year,leaves,Conveyance,Medical,OtherA,ProfessionalAmount,monthnetsalary,TotalDeductions,netsalary,PaidD;
monthselect="";
System.out.println("Enter the name:");
name=sc.next();
System.out.println("Enter the employee id:");
id=sc.next();
System.out.println("Enter the Current Year:");
year =sc.nextInt() ;
System.out.print("Enter the Leaves Taken IN this Month: ");
leaves =sc.nextInt() ;
System.out.print("Enter the monthly Salary : ");
salary =sc.nextInt() ;
System.out.print("Enter the Conveyance Allowance in Percentage: ");
Conveyance =sc.nextInt() ;
System.out.print("Enter the Medical Allowance in Percentage: ");
Medical =sc.nextInt() ;
System.out.print("Enter the Other Allowances in Percentage: ");
OtherA =sc.nextInt() ;
System.out.print("Enter the Professional Tax in Percentage: ");
ProfessionalAmount =sc.nextInt() ;
System.out.print("Enter the Current Month: ");
month =sc.nextInt();
switch (month) {
case 1:
monthDay = 31;
monthselect = "January";
break;
case 2:
if ((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0))) {
monthDay = 29;
} else monthDay = 28;
monthselect = "February";
break;
case 3:
monthDay = 31;
monthselect = "March";
break;
case 4:
monthDay = 30;
monthselect = "April";
break;
case 5:
monthDay = 31;
monthselect = "May";
break;
case 6:
monthDay = 30;
monthselect = "June";
break;
case 7:
monthDay = 31;
monthselect = "July";
break;
case 8:
monthDay = 31;
monthselect = "August";
break;
case 9:
monthDay = 30;
monthselect = "September";
break;
case 10:
monthDay = 31;
monthselect = "October";
break;
case 11:
monthDay = 30;
monthselect = "November";
break;
case 12:
monthDay = 31;
monthselect = "December";
break;
default:
System.out.println("enter Between 1 to 12 ");
}
//calculation
PaidD=monthDay-leaves;
leaves=(int) ((float)(salary/monthDay)*(leaves));
salary=salary*12;
Conveyance=(int) ((float) salary*Conveyance/100);
OtherA=(int) ((float) salary*OtherA/100);
Medical=(int) ((float) salary*Medical/100);
TotalDeductions=Conveyance+OtherA+Medical;
monthnetsalary=TotalDeductions/12 ;
CTC=salary+TotalDeductions;
monthnetsalary=salary-leaves;
ProfessionalAmount=(int) ((float) monthnetsalary*ProfessionalAmount/100);
TotalDeductions=leaves+ProfessionalAmount;
netsalary=monthnetsalary+monthnetsalary-TotalDeductions;
System.out.println();
System.out.println();
System.out.println("------Output---------");
System.out.println();
System.out.println();
System.out.println("Employee Name= " +name);
System.out.println("Employee Id ="+ id);
System.out.println("Paid Days = "+ PaidD);
System.out.println("Basic Salary= "+ salary);
System.out.println("Total Working Days = "+ monthDay);
System.out.println("Leaves Amount ="+ leaves);
System.out.println("Conveyance Allowance ="+ Conveyance);
System.out.println("Other Allowance ="+ OtherA);
System.out.println("Medical Allowance ="+ Medical);
System.out.println("CTC =" + CTC);
System.out.println("Total Allowance =" +TotalDeductions);
System.out.println("Professional Tax = " + ProfessionalAmount);
System.out.println("Total Deductions = "+ TotalDeductions);
System.out.println("Net Salary = " +netsalary);
System.out.println("Month = " +monthselect+"/"+year);
}
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assignment Questions
Class Design:
Employee
class to store the employee's details:Salary Components:
Input Handling:
Output Handling:
Validation:
Formatting:
Main Method:
Employee
object, take input, perform calculations, and display the salary details.Example Input
Example Output
Assignment Submission
Submit the Java source code file along with a document explaining the implementation, including how the input validation was handled and how the salary components were calculated.
The text was updated successfully, but these errors were encountered: