Question

In: Computer Science

IN BASIC C# If It Fits, It Ships! OVERVIEW In this program you will be calculating...

IN BASIC C#

If It Fits, It Ships! OVERVIEW In this program you will be calculating the total amount the user will owe to ship a rectangular package based on the dimensions and we will add in insurance based on the prices of the items inside of the package.. INSTRUCTIONS: 1. Welcome the user and explain the purpose of the program. 2. In the Main, prompt the user for the width, length and height of their package. a. Each of the 3 variables should be validated and converted. 3. Create a custom function called SortByDimensions a. This function needs 3 parameters: the width, length and height. b. The function will be returning the number of what tier pricing is going to be used. c. Inside of the function, use a series of conditionals and logical operators to determine the tier based on the chart below. d. Return this integer of the matching tier to the main. i. Make sure to catch this in a variable of the correct type. 4. Back in the Main, let the user know what Tier for dimensions the package is. 5. In the Main, prompt the user for a comma separated text string of the prices of each item in the package. a. Remind the user NOT to put in the $. i. I.e. 5.60, 9.99, 10.50 b. Validate that this text string is not left blank. c. Once you have this text string, split about this string into a string array. d. Each element should be one price of an item. TIER # Requirements 1 All dimensions must be 10” and under. 2 Largest of the dimension is between 10” and 48”. 3 Largest of the dimensions is 48” or above. 6. Create a custom function called CalcInsurance. a. This function needs a parameter of the string array of item prices. b. The function will return the cost of the insurance for the package. c. Inside of this function a variable that will hold the total cost of all of the items. d. You will also need a variable to hold the cost of the insurance. e. Loop through the item string array and one at a time, convert each item to a number data type i. Add this price to the variable that holds the total cost. ii. After the loop, you should have a variable that holds the total of all items inside the package. f. Use the chart below to setup a conditional block that will give you the cost of the Insurance for this package. g. Return this cost of insurance to the Main. i. Make sure to catch this in a variable of the correct type. Total Cost of Items In Package Cost Of Insurance $0.00 to and including $10.00 $1.00 Up to $250.00 $5.00 Up to $500.00 $10.00 $500.00 and above $25.00 7. Create a 3rd custom function called TotalShippingCost. a. This function will have 2 parameters: the tier number based on the dimensions and the total cost of the insurance. b. The function will return the total of the shipping cost. c. In the function create a conditional block the will set the shipping base cost. i. This will be based on the chart below. d. Once you have the base price, add in the insurance to create the total shipping cost. e. Return this total for the shipping to the Main. i. Make sure to catch this in a variable of the correct type. 8. Now in the Main you will output to the user the final results. a. It should be in the following format. i. “Your package will cost $X to ship, which includes the $Y insurance price.” 1. Where X is the total cost to ship the package formatted for money and rounded to 2 decimal places. 2. Where Y is the insurance cost formatted for money and rounded to 2 decimal places. TIER # Base Shipping Cost 1 $6.25 2 $15.50 3 $30.00 9. Test, Test, Test a. Test your code at the very least 2 times and put your Test Results in a multi-lined comment at the end of your Main Method. b. Here is one data set that you should test with to make sure your math is correct. i. Package Dimensions: 1. 2. 3. 4. ii. Prices 1. 2. Width = 5 Length = 12 Height =2 For troubleshooting you could check the Tier # is 2. of items in package: 50.50, 25.00, 6.00, 150.00 For troubleshooting you could check the total is 231.50. iii. Final Output should be: 1. “Your package will cost $20.50 to ship, which includes the $5.00 insurance price.” 10. When you are finished zip your whole folder and submit it on FSO.

Solutions

Expert Solution

Screenshot

-------------------------------------------------------------

Program

using System;
namespace ShippingCharge
{
    class Program
    {
        //Method to print welcome message and instructions
        static public void welcome()
        {
            Console.WriteLine("     WELCOME TO SHIPPING SERVICE Instructions:-");
            Console.WriteLine("1.Prompt for dimensions of rectangular box in inches 2.Prompt for item prices in the box, You have to enter comma separated string. 3.Display total charge with insurance");
        }
        //Method to find out the tier count
        //First check all dimensionas within 10 inch range then tier1
        //Otherwise find large dimension
        //Large dimension within 10-48 then tier2
        //Else tier3
        static public int SortByDimensions(double l,double w,double h)
        {
            if(l<=10 && w<=10 && h <= 10)
            {
                return 1;
            }
            else
            {
               double max = l > w ? (l > h ? l : h) : (w > h ? w : h);
                if(max>10 && max < 48)
                {
                    return 2;
                }
                else
                {
                    return 3;
                }
            }
        }
        //Method to calculate insurance
        //Take item prizes array
        //Calculate total
        //Total within 10 ther 1.00 for insurance
        //within 10 -250 then 5.00
        //Within 250-500 then 10.00
        //Otherwise 25.00
        static public double CalcInsurance(string[] arr)
        {
            double total = 0;
            for(int i = 0; i < arr.Length; i++)
            {
                total += Convert.ToDouble(arr[i]);
            }
            if(total>=0 && total <= 10)
            {
                return 1.00;
            }
            else if (total >10 && total <=250)
            {
                return 5.00;
            }
            else if (total >250 && total <= 500)
            {
                return 10.00;
            }
            else
            {
                return 25.00;
            }
        }
        //Method to find total charge for shipping
        //First calculate base rate according to tier values
        //For tier1=6.25
        //For ter2=15.00
        //For tier3=30.00
        //return total=base+insurance
        static public double TotalShippingCost(int tier,double ins)
        {
            double basicRate = 0;
            if (tier == 1)
            {
                basicRate = 6.25;
            }
            else if (tier == 2)
            {
                basicRate = 15.50;
            }
            else
            {
                basicRate = 30.00;
            }
            return (basicRate + ins);
        }
        //Test
        static void Main(string[] args)
        {
            //Method to display welcome message
            welcome();
            //Prompt for length
            Console.Write(" Enter Length: ");
            double length = Double.Parse(Console.ReadLine());
            //Length validation
            while (length <= 0)
            {
                Console.WriteLine("Error!!!Length should be positive. Re-enter");
                Console.Write("Enter Length: ");
                length = Double.Parse(Console.ReadLine());
            }
            //Prompt for width
            Console.Write("Enter Width: ");
            double width = Double.Parse(Console.ReadLine());
            //Width validation
            while (width <= 0)
            {
                Console.WriteLine("Error!!!Width should be positive. Re-enter");
                Console.Write("Enter Width: ");
                width = Double.Parse(Console.ReadLine());
            }
            //Prompt for height
            Console.Write("Enter Height: ");
            double height = Double.Parse(Console.ReadLine());
            //Height validation
            while (height<= 0)
            {
                Console.WriteLine("Error!!!Height should be positive. Re-enter");
                Console.Write("Enter Height: ");
                height = Double.Parse(Console.ReadLine());
            }
            //Get tier number
            int tier = SortByDimensions(length, width, height);
            //Prompt for item price
            string prices = "";
            Console.Write("Enter prices of item(using commato separate prices and don't put $): ");
            while(string.IsNullOrEmpty(prices=Console.ReadLine()))
            {
                Console.WriteLine("Error!!!Not enter blank.Please re-enter");
                Console.Write("Enter prices of item(using comma to separate prices and don't put $): ");
            }
            //Split item price and store into a string array
            string[] itemPrices= prices.Split(',');
            //Get insurance amount
            double insuranceAmt=CalcInsurance(itemPrices);
            //Get total charge
            double totalCharge = TotalShippingCost(tier, insuranceAmt);
            //Display charge
            Console.WriteLine(" Your package will cost $" + totalCharge.ToString("#.##") + " to ship, which includes the $" + insuranceAmt.ToString("#.##") + " insurance price.");
        }
    }
}

-------------------------------------------------------

Output

     WELCOME TO SHIPPING SERVICE
Instructions:-
1.Prompt for dimensions of rectangular box in inches
2.Prompt for item prices in the box, You have to enter comma separated string.
3.Display total charge with insurance

Enter Length: 5
Enter Width: 12
Enter Height: 2
Enter prices of item(using comma to separate prices and don't put $): 50.50,25.00,6.00,150.00

Your package will cost $20.5 to ship, which includes the $5 insurance price.


Related Solutions

General overview (In C++) In this program you will be reading sales information from a file...
General overview (In C++) In this program you will be reading sales information from a file and writing out a bar chart for each of the stores. The bar charts will be created by writing out a sequence of * characters. You will have to create input files for your program. You can use a text editor such as Notepad or Notepad++ to create this. There may also be an editor in your IDE that you can use. You can...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Done in C language using mobaxterm if you can but use basic C This program is...
Done in C language using mobaxterm if you can but use basic C This program is broken up into three different functions of insert, delete, and main. This program implements a queue of individual characters in a circular list using only a single pointer to the circular list; separate pointers to the front and rear elements of the queue are not used. The linked list must be circular.      The insert and remove operations must both be O(1)    You...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
C++ program that runs on Visual Basic that computes the total cost of books you want...
C++ program that runs on Visual Basic that computes the total cost of books you want to order from an online bookstore. It does so by first asking how many books are in your shopping cart and then based on that number, it repeatedly asks you to enter the cost of each item. It then calls two functions: one for computing the taxes and another for computing the delivery charges. The function which computes delivery charges works as follows: It...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
I have to write a c program for shipping calculator. anything that ships over 1000 miles,...
I have to write a c program for shipping calculator. anything that ships over 1000 miles, there is an extra 10.00 charge. I have tried everything. no matter what I put, it will not add the 10.00. please help here is my code #include <stdio.h> #include <stdlib.h> int main() { double weight, miles, rate, total; printf("Enter the weight of the package:"); scanf("%lf", &weight); if (weight > 50.0) { puts("we only ship packages of 50 pounds or less."); return 0; }...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
The Basic Steps to Calculating a Hypothesis Test You want to start by determining whether you...
The Basic Steps to Calculating a Hypothesis Test You want to start by determining whether you are interested in working with a mean or a proportion. Then identify each of the parts listed below. In order to use the formulas for a hypothesis test we first need to confirm that the sample size requirements for the central limit theorem are satisfied. See the notes for more information. If the sample size is not met acknowledge that you need to proceed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT