CD Publisher


 

In this exercise, we will develop an application for a small CD publishing company. The owner wants the prices to be calculated so a customer would get a discount if he orders more. To attract customers and encourage them to order more, she has decided to fix the prices so that the customer would pay:

  • $20/CD if he orders less than 20 units
  • $15/CD if he orders less than 50 units
  • $12/CD if he orders less than 100 units
  • $8/CD if he orders less than 500 units
  • $5/CD if he orders more than 500 units
  1. Start Visual Studio
  2. Create a new Visual C# Windows Application and name it CDPublisher
  3. Design the form as follows:
     
    CD Publisher Design
    Control Name Text Other Properties
    Label   Number of CDs:  
    NumericUpDown updQuantity   Maximum: 10000
    TextAlign: Center
    Label   Unit Price:  
    TextBox txtUnitPrice 0 TextAlign: Right
    Label   Total Price:  
    TextBox txtTotalPrice 0 TextAlign: Right
    Button btnClose Close  
  4. Double-click the Close button and implement it as follows:
     
    private void btnClose_Click(object sender, System.EventArgs e)
    {
    	Close();
    }
  5. Double-click the up down button to access its OnChange() event and implement it as follows:
     
    private void updQuantity_ValueChanged(object sender, System.EventArgs e)
    {
    	int Quantity;
    	double UnitPrice, TotalPrice;
    
    	Quantity = Decimal.ToInt32(updQuantity.Value);
    
    	if( Quantity < 20 )
    		UnitPrice = 20;
    	else if( Quantity < 50 )
    		UnitPrice = 15;
    	else if( Quantity < 100 )
    		UnitPrice = 12;
    	else if( Quantity < 500 )
    		UnitPrice = 8;
    	else
    		UnitPrice = 5;
    
    	TotalPrice = Quantity * UnitPrice;
    	
    	txtUnitPrice.Text = UnitPrice.ToString("C");
    	txtTotalPrice.Text = TotalPrice.ToString("C");
    }
  6. Test the application
  7. Close it
 

Home Copyright © 2003 FunctionX, Inc.