Question

THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost...

THIS MUST BE DONE ON VISUAL STUDIO

Write a C# program that computes a the cost of donuts at your local Rich Horton’s store. The cost, of course, depends on the number of donuts you purchase. The following table gives the break down: Donuts Purchased Cost per Donut ($) = 15 0.75 A customer can save on the HST (13%) if they buy 12 or more donuts so only charge HST (use a constant) on the purchase if the customer purchases less than 12 donuts. Finally, there is a cover charge for the luxury of actually getting one of Rich Horton’s gourmet donuts. The constant cover charge is a flat $0.25 (before HST) which is added to the cost no matter how many donuts are purchased (this should be a constant). The program should input the Customer’s Last Name (string), and the number of donuts purchased (int). The program should output (in a neat manner): Last Name, Number of Donuts Purchased, and Total Cost. The program should also validate the user’s input so if the user enters a negative number of donuts, an error message should be printed. For all assignments, you are to submit: 1. Properly documented source code (.cs file) which includes comments at the top of your program (containing your name, student number, a description of the program), the list of variable names with their uses (data dictionary), and comments within the body of your program (inline comments). 2. Sample output showing your program works using the template that is provided on BlackBoard. This is to be a PDF file that contains one screen shoot of an output window, and several more cut and pastes of sample outputs (use a word processor and then export as a PDF). Please note that one sample output does NOT demonstrate that your program works. Your job is to prove to the marker that your program works for all cases (for example in this case, a negative number of donuts, between 0 and 7 donuts, between 8 and 15 donuts, and greater than 15 donuts. Failure to use the testing template or to submit as a PDF could result in a 0 for the testing component of the assignment. These 2 files are to be attached to the Assignment 1 DropBox by the due date

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Open Visual Studio and create Console Application with the language C#.

The Cost per Donut is 150.75

Create 2 classes Donut and DonutDriver

Donut class:

This class has the following member variables:

  • constant HST
  • constant coverCharge
  • string lastName
  • int numberOfDonuts
  • double totalCost

methods:

  • GetData:
  • CalcPrice
  • Display

GetData()

  • GetData() method gets the input for lastName and number of Donuts
  • this method checks for the valid input for number of Donuts
  • this method gets the input for number of DOnuts only if the user enters positive number
  • if they enter negative number then the code insists the user to re-enter the input.

CalcPrice()

  • CalcPrice() is the method to calculate the total cost for Donuts.
  • if number of Donuts is less than 12 then HST is applicable
  • cover charge for luxury is to be added before applying HST
  • if number of Donuts bought is 12 or more then HST is not applicable and only cover charge is to be added

Display()

  • Display() method prints the lastName of the customer, number of Donuts bought and the total cost.

DonutDriver Class

  • This class creates object for the Donut class
  • Using that object it calls GetData(), CalcPrice() and Display() methods to perform the required operations.

Code:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleAppCS

{

    class Donut

    {

        public const double HST = 0.13; //HST is 13% of the cost of the Donut

        public const double coverCharge = 0.25; //cover charge for luxury

        private string lastName; //Last name of the customer

        private int numberOfDonuts; //Number of Donuts Purchased

        private double totalCost; //Total Cost for Donuts Bought

        //GetData() method gets the input for lastName and number of Donuts

        //this method checks for the valid input for number of Donuts

        //this method gets the input for number of DOnuts only if the user enters positive number

        //if they enter negative number then the code insists the user to re-enter the input.

        public void GetData()

        {

            Console.Write("\n Enter Last Name : ");

            lastName = Console.ReadLine();

            do

            {

                Console.Write("\n Enter Number of Donuts : ");

                numberOfDonuts = Convert.ToInt32(Console.ReadLine());

                if (numberOfDonuts <= 0)

                    Console.WriteLine("Enter Valid Input for Number of Donuts !");

            } while (numberOfDonuts <= 0);

        }

        //CalcPrice() is the method to calculate the total cost for Donuts.

        //if number of Donuts is less than 12 then HST is applicable

        //cover charge for luxury is to be added before applying HST

        //if number of Donuts bought is 12 or more then HST is not applicable and only cover charge is to be added

        public void CalcPrice()

        {

            if (numberOfDonuts<12)

            {

                totalCost = (numberOfDonuts * 150.75 + coverCharge) * HST ;

            }

            else

            {

                totalCost = numberOfDonuts * 150.75 + coverCharge;

            }

        }

         

        //Display() method prints the details like last name, number of Donuts and total cost.

        public void Display()

       {

            Console.WriteLine("Last Name : {0}", lastName);

            Console.WriteLine("Number of Donuts : {0}", numberOfDonuts);

            Console.WriteLine("Total Cost : ${0:0.00}", totalCost);

        }

    }

    //DonutDriver is a driver class for Donut class

    //An object for Donut is created and the member methods of the Donut class is called using that object.

    class DonutDriver

    {

        static void Main(string[] args)

        {

            Donut d = new Donut();

            d.GetData();

            d.CalcPrice();

            d.Display();

        }       

    }

}

