gpt4 book ai didi

java - 找不到符号 - InventoryItem 类

转载 作者:太空宇宙 更新时间:2023-11-04 10:06:16 24 4
gpt4 key购买 nike

我从书中重新输入这些代码,不知怎的,我得到了错误“找不到符号 - InventoryItem 类”

import java.util.Scanner;

public class ReturnObject {
public static void main(String[] args) {
InventoryItem item;
item = getData();

System.out.println("Des: " + item.getDescription() + " Unit: " +
item.Units());

}

public static InventoryItem getData() {
String desc;
int units;
Scanner keyboard = new Scanner(System.in);
System.out.print("enter descri: ");
desc = keyboard.nextLine();
System.out.print("number of unit: ");
units = keyboard.nextInt();
return new InventoryItem(desc, units);
}
}

我是java新手,请帮忙谢谢。

最佳答案

我认为这应该是您需要的InventoryItem

 /**
* This class uses three constructors.
*/

public class InventoryItem {
private String description; // Item description
private int units; // Units on-hand

/**
* No-arg constructor
*/

public InventoryItem() {
description = "";
units = 0;
}

/**
* The following constructor accepts a
* String argument that is assigned to the
* description field.
*/

public InventoryItem(String d) {
description = d;
units = 0;
}

/**
* The following constructor accepts a
* String argument that is assigned to the
* description field, and an int argument
* that is assigned to the units field.
*/

public InventoryItem(String d, int u) {
description = d;
units = u;
}

/**
* The setDescription method assigns its
* argument to the description field.
*/

public void setDescription(String d) {
description = d;
}

/**
* The setUnits method assigns its argument
* to the units field.
*/

public void setUnits(int u) {
units = u;
}

/**
* The getDescription method returns the
* value in the description field.
*/

public String getDescription() {
return description;
}

/**
* The getUnits method returns the value in
* the units field.
*/

public int getUnits() {
return units;
}
}

complete example click herehere

关于java - 找不到符号 - InventoryItem 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52887021/

24 4 0
文章推荐: jquery - 在多个
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com