Question

Hello can someone help me in my code I left it as comment  task #0, task#1, task#2a...

Hello can someone help me in my code I left it as comment  task #0, task#1, task#2a and task#2b the things that I am missing I'm using java

domain class

public class Pizza
{
private String pizzaCustomerName;
private int pizzaSize; // 10, 12, 14, or 16 inches in diameter
private char handThinDeep; // 'H' or 'T' or 'D' for hand tossed, thin crust, or deep dish, respecitively
private boolean cheeseTopping;
private boolean pepperoniTopping;
private boolean sausageTopping;
private boolean onionTopping;
private boolean mushroomTopping;
  
public Pizza(String aPizzaCustomerName, int aSize, char aPizzaType, boolean aCheeseTopping, boolean aPepperoniTopping, boolean aSausageTopping, boolean aOnionTopping, boolean aMushroomTopping)
{
  
pizzaCustomerName = aPizzaCustomerName;
pizzaSize = aSize;
handThinDeep = aPizzaType;
cheeseTopping = aCheeseTopping;
pepperoniTopping = aPepperoniTopping;
sausageTopping = aSausageTopping;
onionTopping = aOnionTopping;
mushroomTopping = aMushroomTopping;
}
  

The rest I can add says it's too big

driver/tester

package pizzatester;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

/**
*
* @author cristy
*/
public class PizzaTester_1
{
public static Pizza aPizzaOrder;

/**
* @param args the command line arguments
* 5 methods are called from main: getUserInput(), calculatePizzaCost(), checkForDiscount(), calculateTax(), and displayFinalPrice()
*/
public static void main(String[] args)
{
  
getUserInput(); //method will create aPizzaOrder object, which is a global variable
double cost = calculatePizzaCost(); //method will calculate cost of pizza and return it
double discount = checkForDiscount(); //method will return either 0 or 2, depending on whether user earned a discount or not
double finalCost = cost - discount; //final cost after applying discount
double tax = calculateTax(finalCost); //method will calculate tax using finalCost as argument, and return tax
displayFinalPrice(finalCost, tax); //method will receive finalCost and tax as argument, to display final price
}
  
  
/**
* Add comments about the purpose of getUserInput() method
*/
public static void getUserInput()
{
String firstName; //user's first name
String userInput;
int pizzaSizeInInches; //10, 12, 14, 16
char pizzaType; //hand, thin, deep dish
boolean cheeseTopping = false;
boolean pepperoniTopping = false;
boolean sausageTopping = false;
boolean onionTopping = false;
boolean mushroomTopping = false;

//welcome message
JOptionPane.showMessageDialog(null, "Welcome to Mike and Diane's Pizza.");


//get user's first name
firstName = JOptionPane.showInputDialog("Enter your first name: ");


//prompt user and get pizza size choice
JOptionPane.showMessageDialog(null, "Pizza Size (inches) Cost"+
'\n'+ "10' $10.99"+
'\n'+ "12' $12.99"+
'\n'+ "14' $14.99"+
'\n'+ "16' $16.99");

userInput = JOptionPane.showInputDialog("What size pizza would you like?" +
'\n'+"10, 12, 14, or 16(enter the number only)");
pizzaSizeInInches = Integer.parseInt (userInput);


userInput = JOptionPane.showInputDialog("What type of crust would you like?"+
'\n'+"(H)Hand-tossed, (T) Thin-crust, or (D) Deep-dish)"+
'\n'+ "(Enter H, T, or D):");
pizzaType = userInput.charAt(0);


JOptionPane.showMessageDialog(null,"All pizzas come with cheese."+
'\n'+"Additional toppings are $1.25 each."+
'\n'+"Choose from: Additional Cheese, Pepperoni, Sausage, Onion, or Mushroom.");
  
userInput = JOptionPane.showInputDialog("Would you like additional cheese?");
//Task #0: Write the if-statements to set the value of the cheeseTopping boolean flags to true or false, depending on
// whether the user says Yes or No. Use charAt(0) to get the first letter of their response, and check for
// an uppercase and a lowercase version of the first letter ('Y' or 'y')
// Continue asking the user about all the other toppings (pepperoni, onion, sausage, mushroom), and setting the appropriate flags to true or false
  
  
  
// Task #1: Create an instance of aPizzaOrder by invoking the constructor, and passing it the values in firstName, pizzaSizeInInches, pizzaType, cheeseTopping, pepperoniTopping, sausageTopping, onionTopping, mushroomTopping.
// Hint: Remember to use "new" to instantiate an object of aPizzaOrder
  
}
  
  
/**
* add comments about the purpose of calculatePizzaCost() and describe the value that this method returns
* @return
*/
public static double calculatePizzaCost()
{
  
  
double cost = 12.99; //cost of the pizza   
  
String toppings = ""; //list of toppings   
int numberOfToppings = 0; //number of toppings
String crust = "";
final double TOPPING_PRICE = 1.25;
  
  
if (aPizzaOrder.getHandThinDeep() == 'h'|| aPizzaOrder.getHandThinDeep() == 'H')
crust = "Hand-Tossed";
else if (aPizzaOrder.getHandThinDeep() == 't' || aPizzaOrder.getHandThinDeep() == 'T')
crust = "Thin-Crust";
else if (aPizzaOrder.getHandThinDeep() == 'd' || aPizzaOrder.getHandThinDeep() == 'D')
crust = "Deep-Pan";
  
if (aPizzaOrder.getCheeseTopping())
{
numberOfToppings += 1;
toppings = toppings + "Additional Cheese ";
}
//Task #2a: Determine how many more toppings and concatenate them to the toppings String variable, and add 1 to numberOfToppings for each topping:

  
  
//Task #2b: Set the initial cost of the pizza based upon the size. Hint: Use an if-statement (10inch = 10.99; 12inch = 12.99; 14inch = 14.99; 16inch = 16.99)
  

  
// Finalize the total cost of the pizza:
cost = cost + (TOPPING_PRICE * numberOfToppings);
  
  
//Display the pizza order confirmation:
JOptionPane.showMessageDialog(null, "Your order is as follows: " + "\n One " + aPizzaOrder.getPizzaSize() + " inch pizza \n" + crust + " crust " + toppings + ".");

return cost;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/Task #0: Write the if-statements to set the value of the cheeseTopping boolean flags to true or false, depending on
// whether the user says Yes or No. Use charAt(0) to get the first letter of their response, and check for
// an uppercase and a lowercase version of the first letter ('Y' or 'y')
// Continue asking the user about all the other toppings (pepperoni, onion, sausage, mushroom), and setting the appropriate flags to true or false

Task #0 Implementation

Above the task #0, we have read the value of user input for additional cheese, now we have to check the user input, if it is Yes or 'Y', we need to set the cheeseTopping to true, otherwise false. We can code this as below:

       if (userInput.charAt(0) == 'y' || userInput.charAt(0) == 'Y') {
            cheeseTopping = true;
        } else {
            cheeseTopping = false;
        }

Now, similarly we need to continue asking the user for other topping too, and get the user input. And as per their input, we need to set respective flags:

       userInput = JOptionPane.showInputDialog("Would you like pepperoni?");
        if (userInput.charAt(0) == 'y' || userInput.charAt(0) == 'Y') {
            pepperoniTopping = true;
        } else {
            pepperoniTopping = false;
        }

        userInput = JOptionPane.showInputDialog("Would you like sausage?");
        if (userInput.charAt(0) == 'y' || userInput.charAt(0) == 'Y') {
            sausageTopping = true;
        } else {
            sausageTopping = false;
        }

        userInput = JOptionPane.showInputDialog("Would you like onion?");
        if (userInput.charAt(0) == 'y' || userInput.charAt(0) == 'Y') {
            onionTopping = true;
        } else {
            onionTopping = false;
        }

        userInput = JOptionPane.showInputDialog("Would you like mushroom?");
        if (userInput.charAt(0) == 'y' || userInput.charAt(0) == 'Y') {
            mushroomTopping = true;
        } else {
            mushroomTopping = false;
        }

// Task #1: Create an instance of aPizzaOrder by invoking the constructor, and passing it the values in firstName, pizzaSizeInInches, pizzaType, cheeseTopping, pepperoniTopping, sausageTopping, onionTopping, mushroomTopping.

Task #1 Implementation

We need to create an instance of aPizzaOrder which is an object of Pizza class, so to instantiate the instance, we need to use the new keyword and call the constructor of Pizza class by passing all the parameter values that we have calculated in above task. So, it can be done as:

aPizzaOrder = new Pizza(firstName, pizzaSizeInInches, pizzaType, cheeseTopping, pepperoniTopping, sausageTopping, onionTopping, mushroomTopping);

//Task #2a: Determine how many more toppings and concatenate them to the toppings String variable, and add 1 to numberOfToppings for each topping:

Task #2a Implementation

The statement written above this task, checks if order has cheese topping, if it is, we need to increase the numberOfToppings by 1 and add topping name in the topping string. Similarly, we need to do for other topping options like below:

        if(aPizzaOrder.getPepperoniTopping()){
            numberOfToppings += 1;
            toppings = toppings + "Pepperoni ";
        }
        if(aPizzaOrder.getSausageTopping()){
            numberOfToppings += 1;
            toppings = toppings + "Sausage ";
        }
        if(aPizzaOrder.getOnionTopping()){
            numberOfToppings += 1;
            toppings = toppings + "Onion ";
        }
        if(aPizzaOrder.getMushroomTopping()){
            numberOfToppings += 1;
            toppings = toppings + "Mushroom ";
        }

//Task #2b: Set the initial cost of the pizza based upon the size. Hint: Use an if-statement (10inch = 10.99; 12inch = 12.99; 14inch = 14.99; 16inch = 16.99)

Task #2b Implementation

In this task, we have to set the initial cost of Pizza on the basis of Pizza sizes. If it is 10 inches, cost is 10.99, if it is 12 inches, cost is 12.99, if it is 14 inches, cost is 14.99, if it is 16 inches, cost is 16.99. So, we can do it using if-else statements and set the initial cost of Pizza like below:

       if(aPizzaOrder.getPizzaSize() == 10){
            cost = 10.99;
        }
        else if(aPizzaOrder.getPizzaSize() == 12){
            cost = 12.99;
        }
        else if(aPizzaOrder.getPizzaSize() == 14){
            cost = 14.99;
        }
        else if(aPizzaOrder.getPizzaSize() == 16){
            cost = 16.99;
        }

This completes all the required tasks. Let me know if you have any query or any difficulty in understanding it.

Thanks!

Add a comment
Know the answer?
Add Answer to:
Hello can someone help me in my code I left it as comment  task #0, task#1, task#2a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has...

    C# Programming Exercise and Bonus Exercise (Next Page) 1) Define a class called OrderPizza that has member variables to track the type of pizza being order (either deep dish, hand tossed, or pan) along with the size (small, medium or large), type of toppings (pepperoni, cheese etc.) and the number of toppings. Create accessors for each property (ex.: type, size, type of toppings, and number of toppings). Implementation class should have a CalculateOrderPayment method to compute the total cost of...

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I...

    Using Java, I created 3 files, Pizza,PizzaOrder, and PizzaOrder_Demo that I attached down below. But I cannot compile it. Could you please point out the error.The question is that This programming project extends Q1. Create a PizzaOrder class that allows up to three pizzas to be saved in an order. Each pizza saved should be a Pizza object as described in Q1. In addition to appropriate instance variables and constructors, add the following methods: public void setNumPizzas(int numPizzas)—sets the number...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • is there anyway you can modify the code so that when i run it i can...

    is there anyway you can modify the code so that when i run it i can see all the song when i click the select button all the songs in the songList.txt file can be shown song.java package proj2; public class Song { private String name; private String itemCode; private String description; private String artist; private String album; private String price; Song(String name, String itemCode, String description, String artist, String album, String price) { this.name = name; this.itemCode = itemCode;...

  • Can someone please help with this task for my current code? Task 3 (50 pts (Extra...

    Can someone please help with this task for my current code? Task 3 (50 pts (Extra Credit)). Implement a function to organize the shortest path for each node as a string. For example, if a node 4’s shortest path is 0→2→1→4, you can generate a string variable s=“0→2→1→4”. Modify the displaydistance() function to show the shortest distance and the shortest path for each node. – Hint 1:You definitely need to do operation for the π variable in this task. Feel...

  • Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular a...

    Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...

  • Written in Java I have an error in the accountFormCheck block can i get help to...

    Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT