I am needing some help with Visual C# 2010 Comprehensive An Introduction to Object Oriented Programing by Joyce Farwell, Chappter 11 Question 3.

ArgumentException is an existing class that derives from Exception; you use it when one or more of a method's arguments do not fall within an expected range. Create a class named CarInsurance containing variables that can hold a driver's age and state of residence. Within the class, create a method that accepts the two input values and calculates a preminum. The premium base prive is $100 for residents of Illinois (IL) and $50 for residents of Wisconsin (WI). Additionally, each driver pays $3 times the value of 100 minus his or her age. If the driver is younger then 16, or older than 80, or not a resident of Illinois or Wisconsin, Throw an ArgumentException from the method. In the Main() method of the CarInsurance class, try code that promotes the user for each value. If the user does not enter a numeric value for age, catch a FormatException and display an error message. Call the method that calculates the premium and catch the potential ArgumentEcecption object. Save file as CarInsurance.cs.

I have been fighting with the one for some time now and could realy use some help.

Show us some code, and explain the issues you are having.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CarInsurance
{
 class CarInsurance
    {
        public static void Main()
        {
            int DriverAge = 0;
            string State;
            double IL = 100.00;
            double WI = 50.00;
            try
            {
                Console.Write("Enter Driver's age.. ");
                DriverAge = Convert.ToInt32(Console.ReadLine());
                if (DriverAge < 16 || DriverAge > 80)
                {
                    (3 * (IL - DriverAge));
                }

            }
            catch (FormatException e)
            {

                Console.WriteLine("You have Entered A Letter instead of a number");
            }
            Console.Write("Enter State Driver's Lives.. ");
            State = Console.ReadLine();

        }
    }
}

K... so were you going to tell me what's wrong with it? I'll get you started: the question asks for a class that contains a method, which is called by the Main() method, to calculate premiums. I'm assuming that methods have been covered by the time you got to chapter 11 of a programming book (otherwise they probably wouldn't ask), so maybe you need to go back and read some more. Also, the question is somewhat vague... it asks for the CarInsurance class to hold two variables, and also accept the two variables in the method, which seems unnecessary and redundant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.