Answer: Provided in the section below
Explanation:
Using C# Code:
using System;
class Environment{
//temperature
private double temp;
//sets initial value of temp to 100 Fahrenheits
public Environment(){
temp=100;
}
//sets initial value to given temp
public Environment(double t) {
this.temp = t;
}
//returns temp
public double getTemp(){
return temp;
}
//calculates temp at given frequency
public void calcTemperature(double frequency){
temp=(frequency+40)/4.0;
}
}
class Cricket{
private Random r=new Random();
//frequency of birds
protected double frequency;
//sets frequency to a random value between 0-100
public Cricket(){
frequency=r.NextDouble()*100;
}
//sets frequency to a given frequency
public Cricket(double f) {
frequency = f;
}
//returns the frequency
public double getFrequency() {
return frequency;
}
//randomize the frequency
public virtual void randomFrequency() {
frequency = r.NextDouble()*100;
}
}
class ClemsonCricket: Cricket{
//sets the frequency to 80% of the parent's
public ClemsonCricket(): base(){
frequency=frequency*0.8;
}
//sets frequency to a given frequency
public ClemsonCricket(double f): base(f){}
//randomize frequency and sets it to 80% of the parent's
public override void randomFrequency(){
base.randomFrequency();
frequency=frequency*0.8;
}
}
public class testCrickets {
static void Main(){
Environment env=new Environment();
Console.WriteLine("Initial Temp: "+env.getTemp());
Cricket cricket=new Cricket();
env.calcTemperature(cricket.getFrequency());
Console.WriteLine(String.Format("Temp before changing Frequency: {0:0.00}",env.getTemp()));
cricket.randomFrequency();
env.calcTemperature(cricket.getFrequency());
Console.WriteLine(String.Format("\nTemp after changing Freqency: {0:0.00}",env.getTemp()));
Console.WriteLine("\nClemson Cricket: ");
ClemsonCricket clemsonCricket=new ClemsonCricket();
env.calcTemperature(clemsonCricket.getFrequency());
Console.WriteLine(String.Format("Temp before changing Frequency: {0:0.00}",env.getTemp()));
clemsonCricket.randomFrequency();
env.calcTemperature(clemsonCricket.getFrequency());
Console.WriteLine(String.Format("\nTemp after changing Freqency: {0:0.00}" ,env.getTemp()));
Console.WriteLine("\nPolymorphism Clemson Cricket: ");
Cricket Ccricket=new ClemsonCricket();
env.calcTemperature(Ccricket.getFrequency());
Console.WriteLine(String.Format("Temp before changing Frequency: {0:0.00}",env.getTemp()));
Ccricket.randomFrequency();
env.calcTemperature(Ccricket.getFrequency());
Console.WriteLine(String.Format("\nTemp after changing Freqency: {0:0.00}",env.getTemp()));
}
}
cheers i hope this helped !!