Question
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started