Screenshot:

Qusing System; using System.Collections.Generic; using System.Text; Snamespace ConsoleAppCS { 2 references class Donut { publ

//CalcPrice is the method to calculate the total cost for Donuts. //if number of Donuts is less than 12 then HST is applicabl

Output:

Case 1:

Enter Last Name : AAA

Enter Number of Donuts : 12
Last Name : AAA
Number of Donuts : 12
Total Cost : $1809.25

Enter Last Name : AAA Enter Number of Donuts : 12 Last Name : AAA Number of Donuts : 12 Total Cost : $1809.25

Case 2:

Enter Last Name : LLL

Enter Number of Donuts : 5
Last Name : LLL
Number of Donuts : 5
Total Cost : $98.02

Enter Last Name : LLL Enter Number of Donuts : 5 Last Name : LLL Number of Donuts : 5 Total Cost : $98.02

Case 3:


Enter Last Name : PPP

Enter Number of Donuts : 19
Last Name : PPP
Number of Donuts : 19
Total Cost : $2864.50

Enter Last Name : PPP Enter Number of Donuts : 19 Last Name : PPP Number of Donuts : 19 Total Cost : $2864.50

Add a comment
Know the answer?
Add Answer to:
THIS MUST BE DONE ON VISUAL STUDIO Write a C# program that computes a the cost...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • MUST BE IN C++ COMPATIBLE WITH VISUAL STUDIO ALL FILES INCLUDED MUST WORK MUST BE DONE...

    MUST BE IN C++ COMPATIBLE WITH VISUAL STUDIO ALL FILES INCLUDED MUST WORK MUST BE DONE USING A CHARACTER ARRAY TO MEET THE REQUIREMENT 1.You have the following clients for your consulting firm: Client Business Type Acme Construction Johnsohn Electrical Brown Heating and Cooling Smith Switches Jones Computers Williams Cleaning Equipment Machinery design Switch manufacturing Boiler design Switch manufacturing Computer sales Machinery sales To keep track of your clients in an orderly manner, you need a program that can arrange...

  • Linux & Unix Write a bash program to indent the code in a bash source file....

    Linux & Unix Write a bash program to indent the code in a bash source file. Conditions:     The source file will contain only printing characters, spaces, and newlines. It is not necessary to check for invalid input.     The source file will not contain comments (words beginning with #). Requirements:     Read from standard input, write to standard output.     Code inside while statements should be indented 2 spaces. Be sure your program includes all of the following:    ...

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • In Java with comments. Write a program that computes the cost of flowers sold at a...

    In Java with comments. Write a program that computes the cost of flowers sold at a flower stand. Five kinds of flowers—petunia, pansy, rose, violet, and carnation— are stocked and cost, respectively, 50¢, 75¢, $1.50, 50¢, and 80¢ per flower. Create an array of strings that holds the names of these flowers. Create another array that holds the cost of each corresponding flower. Your program should read the name of a flower and the quantity desired by a customer. Locate...

  • Write a C program as follows: Single source code file Requests the user to input two...

    Write a C program as follows: Single source code file Requests the user to input two integer numbers Requests the user to make a choice between 0 (add), 1 (subtract), or 2 (multiply) Declares three separate functions Uses a pointer to these three functions to perform the requested action Outputs the result to the screen Submit your program source code file to this assignment. Sample Output Enter first integer number: 15 Enter second integer number: 10 Enter Choice: 0 for...

  • C++ visual studio program...Write your own version of a class template that will create a dynamic...

    C++ visual studio program...Write your own version of a class template that will create a dynamic stack of any data type. The pop function must return a bool; it should return a false if it was not able to pop an item off the stack. Otherwise it returns true. The parameter to the pop function is passed by reference and should be the item on the list if it was able to pop something. Create a driver program (main) that...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Write a C program which computes the count of the prime and perfect numbers within a...

    Write a C program which computes the count of the prime and perfect numbers within a given limit Land U, representing the lower and upper limit respectively. Prime numbers are numbers that have only 2 factors: 1 and themselves (1 is not prime). An integer number is said to be perfect number if its factors, including 1 (but not the number itself), sum to the number. Sample Inputi: 1 100 Sample Outputs: Prime: 25 Perfect: 2 Sample Input2: 101 10000...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT