Skip to main content

Output Generator HELP PLEASE!!!!

2 replies [Last post]
bboyewal
Offline
Joined: 2006-02-17
Points: 0

im having problems writing some code ....i think i need an output generator but am not sure....i started to write the code for it but im sort of stumped please help heres the code i have so far

http://www.uberdata.net/ue/Jeff's%20Folder/Java/bonuses.java

and this is the input file

http://www.uberdata.net/ue/Jeff's%20Folder/Java/prod-final.dat

and here is the detailed information on what im supposed to do
http://www.uberdata.net/ue/Jeff's%20Folder/Java/TakeHome.doc

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bboyewal
Offline
Joined: 2006-02-17
Points: 0

Im getting an error ...basically that it can't read from the file prod-final.dat which is the input file for instance
Abernathy Christine 83078307
^^ that is the first line in prod-final.dat, lastname firstname last years production and this years production (4 places each), what am i doing wrong (to not get the input file to be recognized)??

This is what i have right now:

[CODE]import java.io.*;
public class InputAndOutput
{
public static void main(String []args)
{

BufferedReader reader = null;

try
{
FileReader inFile = new FileReader("prod-final.dat");
reader = new BufferedReader (inFile);
}

catch (FileNotFoundException fnfe)
{
System.err.println("File not found...Exiting");
System.exit(-1);
}

String inputLine = null;

try
{
inputLine = reader.readLine();

String lastName = reader.readLine();
String firstName = reader.readLine();

while(inputLine != null)
{
inputLine = reader.readLine();

String lastProduction = reader.readLine();
String thisProduction = reader.readLine();
}
}
catch(IOException ioe)
{
System.err.println("I/O Exception encountered...Exiting");
System.exit(-2);

}

int numReps = -1;
double runLength = -1.0;
lastName = inputLine.substring(0,20).trim();
firstName = inputLine.substring(21,30).trim();
lastProduction = inputLine.substring(31,34).trim();
thisProduction = inputLine.substring(35,38).trim();
try {
inputLine = reader.readLine();
numReps = Integer.parseInt(inputLine);

inputLine = reader.readLine();
runLength = Double.parseDouble(inputLine);
}
catch(NumberFormatException nfe)
{
System.err.println("Invalid numeric data...Exiting");
System.exit(-1);
}
catch(IOException ioe)
{
System.err.println("I/O Exception encountered...Exiting");
System.exit(-2);
}
PrintWriter out = null;
try
{
FileWriter bonuses = new FileWriter("prod-final");
out= new PrintWriter(bonuses, true);
}
catch(IOException ieo)
{
System.err.println("Unable to open output file...Exiting");
System.exit(-2);
}
}
}[/CODE]

brinkley
Offline
Joined: 2003-06-06
Points: 0

Question doesn't belong in JavaHelp forum. Moved here.

Binky