Likes

Java Lab04_Ans2

Write a program to store the employee details, such as employee ID, name,designation.
In addition, the employee details should be display when the object of the class is printed.


Answer


public class Employee {
public int empID;
Public String empName;
Public String empDesg;
Public String empDept;

public Employee()  {

empID = 2132;
empName = "Kamal Sharma";
empDesg = "Manager";
empDept = "Admin";
}

public String toString() {
StringBuffer = new StringBuffer();
buffer.append("The Employee Details are: \n");
buffer.append("The Employee ID: "+ empID+ "\n");
buffer.append("The Employee Name: "+ empName+"\n");
buffer.append("The Employee Designation: "+ empDesg+"\n");
buffer.append("The Employee Department: "+ empDept+"\n");
return buffer.toString();
    }
public static void main(String[] args) {
Employee oobj = new Employee();
System.out.println(eobj);
    }
}

Java Lab02_Ans4

Write a program that will store the employee records, such as employee ID, employee name, department, designation,
date of joining, date of birth, and marital status, in an array. In addition, the stored record needs to be displayed.

ANSWER


public class employeerecord

  string employeeDetails [] [] = new String [1] [7];
    public void storeData() {
 
   employeeDeatils [0] [0] = "A101";
   employeeDeatils [0] [1] = "john mathew";
   employeeDetails [0] [2] = "admin";
   employeeDetails [0] [3] = "manager";
   employeeDetails [0] [4] = "05/04/1998";
   employeeDetails [0] [5] = "11/09/1997";
   employeeDetails [0] [6] = "married";
 }
    public void displayData() {
     system.out.println ("Employee Details:");
    for ( int i = 0; i < employeeDetails,length;
    for ( int j = 0; j < employeeDetails[i].length; j++ {

      system.out.println(employeeDetails[i] [j] );
    }
 }


}

     public static void main (String [] args) {
      EmployeeRecord obj = new EmployeeRecord();
      obj.storeData();
     obj.displayData();
  }

}

JAVA Lab03_Ans3

Write a Program to print the table of five.


Answer


public class table {

  public static void main(String [] args)
  int result;
 
   for (int i = 1; i <=10; i++) {
    result = i * 5;
 
  system.out.println("5 * " + i " = " + result);
 
   }
 }

 } 

JAVA Lab03_Ans2

Write a program to check if the first number is divisible by the second number or not.
In addition, display approprate message accordingtothe result...


ANSWER

public class DivisibleChecker {

public static void main(string [] args) {

int num1, num2;
num1 = 32;

num2 = 12;

if (num1 % num2 == 0) {
    System.out.println("The first number is divisible by the second number");
} else {
System.out.println("The first number is not divisible by the second number");
}
}
}

NIIT HTML Lab@ Home

Java Lab02_Ans2

Write a program to creat a class named EmployeeDetails and display a menue similar to the following menu:
--------------Menu--------
1. Enter Data 
2. Display Data 
3. Exit

Chosse the option
Thereafter, invoke the respective method according to the given menu input. The methods will contain appropriate message, such as the displayData() 
method will contain the message, displayData method is invoked.



ANSWER

1. Create a Java application, Lab02_Ans2.
2. Create a class, EmployeeDetails, in the Java application, Lab02_Ans2.
3. Replace the exisiting code in the EmployeeDetails.java file with following code:

   public class EmployeeDetails {

     public void showMenue ()  {
         int option;
         System.out.println("------------Menu--------");
         System.out.println("1. Enter Data");
         System.out.println("2. Display Data");
         System.out.println("3. Exit");
         System.out.println("\nChoose the option:  ");


         Option = 2;
switch (option)  {
case 1:
enterData();
break;
case2:
DisplayData();
break;
case3:
exitMenue();
break;
defalt:
System.out.println("Incorrect menu option");
showMenu();
break;
 }
}
public void enterData() {
System.out.println("enterData method is invoked");
}

public void enterData() {
System.out.println("displayData method is invoked");
}


public void enterData() {
System.out.println("exitMenu method is invoked");
System.exit(0);
}

public static void main(String[] args)  {
EmployeeDetails obj = new EmployeeDetails();
obj.showMenu();
  }
}

Java Lab02 Ans1

Wrire a Proram to creat a class that stores the train reservation details. In addition, define a method that will display the stored details..

ANSWER

1. Create a Java application, Lab02_Ans1.
2. Create a class, Reservation, in the Java application, Lab02_Ans1.
3. Replace the exisiting code in the Reservation.java file with following code:

   public class Reservation {

int ticketID;
String name;
String source;
String destination;

Reservation()   {
ticketID = 80;
name ="Harry";
source = "Chicago"
destination = "Dallas";
}


public void showTicket ()  {
         System.out.println("The Ticket ID is "+ ticketID);
         System.out.println("The Passenger Name is "+ name);
         System.out.println("The Sourse is" + sourse);
         System.out.println("The Destination is" + Destination);
         System.out.println("\nChoose the option:  ");


public static void main(String[] args)  {
Reservation g = new Reservation();
g.showTicket();
    }
}