Results 1 to 2 of 2
  1. #1
    Jamil37037 is offline Member
    Join Date
    Feb 2013
    Location
    Islamabad, Pakistan
    Posts
    25
    Rep Power
    0

    Default Got stuck in sorting through interface

    Problem Resolved . Thanks
    Last edited by Jamil37037; 03-20-2013 at 09:58 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default Re: Got stuck in sorting through interface

    For the curious, that was:
    Quote Originally Posted by Jamil37037 View Post
    have to submit assignment in next 8 hours so please be fast.

    Ok here are specification.
    -->person class with name, address, contact no, age and setters and getters
    -->Student class extends Person and also have roll_no and grade and array for marks of 5 subjects.
    -->Have to create a link list in which student is the data part of each node and node next to stor adress
    --> Now i have to sort this linklist alphabetically. so i designed interface
    Java Code:
     interface Sortable{
     boolean isGreater(Sortable a);
     void swap(Sortable a);
     }
    and a sort class having static sorting function.
    Java Code:
     class Sort{
     public static void sorting(Sortable a){
     Sortable curr=a;
     Sortable curr1=a.next;//ERROR 1
     while(curr!=null){
     while(curr1!=null){
     if(curr.isGreater(curr1)){
     curr.swap(curr1);
     }
     else curr1=curr1.next;//ERROR 2
    
     }
     curr=curr.next;//ERROR 3
     }
     }
     }
    Call from main is as follows:
    Java Code:
     LinkList obj3=new LinkList();
     Sortable a=new Node();
     a=obj3.getFirst();
     Sort.sorting(a);

    And node class implementing interface.
    Java Code:
     class Node implements Sortable{
     Student student;
     Node next;
     Node(){}
     Node(String a,String b,long c,long d,int e,int[] f){
     student=new Student(a,b,e,c,d,f);
     next=null;
     }
     public String toString(){
     String s=student.toString();
     return s;
     }
     public boolean isGreater(Sortable a){
     if(this.student.isGreater(((Node)a).student)){
     return true;
     }
     else return false;
     }
     public void swap(Sortable a){
     this.student.swap(((Node)a).student);
     }
     }



    and student class implementing it as well

    Java Code:
     public boolean isGreater(Sortable x){
    
     if(this.getName().compareTo(((Student)x).getName() )>0)
     return true;
     else
     return false;
     }
    
     public void swap(Sortable c){
     String name;
     String address;
     long roll_no;
     long contact_no;
     int a;//for age
     int[] marks=new int[5];
    
     name=this.getName();
     this.setName(((Student)c).getName());
     ((Student)c).setName(name);
    
    
     }
    Now having error on ERROR 1 that cannot find symbol (Symbol next location a of type sortable)
    Same errors on ERROR 2 and ERROR 3
    Please don't delete posts in future.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 07-08-2012, 05:23 PM
  2. Replies: 4
    Last Post: 11-13-2011, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •