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

Using Java import data from a text file named fata.txt then create two Student o

ID: 673180 • Letter: U

Question

Using Java import data from a text file named fata.txt then create two Student objects with the following name(String), id(String), and gpa(double values:

S1: John, 1111, 3.5

S2: Jean,2222, 3.9

The Student class must be a subclass of a Person class. The Person class must have a name field and an id field and the Student class must have a gpa field. THe Student class must also implement an interface called CurveGPA. The interface forces the Student class to implement a curveGPA() method that would add to each exisiting GPA.

Display these two objects with the curved GPA values on the console using toString() method.

Make it so the two objects can be saved into an arraylist or an array. The two objects or the arraylist or the array will then be saved into a binary file. After that, you will display the information on the console or GUI by reading the data from the binary file.

Explanation / Answer

Import data from text file

import java.io*;

public class ReadTextfile{
   public static void main (String[] args) {
      File file = new File ("fata.txt");
      StringBuilder line = new StringBuilder();
      BufferedReader reader = null;

try {
    reader = new BufferedReader (new FileReader(file));
    String text = null;

    while ((text = reader.readLine()) !=null) {
           line.append(text)
               .append(System.getProperty ("line.separator"));
    }
    }
    catch (IOException e) {
      e.printStackTrace();
    catch (FileNotFoundException e) {
      e.printStackTrace();
   }finally {
    try {
        if (reader !=null){
            reader.close();
    }
    }
    catch (IOException e) {
      e.printStackTrace();
    }
    }
    System.out.println(line.toString());
    }
    }


GPA values on the console using toString() method

package One;
class Person{
    String name;
    String id;

    Person(String s, String id){
        name = s;
        id = d;
    }
    @Override
    public String toString(){
        return "Name: "+name+" Id: "+id;
    }
}
class Student extends Person{
    double gpa;
    Student(String s){
        gpa = s;
    }
    @Override
    public String toString(){
        return "The student did his majors in "+gpa;
    }
}


public class Test {

    public static void main(String[] args) {
        Person p = new Person("John", 1111);
        System.out.println(p);
    }
}

display the information on the console or GUI by reading the data from the binary file


import java.io.*;
class ConsoleInput
{
public static void main(String[] args) throws IOException
{
    String id;
    String name;
    BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
    System.out.println(“Enter Id: ”);
    rollNumber = Integer.parseInt(br.readLine());
    System.out.println(“Enter the name: ”);
    name = br.readLine();
    System.out.println(“Id = “ + id);
    System.out.println(“Name = “ + name);
}
}

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