Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# This assignment requires you to improve the OrderAnvils3 program by refactoring the code into methods. The behavior of the program should be exactly the

C# This assignment requires you to improve the OrderAnvils3 program by refactoring the code into methods. The behavior of the program should be exactly the same as ACME Anvils Order Taking 3.0 (from Programming Assignment 3 *on the pictures I uploaded).

Some important notes

  • Good coding practice, including adherence to standards, is important. Penalties for ignoring standards and for ignoring coding practices weve reviewed in class are higher for this assignment.

  • Penalties will be assessed for grossly inefficient code.

  • If you use a feature we havent covered in class:

o Make sure your code conforms to the SDS or you may lose points. o Make sure youre using the feature properly and that it adds value to your solution. If it does

not, you may lose points.

Required coding features

Your refactored code must include the methods below. For full credit you must use the exact method signatures specified. If youd like, youre welcome to add your own helper methods, but make sure to use the ones in the spec as written.

You may start with my published solution for OrderAnvils3 if you wish. Remember: side-by-side executions of this program and Programming Assignment 3 should behave the same!

void PrintBanner() 

Prints the opening banner for the session. Must be called from Main().

void Countdown(int numberOfSeconds)

Displays a countdown timer to accommodate the union-mandated break between orders.

Notes:

  • Called from Main with number of seconds (use 3, please)

  • Use the Thread.Sleep method to sleep for 1000 milliseconds between counts.

    int GetPositiveInt(string prompt)

    Reads and validates integer input from the user using the supplied prompt.

    Notes:

  • Build a validation loop using TryParse to ensure valid integer input.

  • The returned value must be > 0.

  • If the user provides invalid input, re-prompt them with an explanation of what the correct input

    should be (e.g., You must enter a number greater than zero.)

  • Call this method from Main() to get the number of anvils requested.

  • This method must be reusable. That is, it must not include any code specific to anvils.

string GetValidString(string prompt, int min) string GetValidString(string prompt, int min, int max) Reads and validates string input from the user using the supplied prompt. Validation:

  • The returned string must have a length >= to the min parameter.

  • The returned string must have a length

    max parameter is used, that should be interpreted as the string having no specific maximum length.

    It can be as long as the user wants.

  • This method must be reusable. That is, it must not include any code that depends on knowledge of

    the calling application.

    Notes:

  • Build a validation loop to ensure that the input conforms to the callers length min and max parameters.

  • Call this method from Main() to get values for the following fields. Min and max (if appropriate) for each field is in parentheses:

    o Name(1) o Streetaddress(1) o City(1,20) o Zip(5,5)

  • If the validation criteria are not met, inform the user by explaining the valid lengths for the field in question and re-prompting. For example:

o Name must be at least 1 character(s) long. Please re-enter. This sort message should be produced when there is no maximum length specified.

o City must be at between 1 and 20 characters long. Please re-enter. This sort of message should be produced when min is different from max.

o Zip must be exactly 5 characters long. Please re-enter: This sort of message should be produced when min == max.

Hint: Use just the fields name (e.g., name, city) for the prompt parameter. Then build the prompt and error strings around it.

string GetValidState(string prompt, string[] sortedStateArray)

Reads and validates string input from the user using the supplied prompt. Validation:

  • The returned string must precisely 2 characters long.

  • The input value must match a value in the supplied state array. Notes:

  • Initialize the state array in Main().

  • Build a validation loop to ensure that the user enters a valid state abbreviation.

  • Use a loop to search the array for a valid state. Do not use Array.BinarySearch

  • Call GetValidString to get the string from the user. Use 2 for both the min and max parameters.

bool LoyaltyDiscount() 

Interacts with the user to determine whether they belong to the Futility Club.

Notes:

  • Call from Main()

  • Displays the script, asks the user whether they belong to the futility club, responds to their answer

    positively or negatively, and returns true if they belong, false if they do not.

    bool EnterContest(Random chanceGenerator) 

    Interacts with the users who belong to the Futility Club to determine whether they win a fabulous FREE GIFT! Notes:

  • Call from Main() passing in the Random object initialized in Main().

  • Generate a random number for the user to guess.

  • Interact with the user to get them to guess a number between 1 and 10.

  • If the user wins, congratulate them.

  • If the user loses, berate them mercilessly and tell them what the random number was.

  • Return a bool: true if the user wins, false if they do not.

    decimal CalcAndPrintInvoiceBody(int qty, bool discount, bool promotionPrize)

    Performs the necessary calculations to enable printing the main part of the invoice, and then prints it. The return value represents the total invoice amount. Notes:

  • Call this method from Main().

  • Print the shipping address in Main() before you call this method.

  • Determine whether the loyalty discount is applicable in Main() before you call this method.

  • Conduct the contest to determine whether the user will receive the promotional prize in Main()

    before you call this method.

  • The method must produce the following elements of output on the invoice:

o Quantity o Costperanvil o Subtotal o Loyaltydiscountamount(ifapplicable) o Taxable amount o Sales tax o Total o The promotional gift congratulatory message

After the method concludes and control is returned to Main(), print the total message: (Your total today is {total:C}. Thanks for shopping with Acme!), where the value of the variable total is the returned value from CalcAndPrintInvoiceBody

decimal GetAnvilPrice(int qty) 

Returns the price per anvil based on quantity requested.

Notes:

  • This method must be called from CalcAndPrintInvoiceBody.

  • You must use the array-based version of accurate and efficient range checking.

  • image text in transcribed

  • image text in transcribedimage text in transcribedimage text in transcribed

