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

CITP3310 Exam 3 Create a class called \"Fishing\" that has the following member

ID: 3732311 • Letter: C

Question

CITP3310 Exam 3 Create a class called "Fishing" that has the following member variables: A structure variable "Fish", included fishType: A string that will hold information about the fish type fishLength: A double that holds the fish length in inches > fish Weight: A double that holds the fish weight in pounds > actions: A string that will hold information on what to do with the fish. constructors: You should create two constructors. A constructor with no parameters (default constructor) and initialize variables. Also, create a second constructor that takes three In addition, the class should have the following member methods and properties. parameters, the fishType, fishLengh, and fish Weight. You don't have to use both constructors in the test program, you decide which one you want to use. properties: Appropriate properties should be created to allow values to be retrieved from an setAction: The SetActions method should determine what should be done with the fish based t's fi shType, fishLength, fish Weight and actions on the type, length, and weight using the criteria below display: display the fishType, fishLength, fish Weight and actions In the main function, create a fishing objects and let user input the fish information. Then, display the following menu: 1. InputData: create an InputData function (after main function) which let user input the fishType, fishLength, and fishWeight. Do not allow negative numbers for fishLength and fishWeight. The program will determine what should be done with this particular fish based on the criteria below 2. Display: use "Display" function in the Fishing class 3. Save: save the data to "FishInfo.txt" file Then prompt user to enter Y to continue or N to quit the program (use loop). Criteria: Weight Any fish less than 2 pound "throw back", otherwise: "keep" Length: FISHTYPE-Sheepshead

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
  static void Main(string[] args)
  {
   Fish fish;
   fish = new Fish();
   char value='Y';
   string choice;

   while (value == 'Y'){

    Console.WriteLine("1:InputData");
    Console.WriteLine("2:Display");
    Console.WriteLine("3:Save");
    Console.WriteLine("Enter Choice : ");
    choice = Console.ReadLine();
    switch (choice){

    case "InputData":
     fish = this.InputData();
     break;
    case "Display":
     this.Display();
     break;
    case "Save":
     this.Save();
     break;
    }
    Console.WriteLine("Do you want to continue : ");
    value = Console.ReadLine();
   }

   
   Console.WriteLine("Hello, world!");
   Console.ReadLine();
  }

  public Fish InputData(){

   Fish f;
   string fishType;
   double flength;
   double fweight;
   string action;
   int flag = 1;

   Console.WriteLine("Please enter fish type ");
   fishType = Console.ReadLine();
   while (flag == 1){

    Console.WriteLine("Please enter fish length in inches ");

    flength = double.Parse(Console.ReadLine());
    if (flength < 0){

     Console.WriteLine("Please enter fish length greater than 0 ");
    }
    else
     flag = 0;
   }
   flag = 1;

   while (flag == 1){

    Console.WriteLine("Please enter fish weight in pounds ");
    fweight = double.Parse(Console.ReadLine());
    if (fweight < 0){

     Console.WriteLine("Please enter fish weight greater than 0 ");
    }
    else
     flag = 0;
   }

   f = new Fish(fishType, flength, fweight);
   f.setAction();
   return f;

  }

  public void Display(){

   fish.Display();
  }

  public void Save(){

   fish.Save();
  }
}
}

struct Fish
{
private string fishType;
private double flength;
private double fweight;
private string action;

public Fish()
{
  this.fishType = "";
  this.flength = 0;
  this.fweight = 0;
  this.action = "";
}

public Fish(string fType,double flen,double fw)
{
  this.fishType = fType;
  this.flength = flen;
  this.fweight = fw;
  this.action = "";
}

public void Display(){

  Console.WriteLine("fish length in inches : " + fishType);
  Console.WriteLine("fish length in inches : " + flength);
  Console.WriteLine("fish weigth in pounds : " + fweight);
  Console.WriteLine("fish Action : " + action);
}
public void setAction(string Criteria)
{
  switch (Criteria){

  case "Weight":
   if (this.fweight < 2){

    this.action = "throw back";
   }
   else
    this.action = "keep";
   break;
  case "Length":
   if (this.fishType == "Sheepshead"){

    if (this.flenght < 15)
     this.action = "throw back";
    else if (this.flenght > 21)
     this.action = "tag";
    else
     this.action = "keep";
   }
   else if (this.fishType == "Red Drum"){

    if (this.flenght < 20)
     this.action = "throw back";
    else if (this.flenght > 28)
     this.action = "tag";
    else
     this.action = "keep";
   }
   else{

    if (this.flenght < 16)
     this.action = "throw back";
    else if (this.flenght >= 16)
     this.action = "keep";
   }
   break;
  }


}

public void Save(){

  File.AppendAllText("FishInfo.txt", this.fishType + " " + this.flength + " " + this.fweight + " " + this.action);
}
}