Question

In: Computer Science

Create an application that allows you to enter student data than consists of an ID number,...

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.

Solutions

Expert Solution

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(" \n");
           } 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(" \n");
           } 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


Related Solutions

Create a C# application for Cricket Team that allows you to enter data for player of...
Create a C# application for Cricket Team that allows you to enter data for player of Cricket Team and saves the data to a file named Players.txt. Create a Player class that contains fields for of participant's first name, last name, age, salary and position (wicketkeeper, bawler, striker, midwicket), and To String() method. The fields of records in the file are separated with semicolon (. Expecting sentinel value for ending the process of writing to file is *. E.g. of...
Create a C# application for Library that allows you to enter data for books and saves...
Create a C# application for Library that allows you to enter data for books and saves the data to a file named Books.txt. Create a Book class that contains fields for title, author, number of pages, and price of the book and ToString() method. The fields of records in the file are separated with asterisk (*). Expecting sentinel value for ending the process of writing to file is "000"
Show: Create an application that allows the user to enter the number of calories and fat...
Show: Create an application that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *9 The percentage of...
Write an application that allows a user to enter any number of student quiz scores, as...
Write an application that allows a user to enter any number of student quiz scores, as integers, until the user enters 99. If the score entered is less than 0 or more than 10, display Score must be between 10 and 0 and do not use the score. After all the scores have been entered, display the number of valid scores entered, the highest score, the lowest score, and the arithmetic average.
Write an application that allows a user to enter any number of student quiz scores until...
Write an application that allows a user to enter any number of student quiz scores until the user enters 99. If the score entered is less than 0 or more than 10, display an appropriate message and do not use the score. After all the scores have been entered, display the number of scores entered, the highest score, the lowest score, and the arithmetic average. Save the file as QuizScoreStatistics.java. I am struggling with looping in Java and do not...
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Create an application that allows the user to enter the total for an order and the...
Create an application that allows the user to enter the total for an order and the name of the customer. If the order is less than 500 dollars, the customer gets no discount. If the order is greater than or equal to 500 and less than 1000 dollars, the customer gets a 5 percent discount. If the order is greater than or equal to 1000 dollars, the customer gets a 10 percent discount. The application should display the name of...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner;...
In this create a code that will drop a student by ID number //////////////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public void...
Android Studio. Java. Please create an application that -> An activity that allows user to enter...
Android Studio. Java. Please create an application that -> An activity that allows user to enter name, gender, date of birth, state of residence (selected from a pre-defined list: CA, AZ, NV, OR), email address and favorite website. This activity has a button "Show Data" that displays detail entered
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT