Tuesday, 27 September 2016

CORE JAVA LAB@HOME 7 ~ GNIITHELP

Question-1 Deque Object.

Answer:-   The following answer are in the Image format.



































Question-2 Kiwi Request and Response 

Answer:-

import java.until.ArrayDequr;


 public class Request  {


  ArrayDeque<String> pool;


  public Request()   {

       pool = new ArrayDeque<String>();

  }


  public void initRequest(String i, String p)   {

   String ID = i;

   String prb = p;


   String rqt = "Empliyee ID: " + ID +"\nProblem: " + prb;

   pool.add(rqt);


  }


  public void dispRequest()   {

   System.out.println

 ("================================================================");

  System.out.println("-----------------------REQUEST POOL-------\n");


  if (pool.isEmpty () == true) {

           System.out.println ("Currently, there is no request in the pool.");

        }

           else

        {

             for (String s : pool) {

             System.out.println (s);

             System.out.println

      ("--------------------------------------------");

    }

 }


}

      public void attdRequest () {

       String status;


     if (pool . isEmpty () == true) {

         System.out.println

   ("=====================================================");

     System.out.println ("Currently, there is no request in the pool.");

      } else {

           System.out.println

   ("=====================================================");

      System.out.println ("You need to resolve yhr following problem:");

        System.out.print(pool . getFirst () );

  

        status = "R";


      if (status . toUpperCase () . equals ("R") ) {

           System.out.println

    ("======================================================");

       System.out.println ("The problem has been resolved:");

         System.out.println (pool . getFirst () );

          pool . remove ();

     } else if (status . toUpperCase () . equals ("P") ) {

         System.out.println

   ("\n=======================================================");

         System.out.println ("Please resolve the problem ASAP .");

           } else {

              status = "N";

        }

    }

}


     public static void main (String [] args) {

        Request rq = new Request ();

        rq . initRequest ("3423", "System is not working");

        rq . initReuest (" 3764", "Internet is not working");

        rq . dispRequest ();

        rq . attdRequest ();

    }

}    


Question-3 Add a student Details.

Answer:-


Public class Student implements Comparable  {



  private String name;

  private int marks;


  public Student (String nm, int mk)  {

   this.name = nm;

   this.marks = mk;

  }


  public int getMarks()   {

   return marks;

  }


  public void getName()  {

   return name;

  }


  public void setName(String name)  {

   this.name = name;

  }


  public int compareTo (Object obj)  {

   Student s = (Student) obj;


   if (this.marks > s.getMarks())  {

        return 1;

   } else if (this.marks < s.getMarks())  {

        return -1;

   } Else {

        return 0;

   }

  }

  public String toString()  {

   StringBuffer buffer = new StringBuffer();

   buffer.append("Name: " + name + "\n");

   buffer.append("Marks: " + marks + "\n");

   return buffer.toString();

  }

 }



 import Java.until.Comparator;

 public class NameCompare implements Conparator{

  public int compare(Object a, Object b)

  {

   Student x = (Student) a;

   Student yx = (Student) b;

   return x.getName() .compareTo(y.getName());

  }

 }



  import java.until.ArrayList;

  import java.until.Collections;

  import java.until.ListIterator;


  public class Sorting  {


   public static void main (String[]  args)  {

    Student s1 = new Student("Joe",88);

    Student s2 = new Student("Bob",90);

    Student s1 = new Student("Alex",78);


    ArrayList<Student> obj = new ArrayList<>();

    obj.add(s1);

    obj.add(s2);

    obj.add(s3);


    System.out.println("Student details are:");


    ListIterator li = obj.listIterator();

    while (li.hasNext())   {

       System.out.println(li.next());

    }


    collection.sort(obj);


    System,out.println("Mark wise sort:");


    ListIterator li2 = obj.listIterator();

    while (li2.hasNext())

       System.out.println(li2.next());

    }

    Collection.sort(obj, new NameCompare());


    System.out.println("Name wise sort:");


    ListIterator li3 = obj.listIterator();

    while (li3.hasNext())  {

       System.out.println(li3.next());

   }

  }

 }

No comments:

Post a Comment