In: Computer Science
There are a number of national and state parks available to tourists. Create a Park class which should have name of park, location, type of (i.e., national, state, local) facility, fee, number of employees, number of visitors recorded for the past 12 months, and annual budget data members. Write instance methods that: a) Return a string representing name of the park, the location and type of park. b) Return a string representing the name of the park, the location and facilities available c) Compute cost per visitor based on annual budget and the number of visitors during the last 12 months. d) Compute revenue from fees for the past year based on number of visitors and fee.
using System;
namespace ParkExample
{
public class Park //park class
{
string park,location,type,facility; //required data
members
double fee;
int noemployees,noofvisitors;
double annualbudget;
public Park() //default constructor
{
park=location=type=facility=null;
fee=annualbudget=0;
noemployees=noofvisitors=0;
}
public Park(string park,string location,string
type,string facility, double fee,int noemployees,int
noofvisitors,double annualbudget) //constructor with
parameter
{
this.park=park; //assigning each
data member
this.location=location;
this.type=type;
this.facility=facility;
this.fee=fee;
this.noemployees=noemployees;
this.noofvisitors=noofvisitors;
this.annualbudget=annualbudget;
}
string getParkInfo() //get function1
{
return "Park name : "+park+",
Location : "+location+", Type : "+type;
}
string getParkFacilities() //get function2
{
return "Park name : "+park+",
Location : "+location+", Facilities : "+facility;
}
double getCostPerVisitor() //get cost per visitor
calculated
{
return
annualbudget/noofvisitors;
}
double getRevenue() //getting total revenue
{
return noofvisitors*fee;
}
public override string ToString() //overrided
ToString() function from Object class
{
return "Park Information : \n"+getParkInfo()+"\nPark
Facilities : \n"+getParkFacilities()+"\nCost per Visitor :
"+getCostPerVisitor()+"\nRevenue :
"+getRevenue();
}
}
class MainClass
{
public static void Main (string[]
args)
{
Park p=new
Park("Theme park","New Delhi","Entertainment","Swings,
slides",50,15,100,105674); //create park object
Console.WriteLine(p); //printing object of park p
}
}
}
***********************************************************************************************************************************
In case of any doubt do ask in the comment section.Hope you like it