Question: C# i can't post copiable code because it is too long.. This assignment requires you to improve the OrderAnvils3 program by refactoring the code into
C# i can't post copiable code because it is too long..
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).
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.






* Description: 8 9 10 11 12 13 14 15 * * This program is used by an ACME order taker to collect info from a customer who wishes to buy anvils, validate that the info is correct, calculate the total value of the order and display all of the data on an invoice, subject to the following conditions: If the customer is a frequent shopper, they are entitled to an additional 15% discount. 16 * * Frequent shoppers can play a game to win a free gallon of Invisible Paint. * 17 18 19 20 21 22 23 24 25 26 27 Pricing for the anvils is based on the volume of anvils purchased: 1 - 9: $80.00 10-19: $72.35 20+: $67.99 * * * * The program validates that order input is valid. If validation fails, the invoice will not print. * using System; using static System.Console; namespace OrderAnvilsSolution { class OrderAnvils3 { static void Main(string[] args) { int numberOfAnvils; int guess; int contestNumber; string fullName; string streetAddress; string city; string stateAbbreviation; string zipCode = ""; bool fieldValidationSuccess = false; bool loyaltyDiscount; bool sendGift; decimal subTotal; decimal tax; decimal shipping; decimal total; decimal loyaltyDiscountAmt; decimal taxableAmount; ; 37 38 39 40 49 41 42 43 44 45 46 47 48 10 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 bb 67 07 68 69 70 71 72 73 74 14 75 76 77 78 79 80 ga ou 81 82 83 83 84 85 25. 86 80 87 88 99 89 90 90 91 92 93 94 95 double quantityBasedCostPerAnvil; const double Sales Tax = 0.0995; 1/9.95% sales tax reduction due to election year. const decimal CostPerAnvillier1 = 80M; I'M' because it's a variable of type decimal const decimal CostPerAnvillier2 = 72.35M; const decimal CostPerAnvillier3 = 67.99M; const decimal Shipping CostPerAnvil = 99M; const double LoyaltyDiscountFactor = 0.15; //15% discount const int GameMin = 1; const int GameMax = 5; const string ACMEBanner1 = "*** const string ACMEBanner2 = "******* ***** ACME Anvils Corporation ******* const string ACMEBanner3 = "\a********* ***** NEW ORDER ********* //OPTIONAL BONUS: Add a state array. string[] states = new string[] { "AK", "WA", "OR", "CA", "AZ", "NM", "CO", "UT" }; Random contestNumbers = new Random(); //Instantiate random number generator //Welcome message WriteLine(ACMEBanner2); WriteLine("Supporting the animation industry for 70 years and counting!"); //Start the outer loop do { fieldValidationSuccess = false; 155 156 157 while (!fieldValidationSuccess) 158 159 int sub = 0; while (sub GameMax) { WriteLine(" \tThat's not a number between {GameMin) and (GameMax). What an ultra-maroon! \tStill, we value your loyalty."); } else [ if (contestNumber == guess) { WriteLine(" \twoo hoo! You guessed the secret number: {contestNumber}! + " \tA gallon of ACME Invisible Paint is headed your way!"); sendGift = true; } else { WriteLine(" \tAww, too bad. You guessed {guess), but the secret number was " + $"{contestNumber}. No paint. \tWhat a loser. Very sad."); } } else { WriteLine(" \twhat's wrong with you? That just cost you a 15% discount and" + " \tan opportunity to win some Invisible Paint. Sad."); } 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 //Calculate subtotal: price * qty using volume discount if (numberOfAnvils GameMax) { WriteLine(" \tThat's not a number between {GameMin) and (GameMax). What an ultra-maroon! \tStill, we value your loyalty."); } else [ if (contestNumber == guess) { WriteLine(" \twoo hoo! You guessed the secret number: {contestNumber}! + " \tA gallon of ACME Invisible Paint is headed your way!"); sendGift = true; } else { WriteLine(" \tAww, too bad. You guessed {guess), but the secret number was " + $"{contestNumber}. No paint. \tWhat a loser. Very sad."); } } else { WriteLine(" \twhat's wrong with you? That just cost you a 15% discount and" + " \tan opportunity to win some Invisible Paint. Sad."); } 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 //Calculate subtotal: price * qty using volume discount if (numberOfAnvils
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
