Question: I keep getting the error fir my java codestudents.txt not found please help me fix import java.io . File; import java.io . FileNotFoundException; import java.util.ArrayList;

I keep getting the error fir my java code"students.txt not found" please help me fix import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private String name;
private int creditHours;
private int qualityPoints;
public Student(String name, int creditHours, int qualityPoints){
this.name = name;
this.creditHours = creditHours;
this.qualityPoints = qualityPoints;
}
public double gpa(){
return (double) qualityPoints / creditHours;
}
public boolean eligibleForHonorSociety(){
return gpa()> HonorSociety.getGpaThreshold();
}
@Override
public String toString(){
return "Name: "+ name +", GPA: "+ gpa();
}
public static void setGpaThreshold(double threshold){
HonorSociety.setGpaThreshold(threshold);
}
}
class Undergraduate extends Student {
private String year;
public Undergraduate(String name, int creditHours, int qualityPoints, String year){
super(name, creditHours, qualityPoints);
this.year = year;
}
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSociety() && (year.equals("Junior")|| year.equals("Senior"));
}
@Override
public String toString(){
return super.toString()+", Year: "+ year;
}
}
class Graduate extends Student {
private String degree;
public Graduate(String name, int creditHours, int qualityPoints, String degree){
super(name, creditHours, qualityPoints);
this.degree = degree;
}
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSociety() && degree.equals("Masters");
}
@Override
public String toString(){
return super.toString()+", Degree: "+ degree;
}
}
class HonorSociety {
private static double gpaThreshold;
public static double getGpaThreshold(){
return gpaThreshold;
}
public static void setGpaThreshold(double threshold){
gpaThreshold = threshold;
System.out.println("Honor Society GPA Threshold set to: "+ gpaThreshold);
}
}
public class Project2{
public static void main(String[] args){
ArrayList students = new ArrayList<>();
try {
Scanner scanner = new Scanner(new File("students.txt"));
double totalGpa =0;
int count =0;
while (scanner.hasNextLine()){
String line = scanner.nextLine();
String[] data = line.split("");
String name = data[0]+""+ data[1];
int creditHours = Integer.parseInt(data[2]);
int qualityPoints = Integer.parseInt(data[3]);
if (data.length ==5){
// Undergraduate
String year = data[4];
students.add(new Undergraduate(name, creditHours, qualityPoints, year));
} else if (data.length ==4){
// Graduate
String degree = data[3];
students.add(new Graduate(name, creditHours, qualityPoints, degree));
}
totalGpa += students.get(count).gpa();
count++;
}
if (count >0){
double averageGpa = totalGpa / count;
Student.setGpaThreshold((4.0+ averageGpa)/2);
}
scanner.close();
} catch (FileNotFoundException e){
System.out.println("Error: students.txt not found.");
return;
}
System.out.println("Honor Society Members:");
for (Student student : students){
if (student.eligibleForHonorSociety()){
System.out.println(student);
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!