(Solved) : M Confused Code Final Grades Letter Grades Would Helpful Explain Understand Better Thank Q29605884 . . .
I’m confused how to code the Final Grades and Letter Grades? Itwould be very helpful to explain how I do this to understand itbetter. Thank you.
Use setField()s method to calculate Final Grade and Letter Gradeof 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 methodsto keep code neat and clean.
Final Grade = (average of 3 quiz grades converted to 100 ptscale * .30) + (midterm grade * .35) + (final * .35) rounded withMath.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<String> fileRecords;
//Instance (Attribute) Variables forApplication Object
private String Fields;
private Node mainTitle;
private NodeCustomPane;
@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 nError was: +e”);
}
//Create border pane
BorderPane mainBorderPane = new BorderPane();
mainBorderPane.setBottom(getHBox());
mainBorderPane.setTop(new CustomPane(“Project Calculate StudentGrades”));
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 anHBox Bottom Centered
private HBox getHBox() {
HBox hBox = newHBox(10);
hBox.setAlignment(Pos.BOTTOM_CENTER);
hBox.setPadding(newInsets(10, 10, 30, 10));
Button butFirst = newButton(“|<-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 = newButton(“Next->”);
butNext.setStyle(“-fx-background-color: orange”);
butNext.setId(“NextButton”);
butNext.setOnAction(e-> {
defineActionEvent(“NextButton”);
});
hBox.getChildren().add(butNext);
Button butLast = newButton(“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(newLabel (“Course:”), col = 0, row = 0);
formPane.add(tfCourse, col = 1, row = 0);
formPane.add(newLabel (“Last Name:”), col = 0, row = 1);
formPane.add(tfLastName, col = 1, row = 1);
formPane.add(newLabel (“First Name:”), col = 0, row = 2);
formPane.add(tfFirstName, col = 1, row = 2);
formPane.add(newLabel (“Quiz 1:”), col = 0, row = 3);
formPane.add(tfQuiz1,col = 1, row = 3);
formPane.add(newLabel (“Quiz 2:”), col = 0, row = 4);
formPane.add(tfQuiz2,col = 1, row = 4);
formPane.add(newLabel (“Quiz 3:”), col = 0, row = 5);
formPane.add(tfQuiz3,col = 1, row = 5);
formPane.add(newLabel (“Midterm:”), col = 0, row = 6);
formPane.add(tfMidterm, col = 1, row = 6);
formPane.add(newLabel (“Final:”), col = 0, row = 7);
formPane.add(tfFinal,col = 1, row = 7);
formPane.add(newLabel (“Final Grade:”), col = 0, row = 8);
formPane.add(tfFinalGrade, col = 1, row = 8);
formPane.add(newLabel (“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 {
publicCustomPane(String mainTitle) {
getChildren().add(new Label(mainTitle));
setPadding(new Insets(10, 10, 10, 10));
setAlignment(Pos.CENTER);
}
}
//Process events
public ProjectCalculate()
{
tfCourse = newTextField();
tfLastName = newTextField();
tfFirstName = newTextField();
tfQuiz1 = newTextField();
tfQuiz2 = newTextField();
tfQuiz3 = newTextField();
tfMidterm = newTextField();
tfFinal = newTextField();
tfFinalGrade = newTextField();
tfLetterGrade = newTextField();
lblRecordNumber = newLabel();
currentRecordIndex =0;
} //Project03 Constructor
//private EventHandler<ActionEvent>defineActionEvent(final String forNode)
private void defineActionEvent(StringforNode) {
{
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<String> getRecords()throws Exception
{
ArrayList<String> theRecords = new ArrayList<>();
ScannerinputFile;
inputFile = newScanner(new File(“studentgrades.txt”));
while(inputFile.hasNextLine())
{
theRecords.add(inputFile.nextLine());
}
returntheRecords;
}
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 linearguments
*/
public static void main(String[] args) {
launch(args);
}
}
Expert Answer
Answer to M Confused Code Final Grades Letter Grades Would Helpful Explain Understand Better Thank Q29605884 . . .
OR