PERSONAL CODES
Q)employee.java
import java.util.*;
//Find the total salary of an employee given the details hra,da & basic
class Employee {
static String empname;
static int empcode;
static double BasicPay;
Employee(String s, int c, double b) {
empname = s;
empcode = c;
BasicPay = b;
}
static double salaryCal() {
double hra = 30 / 100.0 * BasicPay;
double da = 40 / 100.0 * BasicPay;
double salary = BasicPay + hra + da;
double sa = 0.0d; // special allowance variable
if (empcode <= 15 && salary <= 15000.0)
sa = 20.0 / 100.0 * salary;
if (sa >= 2500.0)
sa = 2500.0;
if (empcode > 15)
sa = 1000.0;
return salary + sa;
}
public static void main(String args[]) throws InputMismatchException
/*
* if static is used in void main then all functions and variables should be
* static otherwise, error will be thrown
*/
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name, employee code and basic pay");
String n = sc.nextLine();
int c = sc.nextInt();
double b = sc.nextDouble();
Employee em = new Employee(n, c, b);
System.out.println("The total salary is=" + em.salaryCal());
}
}
====================================================================
Q)evil.java
import java.util.*;
class evil {
String check_evil(int n) {
int x = 0;
String y = "";
while (n > 0) {
x = n % 2;
n = n / 2;
y = y.concat(String.valueOf(x));
}
return y;
}
public static void main(String args[]) throws InputMismatchException {
evil ev = new evil();
String f = "";
int c = 0;
Scanner sc = new Scanner(System.in);
try {
System.out.println("Enter an integer number");
int n = sc.nextInt();
if (n > 2 && n < 100) {
f = ev.check_evil(n);
System.out.println(ev.check_evil(n));
for (int j = 0; j < f.length(); j++) {
if (f.charAt(j) == '1')
c = c + 1;
}
if (c % 2 == 0)
System.out.println("Is evil no=" + n);
else
System.out.println("Not evil no=" + n);
}
} finally {
sc.close();
}
}
}
Comments
Post a Comment