File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Could someone help me out with this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Could someone help me out with this?" Watch "Could someone help me out with this?" New topic
Author

Could someone help me out with this?

Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
this involves changing the input data stream to include five days of information in order to generate the week's pay. The organization of the data file is workers first name, last name, hourly wage and then 5 sets of two numbers representing each day of the week. The first number in the pair represents regular hours for that day while the second number represents overtime hours for that day.
Kermit D.Frogge 5.25 0.0 8.0 1.5 8.0 2.25 7.75 0.0 8.0 2.0
Based on this organizational scheme, Kermit worked 5.25 regular hours on Monday and 0.0 overtime hours. On Tuesday, he worked 8.0 regular hours and 1.5 overtime hours, etc.....

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package project35;

/**
*
* @author kirtida
* October 28, 2009
* Great Valley
*

/**
* @param args the command line arguments
*/

// file input demo

import java.io.*;
import java.util.StringTokenizer;

public class Project
{
// variables necessary for file input
private static FileInputStream inFile;
private static InputStreamReader inReader;
private static BufferedReader reader;

// StringTokenizer variable used to separate line into different data elements
private static StringTokenizer strTkn;

// program variables to hold data
private static String line,word;
private static int num1, num2,num3,grade, total;
private static double avg;

// throws IOException will have the operating system handle any problems
// that may occur while attempting to acquired data from the file.

public static void main (String args[]) throws IOException
{

initFile();
getData();
calcTotal();
printResults();

// closing the data file
inFile = new FileInputStream ("//Users/106780/Desktop/HSAPCSData//test.txt");
}


// preparing the file for input

public static void initFile() throws IOException
{
inFile = new FileInputStream ("//Users/106780/Desktop/HSAPCSData//test.txt"); // notice the double slash marks
inReader = new InputStreamReader(inFile);
reader = new BufferedReader(inReader);
}


//data acquisition method

public static void getData() throws IOException
{
line = reader.readLine(); //acquiring the data line as a string
System.out.println ("data line = " + line ); // view data line as one string
System.out.println();

strTkn = new StringTokenizer(line); // attaching the string tokenizer to the line

// placing the first word in the dataline into a string variable
word = strTkn.nextToken();

// extracting the parts of the line into separate int and double variables
grade = Integer.parseInt(strTkn.nextToken());
avg = Double.parseDouble(strTkn.nextToken());
num1 = Integer.parseInt(strTkn.nextToken());
num2 = Integer.parseInt(strTkn.nextToken());
num3 = Integer.parseInt(strTkn.nextToken());
}

// processing the int totals
public static void calcTotal()
{
total = num1 + num2 + num3;
}

// output results

public static void printResults()
{
System.out.println("Separated data line :");
System.out.println(word);
System.out.println (grade);
System.out.println (avg);
System.out.println(num1);
System.out.println(num2);
System.out.println(num3);

System.out.println("sum of numbers = " + total);
}

} // end of class
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3947
    
  17

Hi Jeff,

Can you edit your post and UseCodeTags which will make it easier to read. Also, TellTheDetails - what problem are you having?


Steve
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Please also use a meaningful subject line....



It looks like that section came from another application. If you want to adapt it, that's fine, but you need to understand what you want and how to ask the computer to give it to you.

You should start in smaller sections.... get the file input to work and output to the screen, then divide it up into strings and output to screen. Then figure out what needs to be done from there.

My $0.02
Janeice


When you do things right, people won't be sure you've done anything at all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could someone help me out with this?
 
Similar Threads
Integer Object Comparision Confusion
Triangle Perimeter HELP!!!
Problem with Sort Method
Large Numbers
Erroneous sym type What does this mean?