Tuesday, 27 September 2016

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

 }

No comments:

Post a Comment