一个c# OO题 要做一个类 然后做筛选和添加 求大神帮我做

baidu_34846362 2016-04-30 11:00:58
这是要求Create a new class ‘DiscreteStock’ with the following features:
 Inherits from the Stock class;
 A private integer attribute named ‘_StoredStock’;
 A private integer attribute named ‘_ShelfStock’;
 A private double attribute named ‘_WeightPerItem’;
 Public read-only properties encapsulating the above attributes;
 A public custom constructor which accepts parameters for line (Line) and
weightPerItem (double) that passes the line parameter to the base class’ constructor
and initialises the above attributes (initialise both stored and shelf stock to zero);
 Implements/overrides the AdjustStock() method:
o If the quantity is a discrete quantity, add the specified quantity to stored stock;
o If the quantity is not a discrete quantity, it is ignored.
 Implements/overrides the Purchase() method:
o Determine the number of items to be purchased:
 If the quantity is a discrete quantity, the number of items to be
purchased will be the quantity specified;
 If no quantity is specified (null value) or the quantity specified is not a
discrete quantity, the number of items to be purchased will be a single
item (one item);
 If the number of items to be purchased exceeds the number of items on
the shelf (the shelf stock), then the number of items to be purchased is
reduced to be equal to the shelf stock, i.e., if you wanted to buy five items
but there was only three on the shelf, you could only buy three items;
o If the number of items to be purchased is zero, the item output parameter is set
to null and a value of false is returned;
o Otherwise the shelf stock is reduced by the number of items to be purchased
and the items output parameter is assigned an Item object created with
quantity set to the amount purchased, the line’s description, the weight set to
the total weight of those items (number of items * weight per item), and a value
of true is returned;
 Implements/overrides the Restock() method, where any stored stock is added
to/moved to the shelf stock;
 Overrides the ToString() method to return a string:
shelf stock
or if there is also stored stock:
shelf stock (stored stock in storage)


然后这是前面要用的类
1. using System;

namespace project1
{
class VolumeStockQuantity:StockQuantity
{
public VolumeStockQuantity(double Quantity)
{
Quantity = _quantity;
}
private double _quantity;
public double quantity
{
get { return _quantity; }
set { _quantity = value; }
}

}
}
2.using System;


namespace project1
{
abstract class StockQuantity
{
}
}

3.using System;


namespace project1
{
class DiscreteStockQuantity: StockQuantity
{
public DiscreteStockQuantity(int Quantity)
{
_quantity = Quantity;
}
private int _quantity;
public int quantity
{
get { return _quantity; }
set { _quantity = value; }
}


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

namespace project1
{
abstract class Stock
{
private Line _lines;
public Line lines
{
get { return _lines; }

set { _lines = value; }
}
public abstract void AdjustStock(StockQuantity quantity);
public abstract bool Purchase(StockQuantity quantity, out Item item);
public abstract void Restock();
}
}

图片里面是我做好的类

这是我写的代码
using System;

namespace project1
{
class DiscreteStock : Stock
{

public DiscreteStock(int StoredStock, int ShelfStock, double WeightPerItem)
{
_StoredStock = StoredStock;
_ShelfStock = ShelfStock;
_WeightPerItem = WeightPerItem;
}
private double _WeightPerItem;
public double WeightPerItem
{
get { return _WeightPerItem; }
}

private int _ShelfStock;
public int ShelfStock
{
get { return _ShelfStock; }

}

private int _StoredStock;
public int StoredStock
{
get { return _StoredStock; }
set { _StoredStock = value; }
}

private Line _Lines;
public DiscreteStock(Double WeightPerItem, Line _lines) {
base(_lines);
}
public override void AdjustStock(StockQuantity quantity)
{
foreach (DiscreteStock ds in _StoredStock)
if (ds is DiscreteStockQuantity)
StoredStock += Convert.ToInt32(DiscreteStockQuantity._quantity);



}

public override bool Purchase(StockQuantity quantity, out Item item)
{
return false;
}
public override void Restock()
{

}



好难啊好难啊好难啊
求论坛大神教我把这个类做完吧,我现在只学了多态和继承
教我吧教我吧,尽情的调教我吧
...全文
109 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