Price Calculator program Requirements: The company that needed the flowchart and
ID: 3722253 • Letter: P
Question
Price Calculator program Requirements: The company that needed the flowchart and pseudocode for calculating a final price for has given you the responsibility of creating a program for that purpose. The requirements remain the same as those indicated for the flowchart: the program will calculate the final price that a customer will pay for a product based on an initial price, membership on the Store Club and customer’s state of residence. The company serves customers in New York and New Jersey. The components of the final price are the initial price, discount, shipping charge and tax. The discount - 10% of the initial price - is given only to the members of the Store Club. The shipping charge is $5 for New Jersey customers and $3 for New York customers. The tax – applied to the sum of the discounted price plus shipping charge – is 8% for New York customers and 7% for New Jersey customers. The output of the program will be the final price. The formula to calculate the discount in dollars is: initial price x discount percent The formula to calculate the final price is : (initial price – discount in dollars + shipping) x (1 + tax percent) The company has also provided a video – attached to these instructions on Sakai – that displays the way the program should work as well as the screen format when the program is run. (Note: on the video the program is run twice with two different data sets). Additional Requirements: You will enter a comment on the head section with your name on it. You will utilize prompt() functions to request input from the customer. You will utilize the alert() function to display your output as a clear and understandable message to the customer. Variable names should be descriptive. For example, if a program is calculating the tip given at a restaurant, an appropriate variable name may be tipAmount. The format of the screen should be similar to that provided on the video example. Page 2 of 3 Additional Information: Since the content of a text box - which is what the prompt() function generates - is going to be used in mathematical operations, use the function parseInt() to ensure that the numeric input is treated as numeric data. Syntax example: numericVariable = parseInt(numericVariable) To simplify the comparison of text data entered by the user, it is often easier to convert this text to upper case using the notation below. Syntax example: textVariable = textVariable.toUpperCase(); (See https://www.w3schools.com/jsref/jsref_toUpperCase.asp for additional example.) Syntax example for prompt function: var myName = prompt(“Enter your name”); Syntax example for alert function: alert(“My name is “ + myName);
Explanation / Answer
I write the code as per the instruction. I test it in a .html file with javascript coding.
<script language=javascript>
//parseInt is used to convert string to integer
price=parseInt(prompt("Enter the price"));
member=prompt("Enter yes or no for memebr");
state=prompt("Enter state of residence New Jersy or New York");
member=member.toUpperCase();
state=state.toUpperCase();
if(member=="YES")
discount=price*.10;
else
discount=0;
if(state=="NEW JERSY")
{
shipping_charge=5;
tot_price=(price-discount+shipping_charge)*(1 + .07)
}
if(state=="NEW YORK")
{
shipping_charge=3;
tot_price=(price-discount+shipping_charge)*(1 + .08)
}
alert("$"+tot_price,2);
</script>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.