Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a java class FileHandler that has a parameter constructor that takes 2 strings - a read from and write to filename. Create a private

Create a java class FileHandler that has a parameter constructor that takes 2 strings - a read from and write to filename.


Create a private data member that is a file reading scanner object reference and a file writing Formatter object reference file handle which will be used to read and write text files from disk.


Create private data members that are strings representing names of read and write text files.


Create 2 separate public methods on the FileHandler class one to open a file to read returning Boolean true on success and one for opening a file to write returning Boolean true on success.


Create 2 separate public methods on the FileHandler class, one to write grades to a file given an ArrayList of strings representing grades returning Boolean true on success. The second method should read grades from a file and populate an ArrayList passed to it of strings representing grades. It should also return Boolean true on success.


Write a main function on your FileHandler class and test its functionality by writing test code to check the functionality of the functions you have added to the class.


Part 2

Create a main function and a test program to test your FileHandler class by creating this object. Open a file and write some example grades to it. Close the file. Then, open the file and try to read them back and see if the same data is retrieved from the file as was initially written to it. Also, remember to inspect the text file containing the grades to see if the correct grades are indeed in the file.


Part 3


Create a JavaFX project which builds a GUI called GradeIO which creates a basic GUI AnchorPane container. Make sure to see that the project has a .fxml file and controller class separate from the main app. Double click on the projects .fxml file and it should open Scene Builder for that project.


Add a private reference of type ArrayList of strings (named for example m_ gradesFromFile) to hold any grades read from file which should be instantiated using operator new in the initialize method of the controller class.


Add a private reference of type FileHandler which should be instantiated using operator new in the initialize method of the controller class to be then used for file IO.


Scene Builder Activities

 

Add a label that will display the GPA given a chosen grade named GPALabel.


Add a textbox control that will take input for grade filename to read - place a default string "filename" in it via the properties tab in Scene Builder.


Add a button and label it 'Read Grades File". Add an event handler method named handleReadGrades. Implement the code to use the filehandler object to open a file named (given in the filename textbox you created above) and to fill the private ArrayList of strings container to store the read grades.


As an example for students as a control that can be chosen to display grades - the demo has used a combo box control which is loaded with grades once the grade file is read. Then each selection on the combo box is a grade that was read from the file. Any particular selection of the combo box can then be converted into a grade by clicking the Calculate GPA button. It was chosen as it easily allows the program to know which selection (i.e. grade) the user has selected. (other options are radio buttons as another example).


Add a button and label it "Calculate GPA". Add an event handler method named handleCalcGPA. Write a private method on the JavaFX controller class called convertGradeToGPA which when given a grade (which may be a selected grade from the grade display control above) returns the equivalent GPA in string form. This string can then be used to display into the GPALabel. In this handler, you will need to get the selected grade from the GUIs Grade control (e.g. combo box), call convertGradeToGPA, and display the returned string from that method in that label.



 

Add a button and label it 'OK'. Add an event handler method named handleOKPressed. Implement the code to close the stage component of the application.


Extra Credit: Add a button and label it 'Minimize'. Do the research and find the API to minimize a JavaFX application call it - test your app to see if it works.

Grades GUI Read Grades File Calculate GPA GPA is: - Read file successful c:\\temp\\grades.txt Minimize OK X Grades GUI Read Grades File Calculate GPA GPA is: 3.7 0 Minimize C:\develop\CSC262\CSC6 X OK

Step by Step Solution

3.51 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

The given below is Java Code import javaio import javautil import javafxapplicationApplication import javafxsceneScene import javafxscenecontrolButton import javafxscenecontrolComboBox import javafxsc... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

2. Talk to other teachers or parents about ideas for reinforcers.

Answered: 1 week ago