Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Find and fix the bugs in a C# program using System; /* Many businesses need to shipping costs for products they deliver. A customer usually
Find and fix the bugs in a C# program
using System; /* Many businesses need to shipping costs for products they deliver. A customer usually gets a price break for more items ordered. Often, the prices for shipping are put into ranges of weights, only changing as a threshold is reached. Assume that a previous programmer wrote this code, but before debugging and delivering it, was transferred to a new department. Your task to finish the work. The code is almost correct, but compilation (syntax), coding (specification), or output (semantic) bugs exist. Carefully study the code, determine the problem, and fix the bug or bugs so that the output is as expected. Change as little code as possible to correct the problem. Place a comment on or before the fixed lines explaining what is wrong and how the fix resolves the issue--no comment(s), no points. */ namespace FFTB03 { class driver { /* Determine shipping cost based on weight: for up to 1 lb., $3.50; for up to 3 lb., $5.50; for up to 10 lb., $8.50; for up to 20 lb., $10.50; for more than 20 lb. issue a message "the package must be shipped by another carrier". */ static double ComputeCost(double weight) { if (weight < 1) return 3.5; else if (weight < 3) return 5.5; else if (weight < 10) return 8.5; else return 10.5; } static void Main(string[] args) { Console.WriteLine("Expected cost for 2 lb. is 5.5"); Console.WriteLine("Actual cost for 2 lb. is " + ComputeCost(2)); Console.WriteLine("Expected cost for 10 lb. is 8.5"); Console.WriteLine("Actual cost for 10 lb. is " + ComputeCost(10)); Console.WriteLine("Expected cost for 22 lb. is an error message"); Console.WriteLine("Actual cost for 22 lb. is " + ComputeCost(22)); } } }
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