Question

In: Computer Science

Write an AutoInsurance class to abstract auto insurance polices.

USE C#.

Write an AutoInsurance class to abstract auto insurance polices. Each auto insurance policy contains policy holder's name, policy number, car model, monthly premium, inception date, and expire date. This class needs to provide two constructors and one method which is to calculate the yearly premium.

Solutions

Expert Solution

using System;
namespace InsuranceApplication  
{
   class AutoInsurancePolicy
   {
       private string policyHolderName;
       private long policyNumber;
       private string carModel;
       private double monthlyPremium;
       String inceptionDate;
       String expiryDate;

       public AutoInsurancePolicy()
       {
           Console.WriteLine("Object is being created");
       }

       public AutoInsurancePolicy(string name, long number, string model, double premium, String inception, String expiry)
       {
           policyHolderName = name;
           policyNumber = number;
           carModel = model;
           monthlyPremium = premium;
           inceptionDate = inception;
           expiryDate = expiry;
       }

       public double calculateYearlyPremium()
       {
           return monthlyPremium*12;
       }
   }
   class AutoInsurance
   {
       static void Main(string[] args)
       {
           AutoInsurancePolicy policy = new AutoInsurancePolicy("Aakash",123,"abcc",125.00,"12/06/2016","12/06/2020");
           Console.WriteLine("Yearly Premium : {0}", policy.calculateYearlyPremium());
          
           AutoInsurancePolicy policy1 = new AutoInsurancePolicy("Aakash",1222,"abcc",250.00,"12/06/2016","12/06/2020");
           Console.WriteLine("Yearly Premium : {0}", policy1.calculateYearlyPremium());

       }
   }
}

Sample Output :

Yearly Premium : 1500
Yearly Premium : 3000

Related Solutions

Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
Java - Write an abstract class called Shape with a string data field called colour. Write...
Java - Write an abstract class called Shape with a string data field called colour. Write a getter and setter for colour. Write a constructor that takes colour as the only argument. Write an abstract method called getArea()
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's...
Abstract Cart class import java.util.ArrayList; import java.util.HashMap; /** * The Abstract Cart class represents a user's cart. Items of Type T can be added * or removed from the cart. A hashmap is used to keep track of the number of items * that have been added to the cart example 2 apples or 4 shirts. * @author Your friendly CS Profs * @param -Type of items that will be placed in the Cart. */ public abstract class AbstractCart {...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level,...
(In java language) Write an abstract class called House. The class should have type (mobile, multi-level, cottage, etc.) and size. Provide the following methods: A no-arg/default constructor. A constructor that accepts parameters. A constructor that accepts the type of the house and sets the size to 100. All other required methods. An abstract method for calculating heating cost. Come up with another abstract method of your own. Then write 2 subclasses, one for mobile house and one for cottage. Add...
Health insurance companies offer polices that strike a balance among three objectives: consumption smoothing for insurance...
Health insurance companies offer polices that strike a balance among three objectives: consumption smoothing for insurance purchasers, reduce incentives for overuse of medical services (moral hazard restraint), and guard against adverse selection. Explain consumption smoothing, moral hazard and adverse selection.
1. Implement the stack abstract data type. Write it as a separate class called Stack. For...
1. Implement the stack abstract data type. Write it as a separate class called Stack. For simplicity the data type to be stored in the stack is String but you can also use generic type. 2. Test your class implementation by calling push() and pop(). If the stack is empty (size equals zero) pop() should return null and print that “stack is empty”. If stack is full (size equals max) push() returns false and prints that “stack is full”. This...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester...
Write a Java application that implements the following: Create an abstract class called GameTester. The GameTester class includes a name for the game tester and a boolean value representing the status (full-time, part-time). Include an abstract method to determine the salary, with full-time game testers getting a base salary of $3000 and part-time game testers getting $20 per hour. Create two subclasses called FullTimeGameTester, PartTimeGameTester. Create a console application that demonstrates how to create objects of both subclasses. Allow the...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT