Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoingOutOfBusiness
{
    public class OnlineStore : IOnlineStore
    {
        List<producttype> stock = new List<producttype> {new ProductType("Lenovo", "Ps32", "2021", "This is a smart tablet 15 inch screen", 20, 14.8), new ProductType("ASUS", "ASUS-G4", "2021", "This is a gaming laptop", 4, 34.9), new ProductType("Samsung", "S21", "2021", "This is a smart phone", 5, 45.8) };
        

        public void AddProductsToInventory(ProductsPurchaseOrder purchaseOrder)
        {
            throw new NotImplementedException();
        }

        public InventoryItemSummary GetInventoryItemSummary(ProductType stockType)
        {
            InventoryItemSummary product = new InventoryItemSummary(product, model, year, description, count, price);
            stockType.product = "Check product description below";
            stockType.price = 13.56;

            foreach (var summary in stock)
            {
                Console.WriteLine(summary);
            }
            return null;
        }

        public InventorySummary GetInventorySummary()
        {
            InventorySummary InventoryItem = new InventorySummary();
            InventoryItem.Item = "This is all the items in the inventory";
            

            foreach (var item in stock)
            {
                Console.WriteLine(item);
            }
            return InventoryItem;

        }


        public ProductSoldResult SellProdcutsFromInventory(ProductsSellOrder itemsSoldOrder)
        {
            ProductSoldResult itemSoldOrder = new ProductSoldResult();
            itemsSoldOrder.soldProduct = "The item has been sold";

            foreach (var item in stock)
            {
                Console.WriteLine(item);
            }
            return stock;
        }
    }
}


////////////////////////////////////////////////////////////////////////////////////////
                                     the next class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoingOutOfBusiness
{
    public class ProductType
    {
        public string product { get; set;}

        public string model { get; set;}

        public string year {get; set;}

        public string description { get; set; }

        public int count { get; set; }

        public double price { get; set; }

        public ProductType( string product, string model, string year, string description, int count, double price)
        {
            this.product = product;
            this.model = model;
            this.year = year;
            this.description = description;
            this.count = count;
            this.price = price;
        }

        public override string ToString()
        {
            return "Current brand in inventory: " + product + ", " + description + "\n";
        }

    }
}

////////////////////////////////////////////////////////////////////////////////////////
                                     the main method

using System;

namespace GoingOutOfBusiness
{
        public class Program
        {
        static void Main()
        {
            OnlineStore obj = new OnlineStore();
            var InventoryItem = obj.GetInventorySummary();
            Console.WriteLine(InventoryItem.Item);


            //obj.AddProductsToInventory();

            OnlineStore obj2 = new OnlineStore();
            var itemSummary = obj2.GetInventoryItemSummary();
            Console.WriteLine(itemSummary.stockType + " \nthis is the current price: " + itemSummary.price);



            OnlineStore obj3 = new OnlineStore();
            var SoldItem = obj.SellProdcutsFromInventory();
            Console.WriteLine(SoldItem.SoldItem + " Item sold.");


        }
       
    }


What I have tried:

I will add I'm new to C#, I have done a bit of Java before but never to this extent.

I am getting the cs7036, cs0029 errors specifically. This is the class library for the interface, I am trying to implement the stockType now and then purchaseOrder later on.

if you have an idea of what I need to do please assist otherwise, I can use google meet or discord if you wish to see the code upfront.

thank you
Posted
Updated 12-Oct-21 2:37am
v2

If you don't understand an error, google it:
cs7036 - Google Search[^]
cs0029 - Google Search[^]
And use the line numbers the error message includes to identify exactly where in yoru code the error occurs - I have no idea without trying to compile you app, and I don't have the full project (including forms and so forth) to do that under teh same conditions you do.

But one thing does sprint out at me:
InventoryItemSummary product = new InventoryItemSummary(product, model, year, description, count, price);
How do you expect that to work?
You are trying to create a variable called product and set it to a new instance of a class using the variable itself as part of the instance constructor call.
You can't do that: It's like saying "I want a new car and I'll use it as a trade in to buy it".
 
Share this answer
 
Comments
awesome786 12-Oct-21 7:51am    
well I did remove that snippet, do you want me to send you the entire code? and I have googled the errors but as I have said before its not something I easily understand on how to fix.
OriginalGriff 12-Oct-21 7:57am    
No, these are syntax errors, and you really do need to learn how to fix them - because you are going to meet them every time you code, almost certainly! And it's a lot quicker to fix them yourself than to wait hours for someone else to do it for you ... we all get them, we all fix them!

Start in VS by double clicking on the error - it will go directly to the line that has the problem.
Look at it closely. Is it calling a method? If so, what parameters is it trying to pass? What parameters are defined by the method when you create it? Do they match?

If you can;t work it out, copy and paste the entire error, and show us which line it complains about, with a couple of lines above and below for context.
awesome786 12-Oct-21 8:02am    
ok il try that and see how far I go but is it possible to have a code like this //
className methodName(className parameter)//
OriginalGriff 12-Oct-21 8:17am    
I'm not quite sure what exactly you mean by that - it doesn't seem to make much sense.

What are to trying to achieve with that pseudocode?
Dave Kreskowiak 12-Oct-21 8:34am    
Yes, you can, but in your case, why would you want to?

That line of code suggests a parent-child relationship, like you would find in a tree structure. Every branch of a tree can also contain other branches, but in all cases, every object is a "Branch".

This is not something you would find in a shopping site.
C#

namespace GoingOutOfBusiness
{

public interface IOnlineStore
{

void AddProductsToInventory(ProductsPurchaseOrder purchaseOrder);
// add products to the inventory list

ProductSoldResult SellProdcutsFromInventory(ProductsSellOrder itemsSoldOrder);
// remove products from the inventory list

InventoryItemSummary GetInventoryItemSummary(ProductType stockType);
// className methodName (className parameter)
// show specifics about a product

InventorySummary GetInventorySummary();
// show all inventory
}
}

that is the interface code given to me, I want to know how I can implement the line starting with InventoryItemSummary, I have commented the type of code it is underneath.

I'm trying call the method GetInventoryItemSummary() with the class ProductType having a parameter of stockType, which stockType in the class ProductType is an object.
C#

 
Share this answer
 
Comments
Dave Kreskowiak 12-Oct-21 9:04am    
You're focusing on a comment that means nothing in the context of implementing an interface in your own class.

That code should have been given to you like this:
namespace GoingOutOfBusiness
{
        public interface IOnlineStore
        {
	        // add products to the inventory list            
	        void AddProductsToInventory(ProductsPurchaseOrder purchaseOrder);

	        // remove products from the inventory list
	        ProductSoldResult SellProdcutsFromInventory(ProductsSellOrder itemsSoldOrder);

	        // show specifics about a product
	        InventoryItemSummary GetInventoryItemSummary(ProductType stockType);

	        // show all inventory            
	        InventorySummary GetInventorySummary();
        }
}
awesome786 12-Oct-21 9:12am    
but lets say for example ProductSoldResult line, how would I implement ProductsSellOrder in the method SellProductsFromInventory??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900