Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im confused how to code the Final Grades and Letter Grades? It would be very helpful to explain how I do this to understand it

Im confused how to code the Final Grades and Letter Grades? It would be very helpful to explain how I do this to understand it better. Thank you.

Use setField()s method to calculate Final Grade and Letter Grade of the Final Grade. I have to convert String values to Double.parseDouble(fields[3]). Quizzes are indexes 3, 4, 5. Midterm is index 6. Final Grade is index 7. Call additional methods to keep code neat and clean.

Final Grade = (average of 3 quiz grades converted to 100 pt scale * .30) + (midterm grade * .35) + (final * .35) rounded with Math.round()

Letter Grade use a multiway statement.

A = 90 or above B+ = 85-89 B = 80-84 C+ = 75-79 C = 70-74 D+ = 65-69 D = 60-64 F = all other grade value

Must convert the calculated Final Grade to String such as tfFinalGrade.setText(String.valueOf(finalGrade));

SOURCE CODE:

package projectcalculate;

import java.io.File; import java.util.ArrayList; import java.util.Scanner; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import java.io.File; import java.io.FileNotFoundException; import java.util.*; import java.io.FileReader; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import static javafx.application.Application.launch; import javafx.scene.Node; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.Font;

public class ProjectCalculate extends Application {

private TextField tfCourse; private TextField tfLastName; private TextField tfFirstName; private TextField tfQuiz1; private TextField tfQuiz2; private TextField tfQuiz3; private TextField tfMidterm; private TextField tfFinal; private TextField tfFinalGrade; private TextField tfLetterGrade; private Label lblRecordNumber; private int currentRecordIndex; private TextField input; private Label output; private ArrayList fileRecords;

//Instance (Attribute) Variables for Application Object private String Fields; private Node mainTitle; private Node CustomPane;

@Override

public void start(Stage primaryStage)

{

int top, right, bottom, left;

String[] fields;

String Insets;

try

{

java.io.File file = new java.io.File("studentgrades.txt");

Scanner input = new Scanner(file);

fileRecords = getRecords();

setFields(0);

}

catch (Exception e) {

System.out.println("Error! Problem opening file Error was: + e");

}

//Create border pane

BorderPane mainBorderPane = new BorderPane();

mainBorderPane.setBottom(getHBox());

mainBorderPane.setTop(new CustomPane("Project Calculate Student Grades"));

mainBorderPane.setCenter(getFieldsGridPane());

Scene mainScene = new Scene(mainBorderPane, 700, 500);

mainBorderPane.setPadding(new Insets(10, 10, 10, 40));

primaryStage.setTitle("Student Grade Record");

primaryStage.setScene(mainScene);

primaryStage.show();

}

//First, Previous, Next, Last Buttons in an HBox Bottom Centered

private HBox getHBox() {

HBox hBox = new HBox(10);

hBox.setAlignment(Pos.BOTTOM_CENTER);

hBox.setPadding(new Insets(10, 10, 30, 10));

Button butFirst = new Button("|<-First");

butFirst.setStyle("-fx-background-color: yellow");

butFirst.setId("FirstButton");

butFirst.setOnAction(e-> {

defineActionEvent("FirstButton");

});

hBox.getChildren() .add(butFirst);

Button butPrevious = new Button("<-Previous");

butPrevious.setId("PreviousButton");

butPrevious.setStyle("-fx-background-color: orange");

butPrevious.setOnAction(e-> {

defineActionEvent("PreviousButton");

});

hBox.getChildren() .add(butPrevious);

Button butNext = new Button("Next->");

butNext.setStyle("-fx-background-color: orange");

butNext.setId("NextButton");

butNext.setOnAction(e-> {

defineActionEvent("NextButton");

});

hBox.getChildren() .add(butNext);

Button butLast = new Button("Last->|");

butLast.setStyle("-fx-background-color: yellow");

butLast.setId("LastButton");

butLast.setOnAction(e-> {

defineActionEvent("LastButton");

});

hBox.getChildren() .add(butLast);

GridPane.setHalignment(butPrevious, HPos.LEFT);

GridPane.setHalignment(butNext, HPos.RIGHT);

return hBox;

}

private GridPane getFieldsGridPane() {

GridPane formPane = new GridPane();

formPane.setHgap(5);

formPane.setVgap(5);

formPane.setPadding(new Insets(25, 10, 10, 10));

int col = 0, row = 0;

formPane.add(new Label ("Course:"), col = 0, row = 0);

formPane.add(tfCourse, col = 1, row = 0);

formPane.add(new Label ("Last Name:"), col = 0, row = 1);

formPane.add(tfLastName, col = 1, row = 1);

formPane.add(new Label ("First Name:"), col = 0, row = 2);

formPane.add(tfFirstName, col = 1, row = 2);

formPane.add(new Label ("Quiz 1:"), col = 0, row = 3);

formPane.add(tfQuiz1, col = 1, row = 3);

formPane.add(new Label ("Quiz 2:"), col = 0, row = 4);

formPane.add(tfQuiz2, col = 1, row = 4);

formPane.add(new Label ("Quiz 3:"), col = 0, row = 5);

formPane.add(tfQuiz3, col = 1, row = 5);

formPane.add(new Label ("Midterm:"), col = 0, row = 6);

formPane.add(tfMidterm, col = 1, row = 6);

formPane.add(new Label ("Final:"), col = 0, row = 7);

formPane.add(tfFinal, col = 1, row = 7);

formPane.add(new Label ("Final Grade:"), col = 0, row = 8);

formPane.add(tfFinalGrade, col = 1, row = 8);

formPane.add(new Label ("Letter Grade:"), col = 0, row = 9);

formPane.add(tfLetterGrade, col = 1, row = 9);

formPane.add(lblRecordNumber, col = 1, col = 11);

formPane.setHalignment(lblRecordNumber, HPos.RIGHT);

return formPane;

}

class CustomPane extends StackPane {

public CustomPane(String mainTitle) {

getChildren().add(new Label(mainTitle));

setPadding(new Insets(10, 10, 10, 10));

setAlignment(Pos.CENTER);

}

}

//Process events

public ProjectCalculate()

{

tfCourse = new TextField();

tfLastName = new TextField();

tfFirstName = new TextField();

tfQuiz1 = new TextField();

tfQuiz2 = new TextField();

tfQuiz3 = new TextField();

tfMidterm = new TextField();

tfFinal = new TextField();

tfFinalGrade = new TextField();

tfLetterGrade = new TextField();

lblRecordNumber = new Label();

currentRecordIndex = 0;

} //Project03 Constructor

//private EventHandler defineActionEvent(final String forNode)

private void defineActionEvent(String forNode) {

{

System.out.println("Action Event for: "+forNode);

System.out.println("Current Record Index: "+currentRecordIndex);

switch (forNode)

{

case "FirstButton":

if (currentRecordIndex > 0)

{

currentRecordIndex = 0;

setFields(currentRecordIndex);

}

else

{

System.out.println("Reached BEGINNING of Records.");

}

break;

case "PreviousButton":

if (currentRecordIndex > 0)

{

currentRecordIndex--;

setFields(currentRecordIndex);

}

else

{

System.out.println("Reached FIRST Record.");

}

break;

case "NextButton":

if (currentRecordIndex < (fileRecords.size() -1))

{

currentRecordIndex++;

setFields(currentRecordIndex);

}

else

{

System.out.println("Reached LAST Record.");

}

break;

case "LastButton":

if (currentRecordIndex < (fileRecords.size() -1))

{

currentRecordIndex = fileRecords.size() -1;

setFields(currentRecordIndex);

}

else

{

System.out.println("Reached END of Records.");

}

break;

default:

System.out.println("Error. Undefined object.");

break;

}

}

}

private ArrayList getRecords() throws Exception

{

ArrayList theRecords = new ArrayList<>();

Scanner inputFile;

inputFile = new Scanner(new File("studentgrades.txt"));

while(inputFile.hasNextLine())

{

theRecords.add(inputFile.nextLine());

}

return theRecords;

}

private void setFields(int theIndex)

{

String[] fields = fileRecords.get(theIndex).split(",");

tfCourse.setText(fields[0]);

tfLastName.setText(fields[1]);

tfFirstName.setText(fields[2]);

tfQuiz1.setText(fields[3]);

tfQuiz2.setText(fields[4]);

tfQuiz3.setText(fields[5]);

tfMidterm.setText(fields[6]);

tfFinal.setText(fields[7]);

lblRecordNumber.setText(String.format("Record #%3d",

theIndex));

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

launch(args);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

explain what is meant by experiential learning

Answered: 1 week ago

Question

identify the main ways in which you learn

Answered: 1 week ago