Question

I NEED A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX, if we have an DB...

I NEED A JAVA PROGRAM TO IMPLEMENT THE CONCEPT OF INDEX,
if we have an DB file has a records of students number and names like this

(Student file)
stNum**stName
1 jack
2 maya
3 sam
4 alex
5 jane
. .
. .
. .

this file may have a thousands records, if we want to search for a specific record(student),
we need to find it by (Index file), in this index file we have this

(Index file)
stNum**Address
1 (address or the record num from the Student file)
. .
. .
. .



so here we need to write a program with JAVA
to make it easy to find this specific record.

Homework Answers

Answer #1

Implementation in JAVA:

Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Student_Index {

   public static void main(String[] args) throws FileNotFoundException {
      
      
//       Student file class and its address
       File stufile = new File("C:\\Users\\Ankit\\Desktop\\sname.txt");
         
//       creating Student name's Scanner class object
           Scanner ss = new Scanner(stufile);
          
          
//               Address file class and its address
       File addfile = new File("C:\\Users\\Ankit\\Desktop\\address.txt");
         
//           creating Student Address's Scanner class object
       Scanner sa = new Scanner(addfile);
          
//       list of type Students
           ArrayList<Students> list= new ArrayList<>();
          
          
//           read file and Store in Arraylist
           try
           {
           while( ss.hasNext() && sa.hasNext() )
           {
              
               String name=ss.next();
              
               String add=sa.next();
                 
               Students s = new Students(name,add);
              
               list.add(s);
              
           }
           }
           finally
           {
           ss.close();
           sa.close();
           }

//           print
      
System.out.println(" Print All The Students Details\n");
      
       System.out.println(" INDEX NAME ADDRESS ");
       System.out.println(" ");
             
       for(int i=0;i<list.size();i++) {
          
           Students st = list.get(i);
          
           System.out.println(" "+(i+1)+" "+st.getname()+" "+st.getaddrs());
          
       }
      
      
//       you can simply get details of any particular student just by using index
//       like that, now i am printing Student at index 3
      
       System.out.println();
       System.out.println("Printing details of Student at index 3 : ");
      
       Students s= list.get((3-1));
      
       System.out.println("Index : 3, Name : "+s.getname()+", Address : "+s.getaddrs() );
      
       System.out.println();
      
      
      
      

   }

}

// class Students
class Students
{
//   instance Variables
   String name;
   String addrs;
  
//   Argumented constructor
   public Students(String name,String addrs){
      
       this.name=name;
       this.addrs=addrs;
   }
  
//   Getters and Setters methods
  
   public String getname()
   {
       return name;
       }
  
  
   public void setname()
   {
       this.name= name;
       }
  
  
   public String getaddrs()
   {
       return addrs;
       }
  
  
   public void setaddrs(String addrs)
   {
       this.addrs= addrs;
       }
  

}

SAMPLE OUTPUT:

FILES:

1. sname.txt

2.address.txt

// PLEASE THUMBS-UP AND RATE POSITIVELY
If you have any doubt regarding this question please ask me in commnets
// THANK YOU:-)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I need the actual code for this... I found a similar response but it was not...
I need the actual code for this... I found a similar response but it was not thorough enough. Problem Prerequisites: None Suppose that a scientist is doing some important research work that requires her to use rabbits in her experiments. She starts out with one adult male rabbit and one adult female rabbit. At the end of each month, a pair of adult rabbits produces one pair of offspring, a male and a female. These new offspring will take one...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
In narrative essay format, I want you to address a business/organization case study using multiple concepts...
In narrative essay format, I want you to address a business/organization case study using multiple concepts from class. The case question and case text begin on page 5 of this document. You need to demonstrate their best understanding of management and organizational behavior theory, and the application of those ideas to improve the understanding of various issues. You need to clearly identify at least 3 distinct, substantive issues. For each issue you need to 1), identify evidence from the case...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From...
Sign In INNOVATION Deep Change: How Operational Innovation Can Transform Your Company by Michael Hammer From the April 2004 Issue Save Share 8.95 In 1991, Progressive Insurance, an automobile insurer based in Mayfield Village, Ohio, had approximately $1.3 billion in sales. By 2002, that figure had grown to $9.5 billion. What fashionable strategies did Progressive employ to achieve sevenfold growth in just over a decade? Was it positioned in a high-growth industry? Hardly. Auto insurance is a mature, 100-year-old industry...