⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invoice.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:

public class Invoice
    extends SortedList
    implements MenuUser
{
   protected static final String MENU[] =
       {
       "[A] Add Item", "[D] Delete Item", "[S] Show Invoice"};
   protected static final String TITLE = "Invoice Menu";
   protected String name;
   private Inventory inventory;

   public Invoice(Inventory _inventory, String _name)
   {
      super(new ItemComparer());
      inventory = _inventory;
      name = _name;
   }

   public void addItem()
   {
      InventoryItem item = inventory.getPart();
      int units = Util.getInt("Units");
      if ( (item != null) && (item.units >= units) && (units >= 0) && !isFull())
      {
         item.remove(units);
         add(new InvoiceItem(item, units));
      }
      else
      {
         System.out.println("List full, item not found or invalid units");
      }
   }

   public void delItem()
   {
      System.out.println(this);
      int index = indexOf(new Item(Util.getString("Enter item ID:")));
      if (index >= 0)
      {
         delete(index);
      }
   }

   public double getTotal()
   {
      double total = 0.0;
      for (int i = 0; i < getSize(); i++)
      {
         total += ( (InvoiceItem) get(i)).total;
      }
      return total;
   }

   public String toString()
   {
      return "\n" + name + ": " + Util.dollar(getTotal()) + super.toString();
   }

   public void performAction(String command)
   {
      if (command.equalsIgnoreCase("S"))
      {
         System.out.println(this);
      }
      else if (command.equalsIgnoreCase("A"))
      {
         addItem();
      }
      else if (command.equalsIgnoreCase("D"))
      {
         delItem();
      }
   }

   public static void main(String args[])
   {
      Menu menu = new Menu(TITLE, MENU, new Invoice(new Inventory(), "Test "));
   }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -