Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using C# Create a class called Insurance that contains 3 pieces of information a

ID: 3885518 • Letter: U

Question

Using C#

Create a class called Insurance that contains 3 pieces of information as instance variables: name (datatype string), number of customers (datatype int), state where corporate headquarters are located (datatype string).

Create a constructor that initializes the 3 instance variables. The Insurance class must contain a C# property for each instance variable for get and set. These are not java access and mutators. The property for number should verify that the Insurance customers is greater than zero. If a negative value is passed in, the set accessor should set the Insurance number to 0.

Create a second class Insurance Test that prompts the user for information to create two Insurance objects using the constructor that you developed in the Insurance class. Display the name, number of customers, home state.  

Explanation / Answer

using System;

public class Insurance {

private string name;

private int noOfCust;

private string location;

/* Getters for member variable */

public string getName() { return name; }

public int getNoOfCust() { return noOfCust; }

public string getLocation() { return location; }

/* Setters for member variable */

public void setName(string n) { name = n;}

public void setNoOfCust(int cust) {

if (cust < 0)

{ noOfCust = 0;}

else {noOfCust = cust;}

}

public void setLocation(string l) {location = l;}

/*Parametrized constructor */

public Insurance(string n, int cust, string l) {

setName(n);

setNoOfCust(cust);

setLocation(l);

}

}

public class InsuranceTest

{

public static void Main()

{

string name, location;

int count;

/* Read Input from Console for first Insurance Object*/

Console.WriteLine("Enter Name ");

name = Console.ReadLine();

Console.WriteLine("Enter Number of Customer ");

count = int.Parse(Console.ReadLine());

Console.WriteLine("Enter Location ");

location = Console.ReadLine();

Insurance obj = new Insurance(name,count,location); //Create Insurance Object

/*Display first Insurance Object */

Console.WriteLine("Name {0}",obj.getName());

Console.WriteLine("Number of Customer {0}",obj.getNoOfCust());

Console.WriteLine("Location {0}", obj.getLocation());

/* Read input from Console for Second Insurance Object */

Console.WriteLine("Enter Name ");

name = Console.ReadLine();

Console.WriteLine("Enter Number of Customer ");

count = int.Parse(Console.ReadLine());

Console.WriteLine("Enter Location ");

location = Console.ReadLine();

/*Create second Insurance object */

Insurance obj1 = new Insurance(name,count,location);

/*Display information of second Insurance Object*/

Console.WriteLine("Customer's Name {0}",obj1.getName());

Console.WriteLine("Number of Customer {0}",obj1.getNoOfCust());

Console.WriteLine("Location {0}", obj1.getLocation());

}

}

Sample Output :

Enter Name
Ro
Enter Number of Customer
12
Enter Location
DEL
Name Ro
Number of Customer 12
Location DEL
Enter Name
Hello World
Enter Number of Customer
-2
Enter Location
NY
Customer's Name Hello World
Number of Customer 0
Location NY

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote