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
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to...
JAVA: Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are passed to...
Java Implement one of the hashing procedures that we have discussed, and the following related functions:...
Java Implement one of the hashing procedures that we have discussed, and the following related functions: INSERT (item) DELETE (item) FIND (item) Make sure that your program correctly handles collisions and full hash table!
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the...
IN JAVA Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort: <-- (I need the code to be written with these) I need Class river, Class CTRiver and Class Driver with comments so I can learn and better understand the code I also need a UML Diagram HELP Please! Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong()...
Java please. Need to use a linked list only. Many people have used pulling petals off...
Java please. Need to use a linked list only. Many people have used pulling petals off roses and tossing them in the air to determine if someone loves them or not. Your sister wants to use roses to determine which one of several suitors she will let take her to the prom. A linked list can be used to represent the prom date suitors. Write a program to simulate her decision and determine her prom date. The simulation will work...
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...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database,...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database, exercise use of arrays of objects, external classes, processing files and user interaction. For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT