Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M9522396

Have any Question?


Related Questions in Java

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As