参数与构造函数的数据类型不匹配 [英] arguments don't match datatype of constructor

查看:111
本文介绍了参数与构造函数的数据类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我一直试图让我的库存程序编译,但没有运气。我的讲师告诉我,Inventory3类中的参数需要匹配Product类中构造函数的数据类型。我确信这是一件相当简单的事情,我应该能够弄清楚,但我在努力完成这项工作。有没有人有什么建议?我的代码如下。非常感谢任何提前建议的人!!

Hi! I''ve been trying to get my inventory program to compile, but haven''t had any luck. My instructor tells me that my arguments in the Inventory3 class need to match the datatype of the constructor in my Product class. I''m sure this is something rather simple that I should be able to figure out, but I''m at my wits end trying to make this work. Does anyone have any suggestions? My code is below. Thanks so much to anyone with advice in advance!!

展开 | 选择 | Wrap | 行号

推荐答案

嘿,下次还会发布你在尝试编译时遇到的错误,这会帮助别人。


在inventory3中看到你在调用新产品(bla bla)


你不是说新塑料吗?


看看,在库存3中你写的是:



"产品item1 =新产品(1003182," Polytrope TPP",7,1.81,& ;黑色);


这是Product(int,string,int,double,string),但是看看你的产品的构造函数,就像老师说的那样,它是不匹配的,就像这样,来自你的代码:


" public Product(int itemNumber,String itemName,int stock,double price)"


我想知道的那个字符串......你正在扩展类塑料,类塑料的构造函数来自你的代码:


" public Plastic(int itemNumber,String itemName,int stock,double price,String itemColor)"


所以我相信你想输入:

Hey, next time also post the errors you''re getting when you try to compile, that would help people out.

See in inventory3 where you''re calling new Product(bla bla)

Don''t you mean new Plastic?

See, in inventory3 you''re writing this:


"Product item1 = new Product (1003182, "Polytrope TPP", 7, 1.81, "Black" );"

which is Product (int, string, int, double, string), but looking at your product''s constructor, like your teacher said, it doesn''t match, it''s like this, from your code:

"public Product (int itemNumber, String itemName, int stock, double price)"

Where''s that string I wondered... you''re extending class Plastic and the constructor for class plastic is from your code:

"public Plastic ( int itemNumber, String itemName, int stock, double price, String itemColor )"

So I believe you wanted to type:

展开 | 选择 | Wrap | 行号



嗨!我一直试图让我的库存程序编译,但没有运气。我的讲师告诉我,Inventory3类中的参数需要匹配Product类中构造函数的数据类型。我确信这是一件相当简单的事情,我应该能够弄清楚,但我在努力完成这项工作。有没有人有什么建议?我的代码如下。非常感谢任何提前建议的人!!

Hi! I''ve been trying to get my inventory program to compile, but haven''t had any luck. My instructor tells me that my arguments in the Inventory3 class need to match the datatype of the constructor in my Product class. I''m sure this is something rather simple that I should be able to figure out, but I''m at my wits end trying to make this work. Does anyone have any suggestions? My code is below. Thanks so much to anyone with advice in advance!!

展开 | 选择 | Wrap | 行号


你们超级...谢谢 - 那很有效!我的程序现在编译,但它没有给我正确的输出。这是我得到的而不是清单项目列表及其各自的详细信息:


[LProduct; @ 42e816


[LProduct; @ 42e816


[LP产品; @ 42e816


[LP产品; @ 42e816


价值所有项目合并为:
You guys are super ... thanks - that worked! My program compiles now, but it''s not giving me the correct ouput. This is what I get rather than a list of inventory items with their respective details:

[LProduct;@42e816

[LProduct;@42e816

[LProduct;@42e816

[LProduct;@42e816

The Value of all items combined is:


这篇关于参数与构造函数的数据类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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