Question: **JAVA PROGRAMMING** I created this with JavaFX in Eclipse. I am trying to make this invoice input a date in the textField_date when the total
**JAVA PROGRAMMING**
I created this with JavaFX in Eclipse. I am trying to make this invoice input a date in the textField_date when the total button is clicked. I would like to create a GetTax in the Parent Class. Before I started trying to put the date information in this everything else works properly. I cant figure out how to do this. I would also like to see a UML for this program, I built it but now I am confused. Thanks! I appreciate all the help I have received so far, I need to get this finished as soon as possible.
package application;
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.*;
import javafx.scene.layout.*;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class Invoice extends Application {
private TextField textField_haircut;
private TextField textField_trim;
private TextField textField_beardtrim;
private TextField textField_single;
private TextField textField_highlights;
private TextField textField_retouch;
private TextField textField_scalp;
private TextField textField_protein;
private TextField textField_cost_cuts;
private TextField textField_cost_color;
private TextField textField_cost_condition;
private TextField textField_Tax;
private TextField textField_Subtotal;
private TextField textField_Total;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Heather's Hair Care Invoice");
//create invoice form pane
GridPane gridPane = createInvoiceFormPane();
//add UI controls
addUIControls(gridPane);
//create a scene with the invoice form gridPane as the root node
Scene scene = new Scene(gridPane, 800, 600);
//set scene in primary stage
primaryStage.setScene(scene);
primaryStage.show();
}
private GridPane createInvoiceFormPane() {
//new Grid Pane
GridPane gridPane = new GridPane();
//Position the pane
gridPane.setAlignment(Pos.TOP_LEFT);
//set Padding
gridPane.setPadding(new Insets(20, 20, 20, 20));
//set horizontal gap between columns
gridPane.setHgap(10);
//set vertical gap between rows
gridPane.setVgap(10);
gridPane.setBackground(new Background(new BackgroundFill(Color.MINTCREAM, CornerRadii.EMPTY, Insets.EMPTY)));
//Column One Constraints
ColumnConstraints columnOneConstraints = new ColumnConstraints(100, 100, Double.MAX_VALUE);
columnOneConstraints.setPercentWidth(20);
//Column Two Constraints
ColumnConstraints columnTwoConstraints = new ColumnConstraints(100, 100, Double.MAX_VALUE);
columnTwoConstraints.setPercentWidth(15);
//Column Three Constraints
ColumnConstraints columnThreeConstraints = new ColumnConstraints(100, 100, Double.MAX_VALUE);
columnThreeConstraints.setPercentWidth(20);
//Column Four Constraints
ColumnConstraints columnFourConstraints = new ColumnConstraints(100, 100, Double.MAX_VALUE);
columnFourConstraints.setPercentWidth(15);
gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstraints, columnThreeConstraints, columnFourConstraints);
return gridPane;
}
private void addUIControls(GridPane gridPane) {
//Header
Label headerLabel = new Label("Hair Care Invoice");
headerLabel.setFont(Font.font("Arial", FontWeight.BOLD, 24));
gridPane.add(headerLabel, 0,0,2,1);
GridPane.setHalignment(headerLabel, HPos.LEFT);
GridPane.setMargin(headerLabel, new Insets(20,0,20,0));
//Add haircut label
Label cutsLabel = new Label("CUTS & TRIMS");
cutsLabel.setFont(Font.font(null, FontWeight.BOLD, 18));
gridPane.add(cutsLabel, 0, 2);
//Add haircut label
Label haircutLabel = new Label("Haircut");
gridPane.add(haircutLabel, 0, 3);
//add first haircut text field
TextField textField_haircut = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_haircut.setPrefHeight(20);
textField_haircut.setText("0");
textField_haircut.setPrefWidth(20);
gridPane.add(textField_haircut, 1, 3);
//Add trim label
Label trimLabel = new Label("Trim");
gridPane.add(trimLabel, 0, 4);
//add trim text field
TextField textField_trim = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_trim.setPrefHeight(20);
textField_trim.setText("0");
gridPane.add(textField_trim, 1, 4);
//Add beard trim label
Label beardtrimLabel = new Label("Beard Trim");
gridPane.add(beardtrimLabel, 0, 5);
//add beard trim text field
TextField textField_beardtrim = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_beardtrim.setPrefHeight(20);
textField_beardtrim.setText("0");
gridPane.add(textField_beardtrim, 1, 5);
//Add CONDITIONING label
Label conditionLabel = new Label("CONDITIONING");
conditionLabel.setFont(Font.font(null, FontWeight.BOLD, 18));
gridPane.add(conditionLabel, 0, 6);
//Add scalp treatment label
Label scalpLabel = new Label("Scalp Treatment");
gridPane.add(scalpLabel, 0, 7);
//add scalp treatment text field
TextField textField_scalp = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_scalp.setPrefHeight(20);
textField_scalp.setText("0");
gridPane.add(textField_scalp, 1, 7);
//Add protein treatment label
Label proteinLabel = new Label("Protein Treatment");
gridPane.add(proteinLabel, 0, 8);
//add protein treatment text field
TextField textField_protein = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_protein.setPrefHeight(20);
textField_protein.setText("0");
gridPane.add(textField_protein, 1, 8);
//Add COLOR label
Label colorLabel = new Label("COLOR");
colorLabel.setFont(Font.font(null, FontWeight.BOLD, 18));
gridPane.add(colorLabel, 0, 9);
//Add single process label
Label singleLabel = new Label("Single Process");
gridPane.add(singleLabel, 0, 10);
//add single process text field
TextField textField_single = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_single.setPrefHeight(20);
textField_single.setText("0");
gridPane.add(textField_single, 1, 10);
//Add highlights/lowlights label
Label highlightsLabel = new Label("Highlights/Lowlights");
gridPane.add(highlightsLabel, 0, 11);
//add highlights/lowlights field
TextField textField_highlights = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_highlights.setPrefHeight(20);
textField_highlights.setText("0");
gridPane.add(textField_highlights, 1, 11);
//Add retouch label
Label retouchLabel = new Label("Retouch");
gridPane.add(retouchLabel, 0, 12);
//add retouch text field
TextField textField_retouch = new TextField() {
//Numbers only
@Override
public void replaceText(int start, int end, String text)
{
if (text.matches("[0-9]*"))
{
super.replaceText(start, end, text);
}
}
@Override
public void replaceSelection(String text)
{
if (text.matches("[0-9]*"))
{
super.replaceSelection(text);
}
}
};
textField_retouch.setPrefHeight(20);
textField_retouch.setText("0");
gridPane.add(textField_retouch, 1, 12);
//Date
Label dateLabel = new Label("DATE");
dateLabel.setFont(Font.font(null, FontWeight.BOLD, 14));
gridPane.add(dateLabel, 3, 1);
//add first cost of cuts text field
TextField textField_date = new TextField();
textField_date.setPrefHeight(20);
gridPane.add(textField_date, 4, 1);
//Add COST OF CUTS label
Label cost_of_cutsLabel = new Label("CUTS & TRIMS");
cost_of_cutsLabel.setFont(Font.font(null, FontWeight.BOLD, 14));
gridPane.add(cost_of_cutsLabel, 3, 3);
//add first cost of cuts text field
TextField textField_cost_cuts = new TextField();
textField_cost_cuts.setPrefHeight(20);
gridPane.add(textField_cost_cuts, 4, 3);
//Add COST OF CONDITION label
Label cost_of_conditionLabel = new Label("CONDITIONING");
cost_of_conditionLabel.setFont(Font.font(null, FontWeight.BOLD, 14));
gridPane.add(cost_of_conditionLabel, 3, 4);
//add first cost of condition text field
TextField textField_cost_condition = new TextField();
textField_cost_condition.setPrefHeight(20);
gridPane.add(textField_cost_condition, 4, 4);
//Add COST OF COLOR label
Label cost_of_colorLabel = new Label("COLOR");
cost_of_colorLabel.setFont(Font.font(null, FontWeight.BOLD, 14));
gridPane.add(cost_of_colorLabel, 3, 5);
//add first cost of color text field
TextField textField_cost_color = new TextField();
textField_cost_color.setPrefHeight(20);
gridPane.add(textField_cost_color, 4, 5);
//Add subtotal label
Label subtotalLabel = new Label("SUBTOTAL");
subtotalLabel.setFont(Font.font(null, FontWeight.BOLD, 20));
gridPane.add(subtotalLabel, 3, 7);
//add first Subtotal text field
TextField textField_Subtotal = new TextField();
textField_Subtotal.setPrefHeight(20);
gridPane.add(textField_Subtotal, 4, 7);
//Add tax label
Label taxLabel = new Label("TAX");
taxLabel.setFont(Font.font(null, FontWeight.BOLD, 20));
gridPane.add(taxLabel, 3, 8);
//add first Tax text field
TextField textField_Tax = new TextField();
textField_Tax.setPrefHeight(20);
gridPane.add(textField_Tax, 4, 8);
//Add total label
Label totalLabel = new Label("TOTAL");
totalLabel.setFont(Font.font(null, FontWeight.BOLD, 20));
gridPane.add(totalLabel, 3, 9);
//add Tax text field
TextField textField_Total = new TextField();
textField_Total.setPrefHeight(20);
gridPane.add(textField_Total, 4, 9);
// Add Total Button
Button btnTotal = new Button("TOTAL");
btnTotal.setPrefHeight(40);
btnTotal.setDefaultButton(true);
btnTotal.setPrefWidth(100);
btnTotal.setFont(Font.font(null, FontWeight.BOLD, 20));
gridPane.add(btnTotal, 3, 11, 2, 1);
//set onAction for Total button
btnTotal.setOnAction(new EventHandler()
{
@Override
public void handle(ActionEvent event)
{
Child cost_of_services = new Child();
double iTax, iSubtotal, iTotal;
cost_of_services.Haircut = cost_of_services.pHaircut * Double.parseDouble(textField_haircut.getText());
cost_of_services.Trim = cost_of_services.pTrim * Double.parseDouble(textField_trim.getText());
cost_of_services.Beardtrim = cost_of_services.pBeardtrim * Double.parseDouble(textField_beardtrim.getText());
cost_of_services.Single = cost_of_services.pSingle * Double.parseDouble(textField_single.getText());
cost_of_services.Highlights = cost_of_services.pHighlights * Double.parseDouble(textField_highlights.getText());
cost_of_services.Retouch = cost_of_services.pRetouch * Double.parseDouble(textField_retouch.getText());
cost_of_services.Scalp = cost_of_services.pScalp * Double.parseDouble(textField_scalp.getText());
cost_of_services.Protein = cost_of_services.pProtein * Double.parseDouble(textField_protein.getText());
iSubtotal = cost_of_services.GetAmount();
iTax = cost_of_services.GetTax();
iTotal = iSubtotal + iTax;
String Subtotal = String.format("$%.2f", iSubtotal);
textField_Subtotal.setText(Subtotal);
String Tax = String.format("$%.2f", iTax);
textField_Tax.setText(Tax);
String Total = String.format("$%.2f", iTotal);
textField_Total.setText(Total);
//Set Text
String iCuts = String.format("$%.2f", cost_of_services.servicescost1);
textField_cost_cuts.setText(iCuts);
String iColor = String.format("$%.2f", cost_of_services.servicescost2);
textField_cost_color.setText(iColor);
String iCondition = String.format("$%.2f", cost_of_services.servicescost3);
textField_cost_condition.setText(iCondition);
String iDate = String.format("%02d/%02d/%04d", iDate);
textField_date.setText(iDate);
}
});
// Add Reset Button
Button btnReset = new Button("RESET");
btnReset.setPrefHeight(40);
btnReset.setDefaultButton(true);
btnReset.setPrefWidth(100);
btnReset.setFont(Font.font(null, FontWeight.BOLD, 20));
gridPane.add(btnReset, 4, 11, 2, 1);
//set on Action for the reset button
btnReset.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event)
{
textField_haircut.setText("0");
textField_trim.setText("0");
textField_beardtrim.setText("0");
textField_single.setText("0");
textField_highlights.setText("0");
textField_retouch.setText("0");
textField_scalp.setText("0");
textField_protein.setText("0");
textField_cost_cuts.setText(null);
textField_cost_color.setText(null);
textField_cost_condition.setText(null);
textField_Tax.setText(null);
textField_Subtotal.setText(null);
textField_Total.setText(null);
}
});
}
}
PARENT CLASS
package application;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Parent {
//Data types
public double Haircut;
public double Trim;
public double Beardtrim;
public double Single;
public double Highlights;
public double Retouch;
public double Scalp;
public double Protein;
public double pHaircut = 20.00;
public double pTrim = 15.00;
public double pBeardtrim = 8.00;
public double pSingle = 50.00;
public double pHighlights = 65.00;
public double pRetouch = 40.00;
public double pScalp = 15.00;
public double pProtein = 20.00;
public double servicescost1;
public double servicescost2;
public double servicescost3;
public double servicescost;
public double TaxCost;
//Calculates get Amount for each service category
public double GetAmount() {
servicescost1 = Haircut + Trim + Beardtrim;
servicescost2 = Single + Highlights + Retouch;
servicescost3 = Scalp + Protein;
servicescost = servicescost1 + servicescost2 + servicescost3;
return(servicescost);
}
//calculate tax for 7% tax
public double mcTax = .07;
public Double cFindTax(double cAmount) {
double FindTax = cAmount* mcTax;
return(FindTax);
}
//calculate tax
public double GetTax() {
TaxCost = cFindTax(servicescost);
return (TaxCost);
}
Date idate = new Date();
SimpleDateFormat dateForm = new SimpleDateFormat("MM/dd/Y");
}
CHILD CLASS
package application;
public class Child extends Parent{
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
