Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a JavaFX application that lets the user enter the food charge for a meal

ID: 3596784 • Letter: C

Question

Create a JavaFX application that lets the user enter the food charge for a meal at a restaurant. When a button is clicked, the application should calculate and display the amount of an 18 percent tip, 7 percent sales tax, and the total of all three amounts. Include all the java files and fxml files.

This is what I have, but I need the FXML file:

package WordNode;

import java.awt.Button;

import java.util.Scanner;

public class TipTaxTotal { public static void main(String [] args)

{ double charge; double tax = 0.07; double tipRate = 0.18; double totalWithTax;

double taxAmount;

double tipAmount;

double grandTotal;

Scanner keyboard = new Scanner(System.in); //ask for charge from the user

System.out.println("What is the total of your bill? ");

charge = keyboard.nextDouble(); //calculate the charge and the tip

taxAmount = charge * tax;

totalWithTax = charge + taxAmount;

tipAmount = totalWithTax * tipRate;

grandTotal = totalWithTax + tipAmount; //Display it back to the user

System.out.println("Your meal: $" + charge);

System.out.println("Your tax: $" + taxAmount);

System.out.println("Your meal with tax: $" + totalWithTax);

System.out.println("The total cost with the tip included: $" + grandTotal); } }

Here's the sample output:

OUTPUT 49 meal: $49.0 tax: $3.43 meal + tax: $52.43 total cost (tip included) : 561.8674

Explanation / Answer

// TipTaxTotal.java
import java.awt.Button;
import java.util.Scanner;

public class TipTaxTotal {

public static void main(String [] args)
{
double charge;
double tax = 0.07;
double tipRate = 0.18;
double totalWithTax;
double taxAmount;
double tipAmount;
double grandTotal;

Scanner keyboard = new Scanner(System.in);

//ask for charge from the user
System.out.println("What is the charge for your meal?");
charge = keyboard.nextDouble();

//calculate the charge and the tip
taxAmount = charge * tax;
totalWithTax = charge + taxAmount;
tipAmount = totalWithTax * tipRate;
grandTotal = totalWithTax + tipAmount;

//Display it back to the user
System.out.println("meal: $" + charge);
System.out.println("tax: $" + taxAmount);
System.out.println("meal + tax: $" + totalWithTax);
System.out.println("total cost(tip included): $" + grandTotal);


}

}




HTML for above program ,is giving below:

<form id="someIdYouMustGive" action="your method details">

<div class="col-md-2 form-group">
                                                    <label class="control-label">Food Charge:</label> <input
                                                        type="text" class="form-control"
                                                        placeholder="Enter The Charge" autocomplete="off"
                                                        name="foodCharge" id="foodCharge">
                                                </div>

<div class="col-md-2 form-group">
                                                    <label class="control-label">Tip:</label> <input
                                                        type="text" class="form-control">
                                                </div>

<div class="col-md-2 form-group">
                                                    <label class="control-label">Sales Tax:</label> <input
                                                        type="text" class="form-control">
                                                </div>

<div class="col-md-2 form-group">
                                                    <label class="control-label">Total Amount:</label> <input
                                                        type="text" class="form-control">
                                                </div>

<div class="modal-footer">
<button type="submit" class="btn btn-success"
id="submit">
<i class="fa fa-save"></i>&nbsp;&nbsp;Save
</button>
</div>

</form>

Explanation:

Starting I have given the form tag and in that form tag I have given the method details in action attribute and the form tag is ended in the last.In between <form> start tag and </form> end tag, I have given the labels and input field for all the three fields. I have given like which you askeed as food charge,tip,sales tax and total of all the three after entering the values like food charge you can get the calculation of all those which you asked and the calculation part written by you.This is for web page design for the sheet which you asked in HTML code.

Now how to connect to java:

You can incorporate in java by setting path like :

In this way the screen and incorporating in java.