First, I'd like to thank this community, although I haven't been here long, I appreciate every bit of it.
I'm working on a school project, and I think for the most part I got it all figured out except this last little bit. Of course, feel free to offer any advice on anything you see, but my main question is below.
I'm having difficulty printing this out: Should I use a loop, like a boolean to test if true to the posted values?
Count of investment performance indicators: a. Number of As: values $1250 or higher b. Number of Bs: values $1100 or higher and less than $1500 c. Number of Cs: values $900 or higher and less than $1100 d. Number of Ds: values $750 or higher, and less than $900 e. Number of Fs: values less than $750
Lastly, once again thank you all for the patience and understanding. I'm really interested in learning how it all works, so if you could please explain how it works, I'd really appreciate that.
The program calls for a min, max, and mean of the values from a text file. Just a little info to help.(which I've done already)
So far I've tried loops to test the values, I'm not sure I did it right, but it didn't work for me.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
public class Prog07_InvestmentManager {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Scanner inFile=null;;
File file=null;
boolean flag=true;
while(flag) {
try {
flag=false;
System.out.println("Please enter the file name to import, including file extension."); //prompt user
file = new File(in.nextLine()); //store user input in variable
inFile = new Scanner(new FileReader(file)); //read file
}
catch (FileNotFoundException e1) {
flag=true;
}
}
double min = Integer.MAX_VALUE;
double max = 0;
double mean = 0;
inFile.nextLine();
double line = 0;
int sum = 0;
int count = 0;
while (inFile.hasNextLine()) {
line=inFile.nextDouble();
sum+=line;
count++;
if(line>max)
max=line;
if(line<min)
min=line;
}
mean = (sum/count);
System.out.printf("Max: %-4.2f\n", max);
System.out.printf("Min: %-4.2f\n", min);
System.out.printf("Mean: %-4.2f\n", mean);
System.out.println();
if (in.hasNextDouble()) {
double[] values = new double [(int) in.nextDouble()];
}
try {
Scanner inputFile = new Scanner(file);
double[] arr = new double[(int) in.nextDouble()];
for (int i = 0; in.hasNextDouble(); i++) {
arr[i] = in.nextDouble();
}
} catch (FileNotFoundException e) {
file = new File("investments.txt");
System.out.print("File not found.\nPlease enter the correct path if needed.");
file = new File(in.nextLine());
}
in.close();
}
}