Using Java Fx and OOPS concepts learned in your class, code the Assignment 2 in
ID: 3920351 • Letter: U
Question
Using Java Fx and OOPS concepts learned in your class, code the Assignment 2 in Java FX. The application Pizzashop will have all the choices for regular and feast pizza.
1. In the first scene, ask name, type and size of pizza and let the user add toppings.
2. Once the user clicks a button in scene1, it takes him to page 2 where the user sees his order details and a choice to choose his payment.(use radiobutton here)
3. For debit and credit payment show a hyperlink window which takes the user to the respective payment sites, ex interac for debit., paypal for credit. and an image of cash for cash option.
It’s a JavaFX programming assignment.
Code needed
Explanation / Answer
SOLUTION:
According to the given data the below JAVA code follows;
CODE:
import java.text.DecimalFormat;
import java.util.Scanner;
public class pizzaorder{
public static void main(String[] args){
DecimalFormat df = new DecimalFormat("#.####");
Scanner keyboard = new Scanner(System.in);
// Variables
String Cust_Name; // Customer’s name
char Pizza_Type;
String Pizza_Type_Name; // name of Pizza Type
char Payment_Method; //payment method
string payment_Method_Name;//payment method name
int size; // size of pizza
double price = 0.0; // cost of pizza
final double Tax_perc = 5; // rate of tax in %
double tax; // amount of tax
double total_Pizza; // total price of pizza+ toppings(if any)
double GrandTotal; // total of everything
int numberOfToppings1 = 0;
int numberOfToppings2 =0;
int numberOfToppings3;
String toppings = "Pepperoni";
System.out.println("Enter your name: " );
Cust_Name = keyboard.nextLine();
// Prompts for pizza size
System.out.print("What size of pizza would you like (diameter in inches)? (8, 10, 12, 14, or 16) " );
size = keyboard.nextInt();
if (size == 8 ){
price = 9.0000; }
else if (size == 10){
price = 10.0000;}
else if (size == 12){
price = 12.0000;}
else if (size == 14){
price = 14.0000;}
else if (size == 16){
price = 16.0000;}
else if (size != 8 && size != 10 && size != 12 && size != 14 && size != 16){
System.out.println("The value that you have entered is invalid. You will be offered default pizza size of 8 inches " );
price = 9;}
keyboard.nextLine();
// Prompts user for type of pizza
System.out.print("What type of pizza do you want? (RH)Regular-hand tossed, (RT)Regular -Thin-crust, or (F)Feast (enter RH, RT, or F,): " );
Pizza_Type = keyboard.nextLine().charAt(0);
if (Pizza_Type == 'RH' || Pizza_Type == 'rh' ){
Pizza_Type_Name = "Regular & Hand-Tossed";}
else if (Pizza_Type == 'RT' || Pizza_Type == 'rt' ){
Pizza_Type_Name = "Regular &Thin-Crust";}
else if (Pizza_Type == 'F' || Pizza_Type == 'f' ){
Pizza_Type_Name = "Feast & Deep-Dish";}
else if (Pizza_Type != 'RH' && Pizza_Type != 'rh' && Pizza_Type != 'RT' && Pizza_Type != 'rt' && Pizza_Type != 'F' && Pizza_Type != 'f' ){
System.out.println("The pizza type you have entered is invalid. You will be offered Regular – Hand tossed pizza . " );}
Pizza_Type_Name = "Regular & Hand-Tossed";
// Prompts user for more toppings
System.out.println("Our Pizzas have Pepperoni as default topping." );
System.out.println("If you want additional toppings you can , choose from Mushroom (2$) or Sausage(2$)." );
// Mushroom
System.out.println("Do you want Mushroom? (Y/N)" );
numberOfToppings 1= keyboard.nextLine().charAt(0);
if (numberOfToppings1 == 'Y' || numberOfToppings1 == 'y' ){
numberOfToppings1 = 1;
toppings = toppings + " and Mushroom";}
else{
numberOfToppings1 = 0;
}
//Sausage
System.out.println("Do you want Sausage? (Y/N)" );
numberOfToppings2 = keyboard.nextLine().charAt(0);
if (numberOfToppings2 == 'Y' || numberOfToppings2 == 'y' ){
numberOfToppings2 = 1;
toppings = toppings + " and Sausage";}
else{
numberOfToppings2 = 0;}
numberOfToppings3 = (numberOfToppings1) + (numberOfToppings2);
// Calculations for pizza price
total_Pizza= (price) + (numberOfToppings3 * 2) ;
tax = total_Pizza * (Tax_perc/100);
GrandTotal = total_Pizza * ( 1 + (Tax_perc/100) );
// order and payment Confirmation
System.out.println(firstName + ", here are the details of your order:");
System.out.println(size + " inch pizza");
System.out.println(Pizza_Type_Name + ", " + toppings);
System.out.println("Order price: $" + df.format(total_Pizza));
System.out.println("Tax: $" + df.format(Tax_perc));
System.out.println("Total Due: $" + df.format(GrandTotal));
}
}
keyboard.nextLine();
// Prompts user for payment method
System.out.print("How would you like to pay for your pizza? (C)Credit Card, (D)Debit card, or (CH)Cash (enter C, D, or CH,): " );
Payment _Method= keyboard.nextLine().charAt(0);
if (Payment_Method == 'C' || Payment_Method == 'c' ){
Payment_Method_Name = "Credit Card";
Clicklink();
}
else if (Payment_Method == 'D' || Payment_Method == 'd' ){
Payment_Method_Name = "Debit Card";
Clicklink();
}
else if (Payment_Method == 'CH' || Payment_Method == 'ch' ){
Payment_Method_Name = "Cash";}
else if (Payment_Method != 'C' && Payment_Method != 'c' && Payment_Method != 'D' && Payment_Method != 'd' && Payment_Method != 'CH' && Payment_Method != 'ch' ){
System.out.println("The payment method you have selected is invalid.You payment method will be set to cash " );}
Payment_Method_Name = "Cash";
keyboard.nextLine();
}
}
//function for navigating user to the payment page
public void ClickLink(ActionEvent event) throws Exception {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("payment_page/fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root1));
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
Therefore by using the above code we can get our required output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.