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

In C#. Create a class called Item which contains the following private variables

ID: 3732752 • Letter: I

Question

In C#.

Create a class called Item which contains the following private variables:

string name; // Will be received from files.

int weight; //random number from 1-10

The class Weapon is derived from Item. The variable for that class is

int atk; //random number from 1-10

The class Armor is derived from Item. The variable for that class is

int def; //random number from 1-10

You will have 2 files. One called "Weapons.txt" which has the following:

Sword

Dagger

Bow

Lance

Mace

The "Armors.txt" file has the following data

Helmet

Chest Plate

Mail Vest

Cloth Robe

Shield

Your program should create ONE array of 10 Items (no other arrays will be created and files will be closed after all 10 items are received from file). The computer will select the order the items are placed in the array Randomly. (You can try getting a random number between 1 and 2, if it is a 1 you place the next weapon from file while if it is a 2, you place the next armor... though be aware there will be a time when you already received all items from either the weapon or armor file, in which case you get the remainder items from the non-empty file to fill in the rest of the array).

You should then sort the Items based on Damage per minute and Armor per minute (do not separate the weapons and armors from the array, you will sort based on the DPM and APM numeric value). Basically some math will need to be done to get these values based on the following.

if the weight is 1, he can attack 10 times per minute. for each extra weight, he can attack one time fewer as shown in the following (defense works with similar formula):

Weight = 1, 10 attacks per minute.

Weight = 2, 9 attacks per minute.

Weight = 3, 8 attacks per minute.

Weight = 4, 7 attacks per minute.

Weight = 5, 6 attacks per minute.

Weight = 6, 5 attacks per minute.

Weight = 7, 4 attacks per minute.

Weight = 8, 3 attacks per minute.

Weight = 9, 2 attacks per minute.

Weight = 10, 1 attack per minute.

This means if the random number for weight is 7, he can attack 4 times in one minute. This multiplied by the weapon atk gives you the damage per minute.

Display (Neatly) all the content of the Item array on the screen( name, weight, atk/def and attack/armor per minute). You will then send the following to the Screen:

1. The weapon with the strongest Damage per minute along with the name, weight, attack and damage per minute.

2. The armor with the strongest Armor per minute along with the name, weight, defense and armor per minute.

Explanation / Answer

using System;

using System.Text;

namespace Creating_Class

{

class item //creating class

   {

      public string name;

       public int weight;

       public weightvalues(int wgt)

         {    int apm;

                switch (wgt)

                   {

                      case 1 : apm =10;break;

                      case 2 : apm =9;break;

                      case 3 : apm =8;break;

                      case 4 : apm =7;break;

                      case 5 : apm =6;break;

                      case 6 : apm =5;break;

                      case 7 : apm =4;break;

                      case 8 : apm =3;break;

                      case 9 : apm =2;break;

                      case 10 : apm =1;break;

                   }

         }

   }

class weapon   // creating class

   {

      public int atk;

      public void weapondetails()

        {

            string[] w = System.IO.File.ReadAllLines(@"C:UsersPublicTestFolderWeapons.txt");

        }

   }

class armor // creating class

   {

      public int def;

public void armordetails()

        {

            string[] a = System.IO.File.ReadAllLines(@"C:UsersPublicTestFolderArmors.txt");

        }

   }

class program // creating class

   {

      static void main(string[] args)

        {

            item it= new item();

            weapon we = new weapon();

            armor arm = new armor();

             we.weapondetails();

             arm.armordetails();

                int j=0;k=0,i=0;

           for(i=0;i<10;i++)

          {

             Console.WriteLine("enter a random number for waepon class " + we.atk);

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

            Console.WriteLine("enter a random number for armor class " + arm.def);

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

            Console.WriteLine("weight is " + it.weight);

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

            Console.WriteLine("enter a random number 1 or 2" );

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

             if (rand==1)

                {   

                       string[] array_item[i] = w[j];

                       j++;

                      Console.WriteLine(array_item[i]);

                }

             else if(rand==2)

               {

                       string[] array_item[i] = a[k];

                       k++;

                     Console.WriteLine(array_item[i]);

                }

     

       int dpm = we.atk * it.weightvalues(at);

     int apm = arm.def * it.weightvalues(at);

      Console.WriteLine(dpm);

      Console.WriteLine(apm);

}

        }

    }

}