sample output 1 Errors, eventual success, no loyalty discount In the example interaction below, data typed by the user appears highlighted and in boldface. ****** ********* ******* ACME Anvils Corporation ******** Supporting the animation industry for 70 years and counting! Countdown to Order 3 2 1 ************ NEW ORDER *************** **************** How many anvils would you like to order SCRIPT: Hi, I'm . today? Number of anvils: 1 Could you please give me your SCRIPT: I can certainly help you with that. name and addressa Full name: Invalid entry. Full name must have at least 1 character. Please try again: Street address: City: State: Yosemite Sam 15 Main St Rising Gorge NN ***ERROR. We do not ship to NN. Valid state codes are: AK, AZ, CA, CO, NM, OR, UT, WA Please try again: NM Zip: 802345 Invalid entry. Zip must have exactly 5 characters. Please try again: 80234 SCRIPT: Are you a member of our Futility Club, the frequent shopper program that rewards persistence over results? Enter Y or N: SCRIPT: What's wrong with you? That just cost you a 15% discount and an opportunity to win some Invisible Paint. Sad. Press any key to display invoice... **************************************************************************** ************************ ACME Anvils Corporation *************************** CUSTOMER INVOICE SHIP TO: Yosemite Sam 15 Main St Rising Gorge NM 80234 Quantity: Cost per anvil: Subtotal: Sales Tax: Shipping: 1 $80.00 $80.00 $7.96 $99.00 TOTAL: $186.96 **************************************************************************** SCRIPT: Your total today is $186.96. Thanks for shopping with Acme! And don't forget: Acme anvils fly farther, drop faster, and land harder than any other anvil on the market! Ready to take another order? Enter Y or N: y Sample output 2 Loyalty discount, win the game In the example interaction below, data typed by the user appears highlighted and in boldface. Note that this is a continuation of the session begun in sample 1. Countdown to Order 3 2 1 *************** NEW ORDER ************* *** ********************** How many anvils would you like to order SCRIPT: Hi, I'm . today? Number of anvils: 10 Could you please give me your name SCRIPT: I can certainly help you with that. and address ? Full name: Elmer J. Fudd Street address: 3215 La Cienega Blvd City: Studio City State: CA Zip: 90620 SCRIPT: Are you a member of our Futility Club, the frequent shopper program that rewards persistence over results? Enter Y or N: y SCRIPT: Excellent! You'll receive an AMAZING 15% discount on today's purchase! SCRIPT: What's more, as a valued member of our loyalty program, you'll have a chance to win a bonus gift in our exciting Members Only Invisible Paint Extravaganza contest! Pick a number between 1 and 5! Number: 3 SCRIPT: Woo hoo! You guessed the secret number: 3! A gallon of ACME Invisible Paint is headed your way! Press any key to display invoice. **************************************************************************** ************************ ACME Anvils Corporation *************************** CUSTOMER INVOICE SHIP TO: Elmer J. Fudd 3215 La Cienega Blvd Studio City CA 90620 Quantity: Cost per anvil: Subtotal: Less 15% Futility Club: Taxable amount: Sales Tax: Shipping: 10 $72.35 $723.50 ($108.52) $614.98 $61.19 $990.00 TOTAL: $1,666.17 SCRIPT: And congratulations on winning FREE Invisible Paint!!! **************************************************************************** SCRIPT: Your total today is $1,666.17. Thanks for shopping with Acme! And don't forget: Acme anvils fly farther, drop faster, and land harder than any other anvil on the market! Ready to take another order? Enter Y or N: n Press any key to end program... sample output 1 Errors, eventual success, no loyalty discount In the example interaction below, data typed by the user appears highlighted and in boldface. ****** ********* ******* ACME Anvils Corporation ******** Supporting the animation industry for 70 years and counting! Countdown to Order 3 2 1 ************ NEW ORDER *************** **************** How many anvils would you like to order SCRIPT: Hi, I'm . today? Number of anvils: 1 Could you please give me your SCRIPT: I can certainly help you with that. name and addressa Full name: Invalid entry. Full name must have at least 1 character. Please try again: Street address: City: State: Yosemite Sam 15 Main St Rising Gorge NN ***ERROR. We do not ship to NN. Valid state codes are: AK, AZ, CA, CO, NM, OR, UT, WA Please try again: NM Zip: 802345 Invalid entry. Zip must have exactly 5 characters. Please try again: 80234 SCRIPT: Are you a member of our Futility Club, the frequent shopper program that rewards persistence over results? Enter Y or N: SCRIPT: What's wrong with you? That just cost you a 15% discount and an opportunity to win some Invisible Paint. Sad. Press any key to display invoice... **************************************************************************** ************************ ACME Anvils Corporation *************************** CUSTOMER INVOICE SHIP TO: Yosemite Sam 15 Main St Rising Gorge NM 80234 Quantity: Cost per anvil: Subtotal: Sales Tax: Shipping: 1 $80.00 $80.00 $7.96 $99.00 TOTAL: $186.96 **************************************************************************** SCRIPT: Your total today is $186.96. Thanks for shopping with Acme! And don't forget: Acme anvils fly farther, drop faster, and land harder than any other anvil on the market! Ready to take another order? Enter Y or N: y Sample output 2 Loyalty discount, win the game In the example interaction below, data typed by the user appears highlighted and in boldface. Note that this is a continuation of the session begun in sample 1. Countdown to Order 3 2 1 *************** NEW ORDER ************* *** ********************** How many anvils would you like to order SCRIPT: Hi, I'm . today? Number of anvils: 10 Could you please give me your name SCRIPT: I can certainly help you with that. and address ? Full name: Elmer J. Fudd Street address: 3215 La Cienega Blvd City: Studio City State: CA Zip: 90620 SCRIPT: Are you a member of our Futility Club, the frequent shopper program that rewards persistence over results? Enter Y or N: y SCRIPT: Excellent! You'll receive an AMAZING 15% discount on today's purchase! SCRIPT: What's more, as a valued member of our loyalty program, you'll have a chance to win a bonus gift in our exciting Members Only Invisible Paint Extravaganza contest! Pick a number between 1 and 5! Number: 3 SCRIPT: Woo hoo! You guessed the secret number: 3! A gallon of ACME Invisible Paint is headed your way! Press any key to display invoice. **************************************************************************** ************************ ACME Anvils Corporation *************************** CUSTOMER INVOICE SHIP TO: Elmer J. Fudd 3215 La Cienega Blvd Studio City CA 90620 Quantity: Cost per anvil: Subtotal: Less 15% Futility Club: Taxable amount: Sales Tax: Shipping: 10 $72.35 $723.50 ($108.52) $614.98 $61.19 $990.00 TOTAL: $1,666.17 SCRIPT: And congratulations on winning FREE Invisible Paint!!! **************************************************************************** SCRIPT: Your total today is $1,666.17. Thanks for shopping with Acme! And don't forget: Acme anvils fly farther, drop faster, and land harder than any other anvil on the market! Ready to take another order? Enter Y or N: n Press any key to end program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions