Sunday, 13 December 2015

Java Lab@home 2

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


 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();
      }
 }




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

Choose 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


 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();
     }
  }


3.Write a program to create a class that stores the grocery details. In addition, define three methods that will add the weight, remove the weight, and display the current weight, respectively..




4.Write a program to create a class that declares a member variable and a member method. The member method will display the value of the member variable.

Ans.Q 4. 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.

Ans
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();
  }

}


5.Write a program to identify whether the given character is a vowel or a consonant.

Ans.

6.Write a program to display the following numeric pattern:
12345
1234
 123
 12
 1
Ans




.7.Using the NetBeans IDE, create an Employee class, create a class with a main method to test the Employee class, compile and run your application, and print the results to the command line output.

Ans.
1. start the NetBeans IDE by using the icon from desktop.
2. create a new project employeepractice in the D:\labs\02-review\practices directory with an employeetest main class in the com.example package.
3. Set the source/binary format to JDK 7.
a. right-click the project and select properties.
b. select JDK 7 from the drop-down list for SOurc/binary format.
c. click ok.
4. create another package called com.example.domain.
5. Add a java class called Employee in the com.example.domain package.
6. code the employee class.
a. add the following data fields to the employee class-use your judgment as to what you want to call these fields in the class. Refer to the lesson material for ideas on the fields names and the syntax if you are not sure. Use public as the access modifier.
7. create a no-arg constructor for the employee class.
Netbeans can format your code at any time for you. Right-click in the class and select format, or press the Alt-Shift-F key combination.
8. Add accessor/mutator methods for each of the fields.
9. write code in the employeetest class to test your employee class.
a. construct an instance of employee.
b. use the setter mothods to assign the following values to the instance:
c. in the body of the main methoed, use the system.out.printIn method to write the values of the employee fields to the console output.
d. rsolve any missing import statements.
e. save the employeetest class.
10. run the EmployeePractice project.
11. Add some additional employee instances to your test class.

31 comments: