Wednesday 18 November 2015

Java Lab@4

1.Override the toString method of the Object class in the Employeeclass and in the Manager class. You will create an EmployeeStockPlan class with agrantStock method that uses the instanceof operator to determine how much stock togrant based on the employee type.

Ans https://drive.google.com/open?id=0B-yL1mP3zqTbbUpZWUtRMmFOYXc


2.Write a program to create a class that will store the length and breadth of the rectangle. In addition, you need to check whether two objects of the class contain the same values or not.


Ans.

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

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

Ans.

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

}

6.Modify the Manager class to add an array of Employee objects (a staff) tothe manager class, and create methods to add and remove employees from the Manager.Finally, add a method to Manager to print the staff names and IDs.


7.• • • Write a program to demonstrate the polymorphism concept by overloading the add method that allows addition of the following numbers: 
Two integer numbers
 Two fractional numbers 
Three integer numbers

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

18 comments:

  1. Above all else I might want to state administrator thank you since you are imparting a decent blog to us and a decent site. I Have some assistance individuals they can take data
    bt mail login
    garmin.com/express

    ReplyDelete
    Replies
    1. Niit Lab: Java Lab@4 >>>>> Download Now

      >>>>> Download Full

      Niit Lab: Java Lab@4 >>>>> Download LINK

      >>>>> Download Now

      Niit Lab: Java Lab@4 >>>>> Download Full

      >>>>> Download LINK iJ

      Delete
  2. The user can easily get a fix for Norton error code 100, for that the user should get the windows registry entries repaired, further, the user should get the malware scan conducted on the system, after that the user should get the system drivers updated. For more information, the user should get connected Norton antivirus helpline phone number with the team of certified experts.

    ReplyDelete
  3. Thanks For Good Posting Most powerfull Information But And Try It Kaspersky technical team the team can be reached for help through Emails, live chats and also through calls at https://www.pinterest.co.uk/pin/655836764474915279.

    ReplyDelete
  4. you site is good people can take easliy from your site kaspersky hepline number is best service kaspersky toll free number uk

    ReplyDelete
  5. Talking regarding the BullGuard virus scan feature we can say that, the user will have to open the virus scan feature there the user should choose the option “start scan” further the virus scan should be added to the browser. If required then to know more the user should get in touch with the BullGuard experts’ lines are open always. bullguard contact number uk | Bullguard Helpline number uk | BullGuard mobile security app not working

    ReplyDelete
  6. There are lots of blog of kaspersky to read here you can learn about antivirus and take help easily after reading.. and thanks to site author beacuse of they are provind us lots of information relested IT sector

    GUIDE TO FOLLOW FOR ENABLING ANTI- BANNER ON KASPERSKY
    WHAT SHOULD BE DONE TO ACTIVATE KASPERSKY SECURE CONNECTION VPN?

    WHY IS KASPERSKY SHOWING ‘KEY IS BLOCKED’ ERROR?

    HOW TO FIX THE "CORRUPTED DATABASE" ERROR OF KASPERSKY?

    ReplyDelete
  7. Niit Lab: Java Lab@4 >>>>> Download Now

    >>>>> Download Full

    Niit Lab: Java Lab@4 >>>>> Download LINK

    >>>>> Download Now

    Niit Lab: Java Lab@4 >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete