【发布时间】:2017-04-24 14:05:27
【问题描述】:
这是我需要做的事情
编写一个构造函数,该构造函数接受四个字段的参数、每个字段的 mutator 方法和每个字段的访问器方法。此外,编写一个实例方法来计算该库存项目的总值。您可以通过将 numberOnHand 乘以价格来计算总值,并将该值作为双精度值返回。
这个程序大部分已经被淘汰了,但我不知道如何让它成为它应该的样子。
这是给我的。
public PetStoreInventory(String s, String d, int units, double p) {
//your code goes here
}
public void setDescription( String s){
//your code goes here
}
public void setDepartment( String d){
//your code goes here
}
public void setUnitsOnHand ( int units){
//your code goes here
}
public void setPrice ( double p ){
//your code goes here
}
public String getDescription(){
return ""; //so it compiles, you must change this
}
public String getDepartment(){
return ""; //so it compiles, you must change this
}
public int getUnitsOnHand(){
return 0; //so it compiles, you must change this
}
public double getPrice(){
return 0.0; //so it compiles, you must change this
}
public double calcTotalValue(){
return 0.0; //so it compiles, you must change this
}
【问题讨论】:
-
您尝试了哪些方法,哪些方法不起作用? “这是我的作业,我该怎么做?”不是一个真正可以回答的问题。如果你想学习如何用 Java 编写代码,那么你应该从一些 Java 教程开始。
-
填空即可。谷歌一下 setter 和 getter 是什么,你将完成 75% 的工作。
-
首先创建您需要在表中存储前 4 列的四个字段。换句话说,你需要在类本身中存储 (String s, String d, int units, double p)。
标签: java constructor inventory