Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Last active August 29, 2015 14:00
Show Gist options
  • Save JorgeOlvera/11141522 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/11141522 to your computer and use it in GitHub Desktop.
Clients App
import java.io.*;
import java.util.*;
public class clientsApp{
public static void main(String [] args) throws IOException{
try{
Scanner file = new Scanner(new File("clients.txt"));
PrintWriter outputFileM = new PrintWriter(
new BufferedWriter(
new FileWriter("male.txt")));
PrintWriter outputFileF = new PrintWriter(
new BufferedWriter(
new FileWriter("female.txt")));
int theCounter = 0;
int maleCounter = 0;
int femaleCounter = 0;
int maleBalance = 0;
int femaleBalance = 0;
for(int x = 0; x < 30; x++){
String client = file.nextLine();
String gender = file.nextLine();
int balance = file.nextInt();
file.nextLine();
if(gender.charAt(0) == 'm'){
outputFileM.println(client);
outputFileM.println(gender);
outputFileM.println(balance);
maleCounter++;
maleBalance = maleBalance + balance;
} else{
outputFileF.println(client);
outputFileF.println(gender);
outputFileF.println(balance);
femaleCounter++;
femaleBalance = femaleBalance + balance;
}
theCounter++;
}
System.out.println("The total amount of customers is: " + theCounter);
System.out.println("The number of males is: " + maleCounter);
System.out.println("The number of females is: " + femaleCounter);
System.out.println("The average balance for males is: " + (maleBalance/maleCounter));
System.out.println("The average balance for females is:" + (femaleBalance/femaleCounter));
} catch (FileNotFoundException e){
System.err.println("Some exception happened " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment