Well, I have to edit a program which we previously used for reading a header file to be able to read a trailer from a .dat file. The .dat file consists of 5 entries in each record and I am assuming atleast 5 records(which I believe the amount of records should be taken from the trailer). Also I believe he said the SENTINEL value must be -1.
Our instructor gave us an extremely limited amount of information on how to attempt to do this and its not in our text book and google provided no clear information on the subject that I could gather.
So if possible, could you point me in the direction of a webpage with information on this topic?
If there are no pages with relevent information, could you explain to me how I would go about editing my code below?
I bolded and underlined all areas which I believe are relevant to my problem and I also noted in certain areas using (*// ).
I would appreciate any input. I have been racking my brain for the past few hours trying to get this to work. Anyway, thank you. .dat File(the one I have been using for testing) =
4 5 4 9 3
3 5 7 1 6
8 6 5 3 4
4 2 5 3 8
6 1 7 9 6
5
(*//I believe since I need to read a trailer file, that the # of records would be last compared to the header being first) -
import java.util.Scanner;
-
import java.io.FileNotFoundException;
-
import java.io.FileInputStream;
-
-
public class TrailerProgram
-
{
-
public static void main (String[] args)
-
{
-
final int SENTINEL = -1;
-
int trailer=0,i=0;
-
long n1,n2,n3,n4,n5,small;
-
Scanner scanInput = null; // Create a Scanner called scanInput
-
-
-
-
// Data File
-
try
-
{
-
-
scanInput = new Scanner
-
(new FileInputStream ("TrailerFile.dat"));
-
-
headings();
-
-
-
-
// reading trailer
-
trailer = scanInput.nextInt(); (*// I am not sure how to scanInput from last value rather than from the first )
-
System.out.println ("\n\n\n " + "Program Name");
-
System.out.println (" " + "TRAILER VALUE IS " + trailer);
-
System.out.println ("\n" + "SET # SMALLEST VALUE INPUT VALUES FROM THE DATA FILE");
-
-
for(i=1;i<=trailer;i++) (*// I am not sure what he wanted the sentinel value to do at -1. )
-
{
-
-
n1 = scanInput.nextLong();
-
n2 = scanInput.nextLong();
-
n3 = scanInput.nextLong();
-
n4 = scanInput.nextLong();
-
n5 = scanInput.nextLong();
-
-
-
small = findSmallValue ( n1, n2,n3, n4, n5);
-
System.out.printf("%3d.",i);
-
printValues(n1,n2,n3,n4,n5,small);
-
}
-
-
-
-
-
}
-
catch (FileNotFoundException e)
-
{
-
System.out.println ("\n\n\n\n"
-
+ "**** The following data file was not found. ****");
-
System.out.println
-
( "**** TrailerFile.dat ****");
-
-
}
-
-
}
-
-
// ===================== findSmallValue =====================
-
//determine the smallest value of the four longs returned .
-
-
public static long findSmallValue (long n1, long n2, long n3, long n4, long n5)
-
{
-
long small = 0;
-
-
if ((n1 <= n2) && (n1 <= n3) && (n1 <= n4) && (n1 <= n5))
-
small = n1;
-
else if ((n2 <= n1) && (n2 <= n3) && (n2 <= n4) && (n2 <= n5))
-
small = n2;
-
else if ((n3 <= n1) && (n3 <= n2) && (n3 <= n4) && (n3 <= n5))
-
small = n3;
-
else if ((n4 <= n1) && (n4 <= n2) && (n4 <= n3) && (n4 <= n5))
-
small = n4;
-
else
-
small = n5;
-
-
return small;
-
-
}
-
-
// ===================== printValues =====================
-
//
-
-
public static void printValues (long n1, long n2, long n3, long n4, long n5, long small)
-
{
-
-
-
System.out.printf("%15d %15d %7d %5d %5d %5d\n",small,n1,n2,n3,n4,n5);
-
-
}
-
-
}
0 1904 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Raymond Hettinger |
last post by:
Found in a pamphlet at a pre-school:
---------------------------------------
Reading improves vocabulary
Reading raises cultural literacy through shared knowledge
Reading develops writing skills
Reading opens the mind to new ways of understanding
Reading is fun
Accordingly, I suggest the following works of literature:
|
by: sbh |
last post by:
I'm copying data out to a file with pipe delimiters. I would like to
add a header and trailer.
Is this possible? If so, please help me with the steps.
Also, is it possible to append to a text file while doing the bcp? If
so, how?
|
by: Lionel B |
last post by:
Greetings,
I need to read (unformatted text) from stdin up to EOF into a char
buffer; of course I cannot allocate my buffer until I know how much
text is available, and I do not know how much text is available until I
have read it... which seems to imply that multiple reads of the input
stream will be inevitable.
Now I can correctly find the number of characters available by:
|
|
by: Oliver Knoll |
last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode
(that is just writing, right?). How would one reopen it for reading?
I got the following (which works):
FILE *tmpFile = tmpfile();
/* write into tmpFile */
...
|
by: Yeow |
last post by:
hello,
i was trying to use the fread function on SunOS and ran into some
trouble.
i made a simple test as follows:
i'm trying to read in a binary file (generated from a fortran code)
that contains the following three floating-point numbers:
1.0 2.0 3.0
| |
by: Catalin Porancea |
last post by:
Hello,
I have a txt file that I need to validate before importing in a database. In
order to be valid, the file needs to have a header, records and a trailer.
How do I read only the first and the last line in the file and load them in
2 strings so I can compare them?
Thank you.
Catalin
|
by: Mike Reed |
last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code
to read a cookie's expiration date/time in an ASP page/VBScript.
What am I missing?
*** Sent via Developersdex http://www.developersdex.com ***
|
by: Gaijinco |
last post by:
I had a file named nap.in which looks like this:
4
10:00 12:00 Lectures
12:00 13:00 Lunch, like always.
13:00 15:00 Boring lectures...
15:30 17:45 Reading
4
10:00 12:00 Lectures
12:00 13:00 Lunch, just lunch.
|
by: henry |
last post by:
Folks:
Using Dreamweaver CS3...
Consider a home page, "index.php" which conditionally REQUIREs one of 'N'
HTML files of pure content. All site styles are specified in a master CSS
file, "siteformatting.css"
The home page, "index.php" must link to the master CSS file, so that HTML
elements in this file can conform to site-wide standards, right? (Or
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |