Question: Here is the Java Code I have so far: import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.

Here is the Java Code I have so far:
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.sql.*;
public class BabyNames extends Application {
Statement stmt;
public void start(Stage primaryStage) throws SQLException, ClassNotFoundException {
//initializeDB();
BorderPane bp = new BorderPane();
RadioButton boy = new RadioButton("Boy");
RadioButton girl = new RadioButton("Girl");
RadioButton either = new RadioButton("Both");
ToggleGroup genderGroup = new ToggleGroup();
boy.setToggleGroup(genderGroup);
girl.setToggleGroup(genderGroup);
either.setToggleGroup(genderGroup);
VBox gender = new VBox(3);
gender.setPadding(new Insets(5,5,5,5));
// gender.setStyle("=fx-border-width: 2px; -fx-border-color: green");
gender.getChildren().addAll(boy, girl, either);
bp.setTop(gender);
TextArea taResults = new TextArea();
ScrollPane sp = new ScrollPane(taResults);
Label results = new Label("Results");
BorderPane resultPane = new BorderPane();
resultPane.setTop(results);
resultPane.setBottom(sp);
bp.setBottom(resultPane);
BorderPane masterPane = new BorderPane();
masterPane.setCenter(bp);
ComboBox letter = new ComboBox >();
letter.setPrefWidth(200);
Button search = new Button("Search");
BorderPane fl = new BorderPane();
fl.setCenter(letter);
fl.setTop(new Label("Starts with..."));
fl.setBottom(search);
String[] alphabet={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
"R","S","T","U","V","W","X","Y","Z"};
ObservableList items = FXCollections.observableArrayList(alphabet);
letter.getItems().addAll(items);
BorderPane yearList = new BorderPane();
ComboBox yearDropDown = new ComboBox >();
yearDropDown.setPrefWidth(200);
String[] yr ={"2001","2002","2003","2004","2005","2006","2007","2008","2009","2010"};
ObservableList yritems = FXCollections.observableArrayList(yr);
yearDropDown.getItems().addAll(yr);
yearList.setCenter(yearDropDown);
yearList.setTop(new Label("Year or interest"));
yearList.setBottom(search);
VBox vb = new VBox();
vb.getChildren().addAll(fl, yearList);
bp.setCenter(vb);
Scene scene = new Scene(masterPane,200,400);
primaryStage.setTitle("Baby Name Widget");
primaryStage.setScene(scene);
primaryStage.show();
//event handling
EventHandler eventHandler = e->{
taResults.clear();
char c = letter.getValue().charAt(0); //letter selected in drop down box.
int y = Integer.parseInt(yearDropDown.getValue());
String queryString = null;
if (boy.isSelected()){
System.out.println("boy selected" + c);
char g ='M';
//#1 queryString is set to string that is mysql statement to
//find all boys in y with names that start with c
}
else if (girl.isSelected()){
System.out.println("Girl selected");
//#2 queryString is set to string that is mysql statement to
//find all girls in y with names that start with c
}
else{
//#3 queryString is set to string that is mysql statement to
//find all boys and girls in y with names that start with c
System.out.println("Either");
}
// try {//#4
int rcount =0;
//display the list of names in taResults
System.out.println("row count" + rcount); //this is just to check that displayed number of rows returned
//} catch (SQLException ex){
// ex.printStackTrace();
//}
};
search.setOnAction(eventHandler); //associate event handling on the search button.
}//end start
private void makeQuery(){
}
public void initializeDB() throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Driver loaded");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost/babynames", "root", "root");
stmt = connection.createStatement();
}
public static void main(String[] args){
launch(args);
}
} A. The script, Babynames.sql has been provided in the HW5 project. Run the script in workbench or other method of your choice to create the database babynames.
There is a similar page for years 2002 through 2010. You will need to read in the data and update your database for each of the 10 years. In BabyNamesPopulateDB the for loop goes thru the years, and the while loop takes care of reading in the names for a particular year, based on the loop invariant year.
After you have read in your data, go to workbench and make sure it looks like it was read correctly.
C. GUI query application can be found in BabyNames. You should be able to run the skeleton file to see the GUI and do not need to add anything to the GUI. If you would like to improve the GUI or create your own from scratch, you are welcome to do that. The functionality should be the same. It should look something like this: D. Your next task is to write the generic query string in \#1-\#3 and then to complete the display of
Here is the Java Code I have so far: import

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!