0% found this document useful (0 votes)
143 views

Project Program Question 4

The document defines two classes - Record and Rank. Record stores the names and ranks of 50 students. It has methods to read the values, and display the names and ranks. The Rank subclass finds the highest rank and name. It overrides the display method to print the top rank and name with the highest rank. The highest method finds the index of the topmost rank without sorting, and stores it in the index variable.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views

Project Program Question 4

The document defines two classes - Record and Rank. Record stores the names and ranks of 50 students. It has methods to read the values, and display the names and ranks. The Rank subclass finds the highest rank and name. It overrides the display method to print the top rank and name with the highest rank. The highest method finds the index of the topmost rank without sorting, and stores it in the index variable.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 7:-

A super class record has been defined to store the names and ranks of 50 students.

Define a

subclass Rank to find the highest rank along with the name.

The details of both the classes are given below:

Class name: record

Data members/instance variables:

name[] :to store the names of the students.

rnk[]: to store the ranks of the students.

Members functions

record(): constructor to initialise data members members.

void readvalue():to store the names and ranks and ranks.

void display(): display the names and the corresponding rank.

Class Name: Rank

Data members/instance variable:

Index: integer to store the index of top most rank.

Member functions/methods:

rank():constructor to invoke the base class.

constructor to initialise index

void highest():find the index/location of the topmost rank and store it in index without

sorting the array.

void display (): display the names and ranks along with the name having the topmost

rank.
ALGORITHM:-

class record

Step 1: start

Step 2: a single dimension array name and rank of size 50 are initialised

Record ()

Step 1: start

Step 2: a local variable i of int type is initialise

Step 3: initialise the data members with their initials

Step 4: end

void readValues ()

Step 1: start

Step 2: accept the name and rank of the students from the user

Step 3: end

void display ()

Step 1: start

Step 2: print the name of the students and ranks with suitable headings

Step 3: end

class ended

class Rank extends Record

Step 1: start

Step 2: an instance variable index is initialised

Rank ()

Step 1: start

Step 2: initialise the data member with its initial

Step 3: end
void highest ()

Step 1: start

Step 2: find the index of the topmost rank and store it in index without sorting

Step 3: end

void display ()

Step 1: start

Step 2: print the names and ranks of the students with the name having the topmost

rank

Step 3:

end
import java.util.*;

class Record

String name[] = new String[50];

int rnk[]=new int[50];

Record()

for(int i=0;i<50;i++)

name[i]="";

rnk[i]=0;

void readValues()

Scanner sc=new Scanner(System.in);

for(int i=0;i<50;i++)

System.out.println("ENTER NAME OF THE STUDENT");

name[i]=sc.next();

System.out.println("ENTER RANK OF THE STUDENT");

rnk[i]=sc.nextInt();

void display()

System.out.println("NAME\t\t"+"RANK");

for(int i=0;i<50;i++)
System.out.println(name[i]+"\t\t"+rnk[i]);

class Rank extends Record

int index;

Rank()

index=0;

void highest()

for(int i=0;i<50;i++)

if(rnk[i]<rnk[index])

index=i;

void display()

super.display();

System.out.println(“THE TOP MOST RANK:\t”+rnk[index]);

System.out.println(“NAME WITH TOP MOST RANK:\t”+name[index]);

}
OUTPUT:-
ENTER NAME OF THE STUDENT:

SUMAN

ENTER RANK OF THE STUDENT:

11

ENTER NAME OF THE STUDENT:

AMAN

ENTER RANK OF THE STUDENT:

ENTER NAME OF THE STUDENT:

ASHOK

ENTER RANK OF THE STUDENT:

ENTER NAME OF THE STUDENT:

NITIN

ENTER RANK OF THE STUDENT:

ENTER NAME OF THE STUDENT:

MOHIT

ENTER RANK OF THE STUDENT:

NAME
SUMAN
AMAN
ASHOK
NITIN
MOHIT
RANK
11
4
7
2
9
THE TOPMOST RANK: 2

NAME WITH TOPMOST RANK: NITIN


Variable Description Table:-

Variable Data Type Description

name[ ] String String to store name of the


student

rnk[ ] int Integers to store the rank of the


student

index int Integers to store a number

You might also like