Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an application that allows you to enter student data than consists of an

ID: 3793602 • Letter: C

Question

Create an application that allows you to enter student data than consists of an ID number, first name, last name, and grade point average. If the student's GPA is less than 2.0, write the record to an academic probation file, otherwise, write the record to a good standing file Once the student records are complete, read in the good standing file. If the GPA is greater than or equal to 3.5, display the students name for the Dean's List Be sure to include any exceptions needed for the program to run smoothly. Save the file as StudentsStanding.java I've figured out the first part in writing the files, but having trouble with reading in the files to make the Dean's List.

Explanation / Answer

package com.ap.beans;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Student {
   public int id;
   public String fname;
   public String lname;
   public double gpa;

   public Student(int id, String fname, String lname, double gpa) {
       this.id = id;
       this.fname = fname;
       this.lname = lname;
       this.gpa = gpa;
   }

   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public String getFname() {
       return fname;
   }

   public void setFname(String fname) {
       this.fname = fname;
   }

   public String getLname() {
       return lname;
   }

   public void setLname(String lname) {
       this.lname = lname;
   }

   public double getGpa() {
       return gpa;
   }

   public void setGpa(double gpa) {
       this.gpa = gpa;
   }

   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + ((fname == null) ? 0 : fname.hashCode());
       long temp;
       temp = Double.doubleToLongBits(gpa);
       result = prime * result + (int) (temp ^ (temp >>> 32));
       result = prime * result + id;
       result = prime * result + ((lname == null) ? 0 : lname.hashCode());
       return result;
   }

   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Student other = (Student) obj;
       if (fname == null) {
           if (other.fname != null)
               return false;
       } else if (!fname.equals(other.fname))
           return false;
       if (Double.doubleToLongBits(gpa) != Double.doubleToLongBits(other.gpa))
           return false;
       if (id != other.id)
           return false;
       if (lname == null) {
           if (other.lname != null)
               return false;
       } else if (!lname.equals(other.lname))
           return false;
       return true;
   }

   @Override
   public String toString() {
       return id + " " + fname + lname + " " + gpa;
   }

   public static void main(String[] args) {
       List<String> deanlist = new ArrayList<String>();
       File file = null;
       PrintWriter writer = null;
       Scanner scanner = new Scanner(System.in);

       System.out.println("enter the student no");
       int id = scanner.nextInt();
       System.out.println("enter the student fname");
       String fname = scanner.next();
       System.out.println("enter the student lname");
       String lname = scanner.next();
       System.out.println("enter the student gpa");
       double gpa = scanner.nextDouble();
       Student student = new Student(id, fname, lname, gpa);

       if (gpa < 2.0) {
           file = new File("D:\academicprobation.txt");

           try {
               writer = new PrintWriter(file);
               writer.write(student.toString());
               writer.flush();
               System.out.print(" ");
           } catch (FileNotFoundException e) {

               System.out.println("the academic probation file is not found ");
           }

       } else {
           file = new File("D:\goodstudents.txt");

           try {
               writer = new PrintWriter(file);
               writer.write(student.toString());
               writer.flush();
               System.out.print(" ");
           } catch (FileNotFoundException e) {

               System.out.println("the academic probation file is not found ");
           }

       }
       // to read the file and make adean's list
       try {
           System.out
                   .println("enter the file name to read and make a deans list");
           String filename = scanner.next();
           BufferedReader reader = new BufferedReader(new FileReader(new File(
                   filename)));

           String line = null;
           while ((line = reader.readLine()) != null) {
               int count = 0;
               String[] words = line.split("\s+");

               for (String word : words) {
                   count++;
                   if (count == 2) {
                       deanlist.add(word);
                   }

               }

           }
       } catch (FileNotFoundException e) {
           System.out.println("file not found ");
       } catch (IOException e) {
           System.out.println("error occured while reading the file ");
       }

       // for displaying the deanlist names
       for (String name : deanlist) {
           System.out.println("the name is " + name);
       }

   }

}

output

//enter the wanted fields and give the file names in which files you want to store it will work

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote