This is my code so far for the assignment. I am stuck on the last 3 tasks which are task#3, task#4 and task#5.
Task #3 String Comparisons
In
checkForDiscount()
method of the driver:
1. Figure out if there is a discount of $2 on this order, due to the customer's name being
either Mike or Diane
2. Return either 2 or 0 as the discount to the cost of the pizza
3. Compile, debug, and run. You should now be able to test all the crust types.
Run your program multiple times with different user names, including Mike and Diane.
Task #4 Arithmetic Calculations
In the calculateTax(double cost) method of the driver:
1. Compute the tax by multiplying the constant TAX_Rate by the cost (passed as a
parameter to the method).
2. Return the tax (back to main)
Task #5 Formatting Numbers
In the displayFinalPrice(double cost, double tax) method of the driver:
1. Instantiate the DecimalFormat class (make sure you have imported java.text.DecimalFormat).
Then, using JOptionPane, display the cost, tax, and grand total of the order, applying the
DecimalFormat object.
Hint:
To use DecimalFormat, you must first instantiate it like this:
DecimalFormat aFormat = new DecimalFormat("$##0.00");
Then, to format a variable named cost, you would use the following statement:
aFormat.format(cost)
Note that the DecimalFormat object that always shows 2 decimal places.
2. Compile, debug, and run. Your output should be completely correct at this time, and numeric
output should look like money.
public static double checkForDiscount()
{
double discount = 0;
//return a discount if user is eligible
//Task #3: Figure out whether to return 0 or $2, depending on
whether the customer's name is either Mike or Diana
return discount;
}
/**
* add comments about what this method does, what it receives as a
parameter, and what value it returns.
* @param cost
* @return
*/
public static double calculateTax(double cost)
{
final double TAX_RATE = .08; //sales tax rate
double tax = 0;
//Task #4: Calculate tax by multiplying tax_rate by parameter
return tax;
}
/**
* add comments about what this method does, what it receives as
parameters.
* @param cost
* @param tax
*/
public static void displayFinalPrice(double cost, double tax)
{
//ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES, using the
DecimalFormat class defined at the beginning of this method.
//calculate and display tax and total cost
DecimalFormat aFormat = new DecimalFormat("$##0.00");
//Task #5: Using JOptionPane, display "The cost of your order is: "
(use the DecimalFormat object)
// "The tax is: " (use the DecimalFormat object)
// "The total due is: " (use the DecimalFormat object)
// "Your order will be ready for pick-up in 30 minutes."
}
}
In case of any query do comment. Please rate answer as well.
Code:
import javax.swing.*;
import java.util.*;
import java.text.DecimalFormat;
public class Test
{
public static void main(String[] args)
{
//Let us assume the cost is $25.
double cost = 25.00;
double tax =0.0;
cost = cost - checkForDiscount();
tax = calculateTax(cost);
displayFinalPrice(cost,tax);
}
public static double checkForDiscount()
{
double discount = 0;
//return a discount if user is eligible
//Task #3: Figure out whether to return 0 or $2, depending on
whether the customer's name is either Mike or Diana
/*
you did not mention the full structure of your class and other
things so for testing purpose I am taking input from the user for
name.
It is assumed that customer name is already available for you in
checkFOrDiscount Method, you can remove these lines to get customer
name
*/
String customerName;
Scanner scnr = new Scanner(System.in);
System.out.println("Enter the customer name");
customerName = scnr.next();
if(customerName.equals("Mike") ||
customerName.equals("Diane"))
discount =2.0;
return discount;
}
/**
* Compute the tax by multiplying the constant TAX_Rate by the cost
(passed as aparameter to the method).
* @param cost
* @return cost mulitplied by constant tax rate
*/
public static double calculateTax(double cost)
{
final double TAX_RATE = .08; //sales tax rate
double tax = 0;
//Task #4: Calculate tax by multiplying tax_rate by parameter
tax = cost * TAX_RATE;
return tax;
}
/**
* using JOptionPane, display the cost, tax, and grand total of the
order, applying the DecimalFormat object.
* @param cost
* @param tax
*/
public static void displayFinalPrice(double cost, double tax)
{
//ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES, using the
DecimalFormat class defined at the beginning of this method.
//calculate and display tax and total cost
DecimalFormat aFormat = new DecimalFormat("$##0.00");
String output;
//Task #5: Using JOptionPane, display "The cost of your order is: "
(use the DecimalFormat object)
// "The tax is: " (use the DecimalFormat object)
// "The total due is: " (use the DecimalFormat object)
// "Your order will be ready for pick-up in 30 minutes."
output = "The cost of your order is: " + aFormat.format(cost) +
"\n";
output = output + "The tax is: " + aFormat.format(tax) +
"\n";
output = output + "The total due is: " + aFormat.format(cost + tax)
+ "\n";
output = output + "Your order will be ready for pick-up in 30
minutes.";
JFrame f = new JFrame();
JOptionPane.showMessageDialog(f,output);
}
}
====================Screen shot of the code========


Output:



This is my code so far for the assignment. I am stuck on the last 3...
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...
I am currently stuck with this portion of my assignment: Pointers review: to help determine how many fields are presented from the form at run time, the program will count the '=' signs from the QUERY_STRING and dynamically create a name_value_pairs array of cnt elements to be used by parse() and param(). Here is what to do, in order: As directed above, make a back up of the work so far and work with the new version named retrieve_form_OOP_2.cpp. These...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false;...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false; } for...
In java language
here is my code so far! i only need help with the extra credit
part
For this project, you will create a Rock, Paper, Scissors
game.
Write a GUI program that allows a user to play Rock, Paper,
Scissors against the computer.
If you’re not familiar with Rock, Paper, Scissors, check out the
Wikipedia page:
http://en.wikipedia.org/wiki/Rock-paper-scissors
This is how the program works:
The user clicks a button to make their move (rock, paper, or
scissors).
The program...
Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this: public static double divide(double operand1, double operand2) { return operand1 / operand2; } The random method is supposed to return a double within a lower limit and...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
Problem Description to implement a Java application, called ShoppingApplication, that can be used in a retail store. You are asked to implement three classes: Item, Invoice, and InvoiceDriver. Each of these classes is described below. Item class The Item class represents of an item that is being sold in the retail store (e.g., book or pencil) where an item is identified by three instance variables: name (of type Sring), weight (of type double), price (of type double), and currentDiscount (of...
Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...
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");...