import java.util.Scanner;
// MyStack interface defines the stack operations
interface MyStack {
void push();
void pop();
void display();
}
// Stack class implements the MyStack interface
class Stack implements MyStack {
private int[] stackArray;
private int top;
private int size;
public Stack(int size) {
this.size = size;
stackArray = new int[size];
top = -1;
}
public void push() {
try {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Element: ");
int element = sc.nextInt();
if (top == size - 1) {
System.out.println("Stack Overflow");
} else {
stackArray[++top] = element;
}
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
public void pop() {
if (top == -1) {
System.out.println("Stack Underflow");
} else {
System.out.println("The element popped is " + stackArray[top--]);
}
}
public void display() {
if (top == -1) {
System.out.println("Stack is empty");
} else {
System.out.println("Implementation of Stack");
for (int i = top; i >= 0; i--) {
System.out.println(stackArray[i]);
}
}
}
}
// Main class that contains the program entry point
public class StackADT {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of stack: ");
int size = sc.nextInt();
Stack stack = new Stack(size);
while (true) {
System.out.print("\nEnter the option: 1. Push 2. Pop 3. Display 4. Exit: ");
int option = sc.nextInt();
switch (option) {
case 1:
stack.push();
break;
case 2:
stack.pop();
break;
case 3:
stack.display();
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid option");
}
}
}
}
import java.util.Scanner;
// MyStack interface defines the stack operations
interface MyStack {
void push();
void pop();
void display();
}
// Stack class implements the MyStack interface
class Stack implements MyStack {
private int[] stackArray;
private int top;
private int size;
public Stack(int size) {
this.size = size;
stackArray = new int[size];
top = -1;
}
public void push() {
try {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Element: ");
int element = sc.nextInt();
if (top == size - 1) {
System.out.println("Stack Overflow");
} else {
stackArray[++top] = element;
}
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
public void pop() {
if (top == -1) {
System.out.println("Stack Underflow");
} else {
System.out.println("The element popped is " + stackArray[top--]);
}
}
public void display() {
if (top == -1) {
System.out.println("Stack is empty");
} else {
System.out.println("Implementation of Stack");
for (int i = top; i >= 0; i--) {
System.out.println(stackArray[i]);
}
}
}
}
// Main class that contains the program entry point
public class StackADT {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of stack: ");
int size = sc.nextInt();
Stack stack = new Stack(size);
while (true) {
System.out.print("\nEnter the option: 1. Push 2. Pop 3. Display 4. Exit: ");
int option = sc.nextInt();
switch (option) {
case 1:
stack.push();
break;
case 2:
stack.pop();
break;
case 3:
stack.display();
break;
case 4:
System.exit(0);
default:
System.out.println("Invalid option");
}
}
}
}
import java.util.Scanner;
// Base class (Parent)
class Employee {
protected String Emp_name;
protected String Emp_id;
protected String Mail_id;
protected String Mobile_no;
protected String Designation;
public void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Employee Name: ");
Emp_name = sc.nextLine();
System.out.print("Enter the Employee Id: ");
Emp_id = sc.nextLine();
System.out.print("Enter the Mail_id: ");
Mail_id = sc.nextLine();
System.out.print("Enter the Mobile no.: ");
Mobile_no = sc.nextLine();
System.out.print("Enter the Designation (Programmer/AsstProf/AssocProf/Professor): ");
Designation = sc.nextLine();
}
}
// Child class 1
class Programmer extends Employee {
private double BP, DA, HRA, PF, Club_fund, Gross_Salary, Net_Salary;
public void inputBP() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Basic Pay: ");
BP = sc.nextDouble();
}
public void calculate() {
DA = BP * 0.97;
HRA = BP * 0.10;
PF = BP * 0.12;
Club_fund = BP * 0.01;
Gross_Salary = BP + DA + HRA;
Net_Salary = Gross_Salary - (PF + Club_fund);
}
public void display() {
System.out.println("\nEmployee Name: " + Emp_name);
System.out.println("Employee Id: " + Emp_id);
System.out.printf("The DA is: %,.2f\n", DA);
System.out.printf("The HRA is: %,.2f\n", HRA);
System.out.printf("The PF is: %,.2f\n", PF);
System.out.printf("The Club Fund is: %,.2f\n", Club_fund);
System.out.printf("The Gross Salary is: %,.2f\n", Gross_Salary);
System.out.printf("The Net Salary is: %,.2f\n", Net_Salary);
}
}
// Child class 2
class AssistantProfessor extends Employee {
private double BP, DA, HRA, PF, Club_fund, Gross_Salary, Net_Salary;
public void inputBP() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Basic Pay: ");
BP = sc.nextDouble();
}
public void calculate() {
DA = BP * 0.97;
HRA = BP * 0.10;
PF = BP * 0.12;
Club_fund = BP * 0.01;
Gross_Salary = BP + DA + HRA;
Net_Salary = Gross_Salary - (PF + Club_fund);
}
public void display() {
System.out.println("\nEmployee Name: " + Emp_name);
System.out.println("Employee Id: " + Emp_id);
System.out.printf("The DA is: %,.2f\n", DA);
System.out.printf("The HRA is: %,.2f\n", HRA);
System.out.printf("The PF is: %,.2f\n", PF);
System.out.printf("The Club Fund is: %,.2f\n", Club_fund);
System.out.printf("The Gross Salary is: %,.2f\n", Gross_Salary);
System.out.printf("The Net Salary is: %,.2f\n", Net_Salary);
}
}
// Child class 3
class AssociateProfessor extends Employee {
private double BP, DA, HRA, PF, Club_fund, Gross_Salary, Net_Salary;
public void inputBP() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Basic Pay: ");
BP = sc.nextDouble();
}
public void calculate() {
DA = BP * 0.97;
HRA = BP * 0.10;
PF = BP * 0.12;
Club_fund = BP * 0.01;
Gross_Salary = BP + DA + HRA;
Net_Salary = Gross_Salary - (PF + Club_fund);
}
public void display() {
System.out.println("\nEmployee Name: " + Emp_name);
System.out.println("Employee Id: " + Emp_id);
System.out.printf("The DA is: %,.2f\n", DA);
System.out.printf("The HRA is: %,.2f\n", HRA);
System.out.printf("The PF is: %,.2f\n", PF);
System.out.printf("The Club Fund is: %,.2f\n", Club_fund);
System.out.printf("The Gross Salary is: %,.2f\n", Gross_Salary);
System.out.printf("The Net Salary is: %,.2f\n", Net_Salary);
}
}
// Child class 4
class Professor extends Employee {
private double BP, DA, HRA, PF, Club_fund, Gross_Salary, Net_Salary;
public void inputBP() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Basic Pay: ");
BP = sc.nextDouble();
}
public void calculate() {
DA = BP * 0.97;
HRA = BP * 0.10;
PF = BP * 0.12;
Club_fund = BP * 0.01;
Gross_Salary = BP + DA + HRA;
Net_Salary = Gross_Salary - (PF + Club_fund);
}
public void display() {
System.out.println("\nEmployee Name: " + Emp_name);
System.out.println("Employee Id: " + Emp_id);
System.out.printf("The DA is: %,.2f\n", DA);
System.out.printf("The HRA is: %,.2f\n", HRA);
System.out.printf("The PF is: %,.2f\n", PF);
System.out.printf("The Club Fund is: %,.2f\n", Club_fund);
System.out.printf("The Gross Salary is: %,.2f\n", Gross_Salary);
System.out.printf("The Net Salary is: %,.2f\n", Net_Salary);
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Choose Employee Type:");
System.out.println("1. Programmer");
System.out.println("2. Assistant Professor");
System.out.println("3. Associate Professor");
System.out.println("4. Professor");
System.out.print("Enter choice (1-4): ");
int choice = sc.nextInt();
switch (choice) {
case 1:
Programmer p = new Programmer();
p.input();
p.inputBP();
p.calculate();
p.display();
break;
case 2:
AssistantProfessor ap = new AssistantProfessor();
ap.input();
ap.inputBP();
ap.calculate();
ap.display();
break;
case 3:
AssociateProfessor aap = new AssociateProfessor();
aap.input();
aap.inputBP();
aap.calculate();
aap.display();
break;
case 4:
Professor prof = new Professor();
prof.input();
prof.inputBP();
prof.calculate();
prof.display();
break;
default:
System.out.println("Invalid choice!");
}
}
}
// Converter.java
package converter;
public interface Converter {
public void input();
public void convert();
public void display();
}
// Currency.java
package converter;
import java.util.Scanner;
public class Currency implements Converter {
private double inr;
private double yen;
private double usd;
private double euro;
@Override
public void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the Indian rupee: ");
inr = sc.nextDouble();
}
@Override
public void convert() {
yen = inr * 1.628; // 1 INR = 1.628 Yen (approx)
usd = inr * 0.015; // 1 INR = 0.015 USD (approx)
euro = inr * 0.013; // 1 INR = 0.013 Euro (approx)
}
@Override
public void display() {
System.out.printf("Japanese Yen: %.2f\n", yen);
System.out.printf("US Dollar: $%.2f\n", usd);
System.out.printf("Euro: %.2f\n", euro);
}
public static void main(String[] args) {
Currency converter = new Currency();
converter.input();
converter.convert();
converter.display();
}
}