热门为我的程序JAVA上课

时间:2014-01-25 23:10:03

标签: java class

好的,所以我一直在制作我的这个程序,从头开始获取一些库存数据,因为教授的帮助代码是垃圾。但我有点卡住了。正如你在下面看到的,我的代码将把一些字符串传递给一个名为address的类,它基本上将该信息编译成一个变量。

但是我需要一些帮助来写这个课程,现在我知道这里的大部分海报都不会为我编写代码。我不是要你为我写的,我要求你告诉我如何做到这一点,举个例子。这对我很有帮助。这也意味着以后我可以让制造商独自一人,虽然我知道我会搞砸它。

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

class Inventory
{
    public static void main(String arg[])
    {
        Database db = new Database();
        Database dpl = new Database();

final String[] MENU_OPTIONS = {"exit", "Add product", "Sell product", "Delete product", "Modify product",
                               "Display information"};
final String MENU_NAME = "Inventory";

boolean active = true;

        while(active)
        {


String selection = promptInventory(MENU_NAME, MENU_OPTIONS);

//logic


      switch ( selection )
      {
         case  "exit"         : active = false;
                             break;

         case  "Add product"  : // Creating an order and adding this order to the database
                                 IO.display("Add new product", "New product", JOptionPane.INFORMATION_MESSAGE);
                                String street = IO.getWord("Enter street address");
                                String city = IO.getWord("Enter city");
                                 String state = IO.getWord("Enter state");
                                 String zip = IO.getWord("Enter zip code");
                                Address addr = new Address(street, city, state, zip);

                                // Company stuff
                                String company_name =  IO.getWord("Enter name of the company");
                                 Manufacturer m = new Manufacturer(addr, company_name);



                             break;

         case  "Sell product" : 
                             break;

      }//switch

  }//while loop    

}//main

public static String promptInventory(String MName, String[] options)
   {
      int selection = JOptionPane.showOptionDialog(null, 
                                             "Enter your Transaction Type",
                                             MName,
                                             JOptionPane.DEFAULT_OPTION,
                                             JOptionPane.QUESTION_MESSAGE,
                                             null, options, options[0] );
      return (String)options[selection];
   }//prompt   




}//inventory class

1 个答案:

答案 0 :(得分:0)

class SomeClass {
//method that accept your string and perform action
public void method(String str){
   //TODO Action 
   }
}

要使其工作,您需要在main中创建此类的对象。

SomeClass someclass = new SomeClass;
someclass.method(yourdata);