| // Reading data from a sequential file --
very important for the first program
import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class Application1
{
public Application1()
{
char race, gender;
int age, weight;
int fat_men = 0;
int people = 0;
try
{
FileInputStream filein = new
FileInputStream("data1.txt");
DataInputStream in = new
DataInputStream(filein);
do
{
race = in.readChar();
gender = in.readChar();
age = in.readInt();
weight = in.readInt();
people ++;
if (gender == 'M')
{
if (weight > 600)
fat_men = fat_men + 1;
}
}
while ( people < 10);
JOptionPane.showMessageDialog(null,"number of fat
men
"+fat_men,"file output",JOptionPane.NO_OPTION);
filein.close();
}
catch (IOException e)
{
}
}
public static void main(String[] args)
{
Application1 app = new
Application1();
System.exit(0);
}
}
|