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

Program 1 – (15 points) Create a program with the following OO structure. You do

ID: 3588543 • Letter: P

Question

Program 1 – (15 points)

Create a program with the following OO structure. You do not have to implement any of the methods other than constructors to fill in some default data. You should implement the rest of the methods with a Console.WriteLine to indicate that it has been called.

Within a UNIVERSITY there are 4 DEPARTMENTS MATH, ENGLISH, GEOGRAPHY, COMPUTERSCIENCE

Each DEPARTMENT has up to 10 STAFF

There is a DEAN, PROFESSORs, ADMINISTRATORs and RESEARCHERs

All Staff should have a name and salary

Professors should have a Class

Researchers should have a ResearchSpeciality which is a fixed set of research areas represented by an enumeration Deans, Professors and Researchers should implement an ITeachable interface which contains the Teach() method Deans and Administrators should implement an IAdmin interface which contains the Administrate() method

Pay special attention to the IS­A relationships and the HAS­A relationships and implement things correctly.

You should determine reasonable types for all properties not otherwise specified and initialize things with sensible defaults. Your constructors should have reasonable parameters to set up the type where you cannot simply use constants.

var u = new University() Console.WriteLine(u.Department[2].Staff[3].Name)

u.Department[1].Staff[0] = new Researcher("Andy")

You should create additional test code to make sure that all of the properties and methods are available.

Program 2 – (20 points)

Create a class for an inventory system for an RPG. Your solution should contain the following classes

An Interface called IContainer ­ items that implement IContainer can have other things put inside them

Add method ­ adds an item to the container. You may NOT calculate or store the totals for the container here TotalCount property ­ returns how many items are in the container including any containers inside. You MUST calculate the totalCount recursively when this method is called

TotalWeight property ­ returns the total weight of the container including any containers inside. You MUST calculate the totalWeight recursively when this method is called

A class called Inventory that implements IContainer

The constructor should pass in the number of items in the inventory An abstract base class called Item

Each item should have a cost and a weight property

Several inherited objects from a typical RPG. Each item should have a different cost and weight A BagOfHolding class which inherits from Item and implements IContainer

You should write some test code to test all of your classes. For example, it might look something like this. Make sure that you test the recursive TotalCount and TotalWeight methods

var inventory = new Inventory(3); inventory.Add(new Sword()); inventory.Add(new Potion());

var bagOfHolding = new BagOfHolding(4); inventory.Add(bagOfHolding); bagOfHolding.Add(new Sword());

Console.WriteLine( "The number of items in the inventory is {0} ", inventory.TotalCount); //There a Console.WriteLine( "The total weight of the inventory is {0} ", inventory.TotalWeight); //Weight wil

Explanation / Answer

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sem3_ex2 {
    class Program {
        static void Main(string[] args) {

            // Create Inventory, add things to it.
            Inventory obj = new Inventory(5);
            addInventory(obj); // adds 5 items to inventory.

            // Create Holding Bag
            var bagOfHolding = new BagOfHolding(5);

            // Add 'Bag' to inventory
            obj.add(bagOfHolding);

            // Add things to Bag.
            addToBag(bagOfHolding);

            // Print Inventory Data.
            printInventoryTotal(obj);
            printWeightTotal(obj);
            Console.Read();
        }
        public static void addInventory(Inventory x) {
            x.add(new sword());
            x.add(new potion());
            x.add(new wand());
            x.add(new cloak());
            x.add(new hammer());
        }
        public static void addToBag(BagOfHolding x) {
            x.add(new sword());
            x.add(new potion());
            x.add(new wand());
            x.add(new cloak());
            x.add(new hammer());
        }
        public static void printInventoryTotal(Inventory x) {
            Console.WriteLine(" ");
            Console.WriteLine("Total Number of Items in" +
                                $" Inventory: {x.totalItems}");
        }
        public static void printWeightTotal(Inventory x) {
            Console.WriteLine($"The Total Weight is: {x.totalWeight()} pounds");
        }
  
    }

    interface IContainer {
        // IContainer Interface
        void add(Item x);
        int totalCount();
        double totalWeight();
    }
    abstract class Item {
        // Abstract BASE class
        double cost, weight;

        public string costToString(int x) {
            string amount = x.ToString("C2");

            return amount;
        }
        public void setCost(int x) { cost = x; }
        public double getCost() { return cost; }
        public void setWeight(int x) { weight = x; }
        public double getWeight() { return weight; }
    }
    class Inventory : IContainer {
        // Inventory Class
        public int totalItems = 0;
        public double Weight = 0;

        public Inventory(int x) {
            // Constructor
            totalItems = x;
        }
        public void add(Item x) {
            // Add Item to Container
            // totalItems = totalItems + 1;
            Weight = totalWeight() + x.getWeight();
        }
        public int totalCount() {
            // Calculate recursively
            return totalItems;
        }
        public double totalWeight() {
            // Calculate recursively
            return Weight;
          
        }
        public int getTotalItems() { return totalItems; }
    }
    class BagOfHolding : Item, IContainer {
        // BagOfHolding Class
        int size, weight ;
        public BagOfHolding(int x) {
            // Constructor
            size = x;
            weight = 0;
        }

        public void add(Item x) {
            // Add Item to Container
            totalCount();
            totalWeight();
        }
        public int totalCount() {
            // Calculate recursively
            return size; // filler
        }
        public double totalWeight() {
            // Calculate recursively
            return weight; // Filler
        }
    }
  
}

items.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sem3_ex2 {
    class sword : Item {
        public sword() {
            setCost(500);
            setWeight(5);
        }
    }
    class potion : Item {
        public potion() {
            setCost(700);
            setWeight(1);
        }
    }
    class wand : Item {
        public wand() {
            setCost(1000);
            setWeight(2);
        }
    }
    class cloak : Item {
        public cloak() {
            setCost(200);
            setWeight(3);
        }
    }
    class hammer : Item {
        public hammer() {
            setCost(200);
            setWeight(5);
        }
    }
}

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