I am really in need of help on this Java programming challenge. Thank you in adv
ID: 3767574 • Letter: I
Question
I am really in need of help on this Java programming challenge. Thank you in advance for your help :)
Please help me with the following programming challenge for JavaFx:
Name Formatter
Create a JavaFX application that lets the user enter the following pieces of data:
*The user's first name
*The user's middle name
*The user's last name
*The user's prefered title (Mr., Mrs, Ms.,Dr., etc.)
Assume the user has entered the following data:
*First name: Kelly
*Middle name: Jane
*Last name: Smith
*Title: Ms.
The application should have the buttons that display the user's name formatted in the following ways:
Ms. Kelly Jane Smith
Kelly Jane Smith
Kelly Smith
Smith, Kelly Jane, Ms.,
Smith, Kelly Jane
Smith, Kelly
Explanation / Answer
PROGRAM : import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { private final TableView table = new TableView(); private final ObservableList data = FXCollections.observableArrayList(new Person("A", "B")); final HBox hb = new HBox(); public static void main(String[] args) { launch(args); } public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setWidth(450); stage.setHeight(550); TableColumn firstNameCol = new TableColumn("First Name"); firstNameCol.setMinWidth(100); firstNameCol.setCellValueFactory( new PropertyValueFactory("firstName")); TableColumn middleNameCol = new TableColumn("middle Name"); middleNameCol.setMinWidth(100); middleNameCol.setCellValueFactory( new PropertyValueFactory("middleName"); TableColumn lastNameCol = new TableColumn("Last Name"); lastNameCol.setMinWidth(100); lastNameCol.setCellValueFactory( new PropertyValueFactory("lastName")); table.setItems(data); table.getColumns().addAll(firstNameCol,middleName,lastNameCol); final Button addButton = new Button("Add"); addButton.setOnAction((ActionEvent e) -> { data.add(new Person("Z","X")); }); hb.getChildren().addAll(addButton); hb.setSpacing(3); final VBox vbox = new VBox(); vbox.setSpacing(5); vbox.setPadding(new Insets(10, 0, 0, 10)); vbox.getChildren().addAll(table, hb); ((Group) scene.getRoot()).getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } public static class Person { private final SimpleStringProperty firstName; private final SimpleStringProerty middleName; private final SimpleStringProperty lastName; private Person(String fName,String Mname,String lName) { this.firstName=new SimpleStringProperty(fName) this.middleName = new SimpleStringProperty(MName); this.lastName = new SimpleStringProperty(lName); } public String getFirstName() { return firstName.get(); } public void setFirstName(String fName) { firstName.set(fName); } public String getMiddlename() { return middleName.get(); } public void setMiddleName(String mName) { middleName.set(mName); } public String getLastName() { return lastName.get(); } public void setLastName(String lName) { lastName.set(lName); } } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.