Program to store student record, JAVA Programming

Assignment Help:

Write a program called Grid. The program starts by prompting (asking) the user for the name of an input text file.

This file is guaranteed to be correct and has the following format 

11
Paul di Resta
Force India-Mercedes
46.876
 
The above 4 lines make up what is known as a record. This means that if there is an integer, then the other 3 lines of the record are also present.

There may be any number of records in the input text file. There are NO blank lines between records and no blank line at the end of the file.

The output of this program is that there is a text file with the records sorted in order, with the lowest time at the start of the file, followed by records with increasing times, so that the record with the largest time is at the end of the file. 
 
Note: you are NOT allowed to solve this problem using data structures that have not yet been covered in this unit, such as arrays or linked lists.  You may only use methods from the String class, the Scanner class, the PrintWriter class, the PrintStream and the File class (along with as many temporary text files as may be needed).
 
One possible approach is to read the first record from the input file. Then, inside a loop, read the next record.  Now compare the times, if the first record's time is less than the second record's time, write the first record into the temporary file and set all the values of the first record equal to the values of the second record.

That is, the variable that holds the time of record 1, now has the value of the variable that holds the time of record 2, copied into it and so on for the other variables used to store the values read from the file.

This is because the program is going through the loop again and will read a new set of values into the variables that hold record 2 values.
 
If the time of record 2 is less than the time of record 1, just write the contents of record 2 into the output file, there is nothing to change in record 1.
 
Keep reading records from the input file and writing to the output file until the program reaches the end of the input file. Do not forget to write the last record into the output file. Now close both the input and output files.
 
Swap the file names so that the input file becomes the output file name and the output file name becomes the input file name.
 
Re open both the files.
 
Go back through the process described above once again.
 
Eventually the input file will be sorted. This means that the program will go through the entire input file without making a single swap (time 1 will always be < time 2)

Once this happens it means that the records in the file are properly sorted and the program can stop.

Note: the above approach is one way of solving the problem, but you may use another approach if you wish.


Related Discussions:- Program to store student record

Overloading method, QUESTION 3: Overloaded methods Write the overloaded me...

QUESTION 3: Overloaded methods Write the overloaded method named average () for each of the following problems: a) The first method receives THREE (3) integer values and returns

We require expert programmers who will solve problems, We require expert pr...

We require expert programmers who will solve problems, who can code by the book, and who will code in java and JavaScript what is designed. Skills required: CSS, Java, HTML5,

Create a simple object based gui application, Objective: create a simple o...

Objective: create a simple object, put that object in a simple collection class, use that object and collection in a simple GUI application. Specification:  Consider a Librar

What is constructor chaining, What is constructor chaining and how is it ac...

What is constructor chaining and how is it achieved in Java? A child object constructor always first requires to construct its parent (which in turn calls its parent constructo

Card, Create a class called DeckOfCards that stores 52 objects of the Card ...

Create a class called DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle the deck, deal a deck, and report the number of cards left in the deck. The s

Differentiate uni-processor os from multi-processor os, Differentiate uni-P...

Differentiate uni-Processor OS from Multi-Processor OS? Uni-processor OS : Uni-processor OS'es is designed to schedule tasks on a single uPs just whereas Multiprocessor O

Prepare a small android application, Android App Project Description: ...

Android App Project Description: I am seeking an experienced individual to prepare a small android application The only difference is that I would like movement to be done

Debugging, Debugging mode can be enabled by adding the following line of co...

Debugging mode can be enabled by adding the following line of code before creating new connections: XMPPConnection.DEBUG_ENABLED = true; When debugging mode is enabled, a

Explain any five buzz words in java, Question 1 Explain any five buzz w...

Question 1 Explain any five buzz words in Java 2 Explain exception classes and also explain common exceptions in java 3 Explain primitive and abstract data type in java

write program a, How do I write a program a bout Rotor cipher

How do I write a program a bout Rotor cipher?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd