📄 inventoryitem.java
字号:
//********************************************************************
// InventoryItem.java Author: Lewis/Loftus
//
// Represents an item in the inventory.
//********************************************************************
import java.text.DecimalFormat;
public class InventoryItem
{
private String name;
private int units; // number of available units of this item
private float price; // price per unit of this item
private DecimalFormat fmt;
//-----------------------------------------------------------------
// Sets up this item with the specified information.
//-----------------------------------------------------------------
public InventoryItem (String itemName, int numUnits, float cost)
{
name = itemName;
units = numUnits;
price = cost;
fmt = new DecimalFormat ("0.##");
}
//-----------------------------------------------------------------
// Returns information about this item as a string.
//-----------------------------------------------------------------
public String toString()
{
return name + ":\t" + units + " at " + price + " = " +
fmt.format ((units * price));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -