icse-promo

Question

A super class Record has been defined to store the names and ranks of 50 students. Define a sub-class
Rank to find the highest rank along with the name.The details of both classes are given below:
Classname:Record
Data Members / instance variables:
name[ ]:to store the names of students
mk[ ]:to store the ranks of students
Member functions:
Record():constructor to initialize data members
void readvalues():to store the names and ranks
void display():display the names and the corresponding ranks
Classname:Rank
Data members/ instance variables:
index: integer to store the index of the top most rank
Member functions:
Rank():constructor to invoke the base class constructor and to initialize index=0
void highest():finds the index/location of the top most rank and stores it in index without sorting the array.
void display():displays the names and ranks along with the name having the top most rank.
Specify the class Record giving details of the constructor(), void readvalues() and void display().Using the concept of inheritance, specify the class Rank giving details of constructor( ),void highest() and void display().
THE MAIN() FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;

public class Record
{
    Scanner sc=new Scanner(System.in);
    String name[]=new String[50];
    int rnk[]=new int[50];
    public Record()
    {
        for(int i=0;i< 50;i++)
        {
            name[i]="";
            rnk[i]=0;
        }
    }
    public void readvalue()
    {   
        int i=0;
        System.out.println("enter names & ranks");
        for(i=0;i< 50;i++)
        {
            name[i]=sc.nextLine();
        }
        rnk[i]=sc.nextInt();

    }
    public void display()
    {
        int i=0;
        for(i=0;i< 50;i++)
        {
            System.out.println(name[i]+","+rnk[i]);
        }
    }
}



import java.util.Scanner;
public class Rank extends Record
{
    Scanner sc=new Scanner(System.in);
    int index;	
    public Rank()
    {
        super();
        index=0;
    }
    public void highest()
    {
        int i=0;
        for(i=0;i< 50;i++)
        {	
            if(rnk[index]>rnk[i])
            {
                index=i;
            }
        }
    }
    public void display()
    {	
        readvalue();
        highest();
        super.display();
        System.out.println("Name of the highest rank holder:"+name[index]);
    }
}






				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *