Tuesday 27 September 2016

CORE JAVA LAB@HOME 2 ~ GNIITHELP

Answer-1


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

Answer-2

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


Answer-3

class Grocery{

private int weight;

String productName;

double price;


public Grocery()

{

weight=4;

productName="Sugar";

price=6;

}

public void weightAdd()

{

weight +=3;

}

public void weightRemove()

{

weight -=3;

}

public void checkWeight()

{

System.out.println(+weight);

}

public static void main(String args[])

{

Grocery g=newGrocery();

System.out.println("The Current weight is");

g.checkWeight();


System.out.println("The wight after addition is");

g.weightAdd();

g.checkWeight();

System.out.println("The wight after substraction is");

g.weight Remove();

g.checkWeight();

}

}

Answer-4

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

  }


}

Answer-5

public class VowelChecker

{

public static void main(String args[])

{

String input;

switch(input)

{

case"a":

case"A":

}

}

}

Answer-6


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.

No comments:

Post a Comment