Tuesday 27 September 2016

CORE JAVA LAB@HOME 1 ~ GNIITHELP




Answer:-


1.Open a command or terminal window if you are using Windows O.S.

a. Click on start button.

b. Click on run.

c. Type cmd in run dialog box and the OK button.

2.Execute the java -version command. This verifies that the JRE is installed and not JDK.


3.Execute the javac -version command. This verifies that the JDK is installed.


4.Start NetBeans IDE and verify the version no. of the JDK used by IDE.

a. The installation od NetBeans places a menu in your Start menu.


b. Within NetBeans, click the Help menu, and then click  About.

c. The About dialog box displays both the NetBeans and JDK version numbers that are being used.

d. Click the CLOSE button to close the about dialog box.







Answer:-

1. Obtain the required software:

a. if you require both JDK and NetBeans, the easiest method is to download "JDK 7 With NetBeans 7.0.1" co-bundle.

b. If you require the JDK , download the Java SE 7 JDK.

c. If you require just the NetBeans IDE,Download "NetBeans IDE 7.0.1 For Java SE"


2.Install the required software.

3.Verify the software installation.






Answer:-


1. Configure NetBeans to be aware of the Java 7 platform.

a.In the NetBeans IDE ,select Tools and the Java Platforms from the Main menu.

b.click the Add Platform button and specify the directory that contains your JDK 7 Installation.

c.In the platform Name step, Verify that the default locations of the platform sources zip file and API documentations are valid.

d.Click the Finish button to close the Add Java Platform dialog box.

e.Ensure that JDK 1.7 is selected in the platforms list and click close.


2. Configure NetBeans to start with Java  SE 7 JDK.

a. Open the directory containing the NetBeans congiguration files.

b.Use a Text Editor to edit the netbeans.cofiguration.

c.Modify the netbeans_jdkhome property to have a value of the JDK 7 installation location.


3.restart NetBeans and verify the JDK being used by NetBeans with the steps outlined in practice. 

Read More »

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.

Read More »

CORE JAVA LAB@HOME 3 ~ GNIITHELP

Answer-1

class PrimeNumbers

{

   public static void main (String[] args)

   {

       int i =0;

       int num =0;

       //Empty String

       String  primeNumbers = "";

       for (i = 1; i <= 100; i++)         

       {       

          int counter=0;    

          for(num =i; num>=1; num--)

  {

             if(i%num==0)

     {

  counter = counter + 1;

     }

  }

  if (counter ==2)

  {

     //Appended the Prime number to the String

     primeNumbers = primeNumbers + i + " ";

  }

       }

       System.out.println("Prime numbers from 1 to 100 are :");

       System.out.println(primeNumbers);

   }

}


Answer-2


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

   }

  }

 }

Answer-3

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

   }

 }

 } 

Answer-4


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

     }

  }

Read More »

CORE JAVA LAB@HOME 4 ~ GNIITHELP

Answer-1

Click Here

Answer-2

public class rectangle {


   double length;

   double breadth;


  public rectangle ( double len , double brd) {

     length = len;

     breadth = brd;


   public boolen equals (object obj) {

    rectangle rec  = (rectangle) obj;

   if (this. length == rec.length && this.breadth == rec.breadth) {

  

     return true;

     }

       else {

      return false;

    }

  }

      public static void main(String [] arg) {

       rectangle obj1 = new rectangle (10.5 , 23.6);

       rectangle obj2 = new rectangle (10.5 , 33.6);

    


4.Write a program that stores the details of students and employees. The student details include first name, last name, age, course enrolled, and student ID. The employee details include first name, last name, age, salary, department name, designation, and employee ID. You need to implement the preceding functionalities by ensuring the reusability of code.


Ans.


public class persondetails {


  String firstname;

  String lastname;

  int age;


   public void showdetails() {

   system.out.println("\nThe student details are: \n");

   system.out.println("first name: " + super.firstname);

   system.out.println("last name: " + super.lastname);

   system.out.println("age: " + super.age);

   system.out.println("course enrolled: + + stream);

   system.out.println("student id: " + studentid);


  }

}


   public class employeedetails extends persondetails {

  

    double salary;

    string desg;

    string dept;

  

    public void getdetail(string name1, int age, double sal, string des, string dep) {

     super . getdetail (name1,name2,age);

      salary = sal;

      desg = des;

      dept = dep;

      showdetail ();

  }


     public void showdetail () {

      system.out.println("\nthe employee details are : \n");

      system.out.println(" first name: " + super. firstname);

      system.out.println("age: " + super.age);

      system.out.println("{departmment: " + dept);

      system.out.println("designation: " + desg);

     system.out.println("salary: " + salary);

   }

 }

     public class main details {


      public static void main (string [] args) {

       studentdetails sobj = new studentdetails ();

       sobj.getdetail("peter", "parker", 23 , "science", 125);

       employeedetails eobj = new employeedetails ();

       eobj.getdetail("david", "henson",  34, 2000, "manager", "admin");

    }


5.Write a program that stores the details of the Software and Hardware books. The Software book includes the software version and software name. The Hardware book includes the hardware category and publisher. However, both the books include some common details, such as author name, title, price, and number of pages. Therefore, you need to store and display the book details by implementing the code reusability in the program.


Ansclass book {

   

   string author;

   string title;

   int price;

   int pages;

   int stock;


    public void getdetails(string at, string tt, int pr, int pg, int st) {

       author = at;

       title = tt;

       price = pr;

       pages = pg;

       stock = st;

   }

      public void showdetails () {

       system.out.println (" ");

       system.out.println ("books information");

       system.out.println ("============================");

       system.out.println (" book author: " + author);

       system.out.println (" book title: " + title);

       system.out.println (" book price: " + price);

       system.out.println (" number of pages: " + pages);

       system.out.println (" book of stock: " + stock);

  }

    

}

    class hardwarebook extends book {

  

     string hardwarecatagoery;

     string publisher;

     public void getdetails () {

       super . getdetails ("mark franklin" , "all about pc", 120, 150, 80);

           hardwarecategory = "machine";

           publisher = "denmark";

    }

         public void showdetails() {

           system.out.println (" ");

           system.showdetails ();

           system.out.println ("hardware category: " + hardwarecategory);

           system.out.println ("publisher name: " + publisher);

           system.out.println (" ");

      }

 }

          public class bookdemo {

     

          public static void main(string args []) {

   

          softwarebook softdetails = new softwarebook ();

          softdetails. getdetails ();

          softdetails . showdetails ();

     

          hardwarebook harddetails = new hardwarebook ();

          harddetails . getdetails ();

          harddetails . showdetails ();

   }


}


Answer-3

public class Employee {

  public int empID;

  Public String empName;

  Public String empDesg;

  Public String empDept;


 public Employee()  {


  empID = 2132;

  empName = "Ajay Shamra";

  empDesg = "Software Devloper";

  empDept = "IT";

 }


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

      }

 }

Answer-4

public class persondetails {


  String firstname;

  String lastname;

  int age;


   public void showdetails() {

   system.out.println("\nThe student details are: \n");

   system.out.println("first name: " + super.firstname);

   system.out.println("last name: " + super.lastname);

   system.out.println("age: " + super.age);

   system.out.println("course enrolled: + + stream);

   system.out.println("student id: " + studentid);


  }

}


   public class employeedetails extends persondetails {

  

    double salary;

    string desg;

    string dept;

  

    public void getdetail(string name1, int age, double sal, string des, string dep) {

     super . getdetail (name1,name2,age);

      salary = sal;

      desg = des;

      dept = dep;

      showdetail ();

  }


     public void showdetail () {

      system.out.println("\nthe employee details are : \n");

      system.out.println(" first name: " + super. firstname);

      system.out.println("age: " + super.age);

      system.out.println("{departmment: " + dept);

      system.out.println("designation: " + desg);

     system.out.println("salary: " + salary);

   }

 }

     public class main details {


      public static void main (string [] args) {

       studentdetails sobj = new studentdetails ();

       sobj.getdetail("peter", "parker", 23 , "science", 125);

       employeedetails eobj = new employeedetails ();

       eobj.getdetail("david", "henson",  34, 2000, "manager", "admin");

    }


Answer-5

class book {

   

   string author;

   string title;

   int price;

   int pages;

   int stock;


    public void getdetails(string at, string tt, int pr, int pg, int st) {

       author = at;

       title = tt;

       price = pr;

       pages = pg;

       stock = st;

   }

      public void showdetails () {

       system.out.println (" ");

       system.out.println ("books information");

       system.out.println ("============================");

       system.out.println (" book author: " + author);

       system.out.println (" book title: " + title);

       system.out.println (" book price: " + price);

       system.out.println (" number of pages: " + pages);

       system.out.println (" book of stock: " + stock);

  }

    

}

    class hardwarebook extends book {

  

     string hardwarecatagoery;

     string publisher;

     public void getdetails () {

       super . getdetails ("mark franklin" , "all about pc", 120, 150, 80);

           hardwarecategory = "machine";

           publisher = "denmark";

    }

         public void showdetails() {

           system.out.println (" ");

           system.showdetails ();

           system.out.println ("hardware category: " + hardwarecategory);

           system.out.println ("publisher name: " + publisher);

           system.out.println (" ");

      }

 }

          public class bookdemo {

     

          public static void main(string args []) {

   

          softwarebook softdetails = new softwarebook ();

          softdetails. getdetails ();

          softdetails . showdetails ();

     

          hardwarebook harddetails = new hardwarebook ();

          harddetails . getdetails ();

          harddetails . showdetails ();

   }


}

Answer-6

public class addition {

  

  public int add(int num1 , int num2) {

    return num1 + num2;

 }

    public double add (double num1, double num2 ) {

     return (double) num1 + num2;

}

    public int add(int num1 , int num2 , int num3) {

      return num1 + num2 + num3;

}

     public static void main (string[] args) {

        int a = 10, b = 15, c = 7;

        double x = 4.5, y = 3.2;

        addition obj = new addition ();

  

       system.out.println (" the addition of two integer numbers is " + obj.add(a , b) );

       system.out.println (" the addition of two fractional numbers is " + obj . add(x , y) ) ;

       system.out.println (" the addition of three integer numbers is " + obj . add (a,b,c) ) ;

 }

Read More »