c#构造一个类。很急的,希望大家帮帮忙,谢谢

能选择不同的构造函数来初始化类的实例,同时具有如下功能:记录和访问书店图书信息,包括标题、作者、批发价、库存量、零售价。其中,要求体现批发价为零售价的70%
刚刚学c#,请大家能说的仔细点,最好有代码

using System;
using System.Collections.Generic;
using System.Text;

namespace shuzu
{
class Book
{
private readonly string isbn;
private string title;
private string author;
private double tradePrice;
private string stockNumber;
private double salePrice;

public Book(string isbn)
{
this.isbn = isbn;
this.title = "未知";
this.author = "未知";
this.tradePrice = 0;
this.stockNumber = "未知";
this.salePrice =0;
}
public Book(string isbn, string title, string author, double tradePrice, string stockNumber, double salePrice)
{
this.isbn = isbn;
this.title = title;
this.author = author;
this.tradePrice = tradePrice;
this.stockNumber = stockNumber;
this.salePrice = salePrice;
}
public string ISBN
{
get { return isbn; }
}
public string Title
{
get { return title; }
set { title = value; }
}
public string Author
{
get { return author; }
set { author = value; }
}
public double TradePrice
{
get { return salePrice; }
set { tradePrice = value; }
}
public string StockNumber
{
get { return stockNumber; }
set { stockNumber = value; }
}
public double SalePrice
{
get { return salePrice; }
set { salePrice = value; }
}
public void show()
{
Console.WriteLine("书号:{0}", isbn);
Console.WriteLine("标题:{0}", title);
Console.WriteLine("作者:{0}", author);
Console.WriteLine("批发价(零售价的70%):{0}", 7*salePrice/10);
Console.WriteLine("库存量:{0}", stockNumber);
Console.WriteLine("零售价:{0}", salePrice);
}
class Text
{
static void Main(string[] args)
{
Console.WriteLine("请输入isbn书号:");
Book book1 = new Book(Console.ReadLine());
book1.show();
Console.ReadLine();

Console.WriteLine("请输入标题:");
book1.Title = Console.ReadLine();
Console.WriteLine("请输入作者:");
book1.Author = Console.ReadLine();
Console.WriteLine("请输入库存量:");
book1.StockNumber = Console.ReadLine();
Console.WriteLine("请输入零售价:");
book1.SalePrice = Convert.ToDouble(Console.ReadLine());
book1.show();
}

}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-06
首先,你要有存取图书的数据库,才能进行存取和读取的操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Book
/// </summary>
public class Book
{
private string bookId;
/// <summary>
/// 编号
/// </summary>
public string BookId
{
get { return bookId; }
set { bookId = value; }
}
private string title;
/// <summary>
/// 标题
/// </summary>
public string Title
{
get { return title; }
set { title = value; }
}
private string author;
/// <summary>
/// 作者
/// </summary>
public string Author
{
get { return author; }
set { author = value; }
}
private decimal tradePrice;
/// <summary>
/// 批发价
/// </summary>
public decimal TradePrice
{
get { return SalePrice > 0 ? 7/10*SalePrice : tradePrice; }
set { tradePrice = value; }
}
private string stockNumber;
/// <summary>
/// 库存量
/// </summary>
public string StockNumber
{
get { return stockNumber; }
set { stockNumber = value; }
}
private decimal salePrice;
/// <summary>
/// 零售价
/// </summary>
public decimal SalePrice
{
get { return salePrice; }
set { salePrice = value; }
}
public Book()
{
//
// TODO: Add constructor logic here
//
}
public Book(string Title, string Author)
{
this.title = Title;
this.author = Author;
}
}
第2个回答  2011-04-07
构造函数里可以带不同的参数,构造函数可以不止一个。,但是一个类只允许有一个同名的构造函数。

bhq0326的回答比较好
第3个回答  2011-04-13
构造函数是在类进行实例化(new)时便执行的,是由访问级别、类名构成的,当然他也可以像方法一样在方法名相同的情况下,含有多个输入参数,构成方法重载,楼上说的都很好,补充这些
希望对你理解有所帮助
第4个回答  2011-04-04
直接弄个book类不就行了吗?记录的工作交给数据库
相似回答
大家正在搜