user input to create object

一世执手 提交于 2019-12-02 05:28:48

It depends in how is SodaMachine class implemented. If the constructor of SodaMachine expects String, int, double parameters, call the constructor passing them without specifying the type. Note that it's not necessary to set (using setCostOfBottle(), ...) the members again, because that's why you are passing the variables to the constructor.

SodaMachine one = new SodaMachine(soda, product, cost);

If your constructor doesn't accept parameters:

SodaMachine one = new SodaMachine();

and set the members later:

one.setCostOfBottle(cost);
one.setInventory(product);
one.setNameOfSoda(soda);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!