[不是问题]为可以通过咖啡店的销售点系统销售的商品设计和实施C#类。 [英] [Not a question] Design and implement a C# class for items that can be sold via a point-of-sale system for a coffee shop.

查看:62
本文介绍了[不是问题]为可以通过咖啡店的销售点系统销售的商品设计和实施C#类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为可以通过咖啡店的销售点系统销售的商品设计和实施C#类。设计并实现至少两个派生自您的第一堂课的其他类。每个类必须至少有一个方法和至少两个属性。确保派生类添加其他属性和/或方法。编写一个基于控制台或基于表单的示例应用程序,它实例化每个对象中的一个,并使用ToString方法(默认情况下为所有C#对象定义)在实例化时为每个类输出有意义的数据。通过控制台应用程序实例化该类,并显示该对象的详细信息(通过您实现的ToString方法)。



我不知道如何解决这个问题会不会有任何帮助?

解决方案

嗯。 ..拿垫和铅笔,开始考虑数据和类型



你有一个项目



所以,你有一个项目名称 - 字符串?,项目价格 - 双倍,数量左 - 整数..(例如)



你需要考虑一下这些应该是公共的,私人的(例如你的物品类),并且你需要使用get / set例如



那么想想你的操作d有 - '物品'是他们出售的 - 所以也许你有一个'卖'物品的方法 - 这需要花费多少单位出售,如果要求的数量更多则会产生某种错误比剩下的数量



你已经有了一个你需要的方法的线索 - ToString()



所以,我从也许开始



  public  Class Item 
{
public 字符串 itemName { get ; set ;}
public 十进制itemPrice { get ; set ;}
public Int itemQuantityLeft { get ; set ;}

public 覆盖 字符串 ToString()
{
字符串 readableItem =
字符串 .Format(
名称{0}价格{1}剩余数量{2}
itemName,itemPrice,itemQuantityLeft);
return readableItem;
}

}





但这是一个30秒的启动器 - 你需要实现一个构造函数,销售物品的方法,....似乎你有很多阅读要做


看到洞穴问题是我正在采取的课程首先使用头部进入C#第2版书籍,以及分配给我的问题,这本书绝对没有给我任何帮助。第一周是设计一个控制台,说你好世界很容易,第二周是在比赛中设计一个节目,这很疯狂,可能我应该放弃这个课程,谢谢大家的帮助。

Design and implement a C# class for items that can be sold via a point-of-sale system for a coffee shop. Design and implement at least two other classes derived from your first class. Each class must have at least one method and at least two attributes. Make sure your derived classes add additional attributes and/or methods. Write a sample application that is either console- or forms-based that instantiates one of each of your objects and use the ToString method (defined by default for all C# objects) to output meaningful data for each of your classes as they are instantiated. Instantiate that class via your console application and display (via a ToString method that you implement) the details of that object.

I have no idea how to go about this any help would be appreciated?

解决方案

Well ... take a pad and pencil, start thinking about the data and Types

You have an Item

So, you have an Item Name - String ?, Item Price - Double, Quantity Left - Integer .. (for example)

You'll need to think about wether these should be public, private (to your Item Class for instance), and wether you need to use get/set for example

Then think about what operations you'd have - 'Items' are sold arnt they - so maybe you'd have a method for 'selling' an item - that would take a quantity of how many units are being sold and throw some sort of error if the requested quantity is more than the quantity left

You already have a clue to one method you'll need - ToString()

So, I'd start with maybe

public Class Item
{
    public String  itemName {get; set;}
    public Decimal itemPrice {get; set;}
    public Int     itemQuantityLeft {get; set;}

    public override String ToString()
    {
        String readableItem = 
            String.Format(
                "Name {0} Price {1} Quantity Left {2}",
                itemName, itemPrice, itemQuantityLeft);
        return readableItem;
    }

}


but that's a 30sec starter - you need to implement a constructor, the method for Selling an Item, .... seems you have a lot of reading to do


see the hole problem is the course I am taking uses the head first into C# 2nd edition book, and problems assigned for me to do, the book absolutely gives me no help. the first week was to design a console that says hello world which was easy, the second week was to design a program a day at the races, which was just crazy, may bee I should just drop this class thanks for all your help everyone.


这篇关于[不是问题]为可以通过咖啡店的销售点系统销售的商品设计和实施C#类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