Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How can i fix and run my program?? Please help..

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    3
    My Mood
    Grumpy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy How can i fix and run my program?? Please help..

    I have 2 Clases Item and InventorySystem..
    I can't even run it i'm not sure why??


    import java.text.NumberFormat;
    import java.util.Scanner;

    public class Item
    {

    /**
    * Perform any initialization that is required for the Inventory items.
    *
    */

    // Declaring the modifiers for the inventory items.

    private String Name; // product name field
    private String ID; // products ID number
    private int Quantity; // quantity per product
    private double Price; // price per unit from stock
    private String Description; // product's information
    //private String size; // product size
    //private in unitsAtHand; // number of units in stock
    private int ReorderLevel = 5;

    String newName, newID, newDescription;
    int newQuantity, choice;
    double newPrice;
    int itemsold;


    Scanner scan = new Scanner(System.in);

    NumberFormat fmt = NumberFormat.getCurrencyInstance();


    //------------------------------------------------------------------------------
    // Create new items with given attributes.
    //------------------------------------------------------------------------------

    // Set the constructor. Set up the item by defining its fields.
    public Item ( String itemName, String itemID, int itemQuantity, double itemPrice, String itemDescription)
    {
    this.Name = itemName;
    this.ID = itemID;
    this.Quantity = itemQuantity;
    this.Price = itemPrice;
    this.Description = itemDescription;
    //size = itemSize;
    }

    public static void printMenu()
    {
    System.out.println("Super Outdoor Store");
    System.out.println("Choose from the following menu.");

    System.out.println("1: Enter a name item.");
    System.out.println("2: Remove or discontinue the existing item.");
    System.out.println("3: Check the specific item in stock.");
    System.out.println("4: Show the information about all existing items");
    System.out.println("5: Show the certain product's information.");
    System.out.println("6: Change the existing item.");
    System.out.println("7: Exit");
    System.out.println();
    }




    public String getName()
    {
    return Name;
    }

    public String getID()
    {
    return ID;
    }

    public int getQuantity()
    {
    return Quantity;
    }

    public String getPrice()
    {
    return fmt.format(Price);
    }

    public String getDescription()
    {
    return Description;
    }

    public void ReorderLevel()
    {
    System.out.println("Super Outdoor Store Inventory");
    System.out.println("Product name: "+ Name + " Quantity " + Quantity + " of the item and their" +
    "re-order level is set to "+ ReorderLevel);
    }

    public void infoModify()
    {

    System.out.println("Enter the new item name");
    newName = scan.next();
    Name = newName;

    System.out.println("Enter the new item ID");
    newID = scan.nextLine();
    ID = newID;

    System.out.println("Enter the new item Quantity");
    newQuantity = scan.nextInt();
    Quantity = newQuantity;

    System.out.println("Enter the new item price");
    newPrice = scan.nextDouble();
    Price = newPrice;

    System.out.println("Enter the new item description");
    newDescription = scan.next();
    Description = newDescription;

    //System.out.println("Enter the new item size");
    //String newSize = scan.next();
    }

    // -------------------------------------------------------

    // Return a string with the information about the item

    // -------------------------------------------------------

    public String toString ()

    {
    /*
    String item;
    if (Name.length() >= 8)
    {
    item = Name + "\t";
    }
    else
    {
    item = Name + "\t\t";
    */
    return (Name + "\t\t" + ID +"\t"+ Quantity +"\t"+ fmt.format(Price) + "\t" + Description);
    // +"\t "+ total value "+ fmt.format(price*quantity));

    }

    /*
    return item;
    }*/
    }
    ==============

    import java.util.ArrayList;
    import java.util.Scanner;

    public class InventorySystem
    {

    //Create an array and object to add it to the array
    private ArrayList<Item> inventory;


    public InventorySystem()
    {
    inventory = new ArrayList<Item>();
    }

    public void addItem( String iName, String iID, int iQuantity, double iPrice, String iDescription)
    {
    Item p = new Item(iName, iID, iQuantity, iPrice, iDescription);
    inventory.add(p);
    }


    public void removeItem(String ID)
    {
    Item p = searchItem(ID);
    int index = inventory.indexOf(p);
    if(index >= 0)
    {
    inventory.remove(index);
    if(!ID.equals(inventory))
    {
    System.out.print("Item " + ID + " has been removed from inventory");
    System.out.println();
    }
    }
    else
    System.out.print("Item "+ ID +" is not found! Enter another item");
    }

    public Item searchItem(String ID)
    {
    Item prodct = null;
    for(Item storeI : inventory)
    {
    if(storeI.getID().equals(ID))
    {
    prodct = storeI;
    }
    }

    return prodct;
    }


    public void newInfo(String ID)
    {
    searchItem(ID);

    for( Item storeI : inventory)
    {
    if(storeI.getID().equals(ID))
    {
    storeI.infoModify();
    }
    }
    }

    public void listInvt()
    {
    for(Item myItem : inventory)
    System.out.println(myItem);
    }


    public void checkQuantity( String ID)
    {
    searchItem(ID);

    for(Item item :inventory)
    {
    if(item.getID().equals(ID))
    {

    item.ReorderLevel();
    }

    }
    }


    public static void main (String[] args, String y)
    {

    Scanner scan = new Scanner(System.in);
    InventorySystem SuperOutdoorStore = new InventorySystem();




    String ItemName;
    String ItemID;
    int ItemQuantity ;
    double ItemPrice = 0;
    String ItemDescription;
    int choice = 0;
    int menu = 0;

    //String ItemSize;
    //String itemID;
    // itemAtHand= 0;
    //String itemOrderDate;
    //ArrayList<Item>inventory = new ArrayList<Item>();

    while( menu == 0)
    {
    System.out.println();
    System.out.println(" Welcome to Super Outdoor Store");
    System.out.println("Choose from the following menu.");
    Item.printMenu();
    System.out.println();
    System.out.println("Enter your selection: ");
    choice = scan.nextInt();

    switch(choice)
    {
    case 1: //Add new product to an inventory system.
    {

    String keepAdding = "y";

    do
    {


    System.out.println(" Enter the new product's name: ");
    ItemName =scan.next();

    System.out.println(" Enter new product's ID number: ");
    ItemID =scan.next();
    System.out.println("Enter new product's quantity: ");
    ItemQuantity =scan.nextInt();
    System.out.println("Enter new product's price: ");
    ItemPrice =scan.nextDouble();
    System.out.println("Enter new product's description:");
    ItemDescription =scan.nextLine();
    //ItemDescription =scan.nextLine();

    SuperOutdoorStore.addItem(ItemName,ItemID, ItemQuantity, ItemPrice, ItemDescription);

    System.out.print("Would you like to add more products (y/n)?");
    keepAdding =scan.next();
    }
    while(keepAdding.equals("y"));

    System.out.println();
    menu = 0;
    break;
    }
    case 2: // Remove an item from inventory system
    {
    System.out.println("Enter product's ID number to remove or discontinue: ");
    String item = scan.next();
    SuperOutdoorStore.removeItem(item);
    menu = 0;
    break;
    }

    case 3: // Search for an specific products in inventory system.
    {
    System.out.println("Enter product's ID number to list the product information: ");
    String items =scan.next();

    System.out.println(SuperOutdoorStore.searchItem(it ems));
    System.out.println();
    menu = 0;
    break;
    }

    case 4: // Give list of all the products in the inventory system.
    {
    SuperOutdoorStore.listInvt();
    menu = 0;
    break;
    }

    case 5: // Search for an specific products in inventory system.
    {
    System.out.println("Enter product's ID number to check the inventory: ");
    String ID = scan.next();
    SuperOutdoorStore.checkQuantity(ID);
    System.out.println();
    menu = 0;
    break;
    }

    case 6: // To modify the existing product in inventory system.
    {
    System.out.println();
    System.out.println("Enter product's ID number to make the changes: ");
    String ID = scan.next();
    SuperOutdoorStore.newInfo(ID);
    System.out.println();
    menu = 0;
    break;
    }

    case 7: // Exit the system message.
    {
    System.out.println("You have finished working with inventory.Thank You!");
    menu = 1;
    break;
    }
    }
    }
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How can i fix and run my program?? Please help..

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    BeginCode (May 6th, 2012)

  4. #3
    Junior Member
    Join Date
    May 2012
    Posts
    3
    My Mood
    Grumpy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How can i fix and run my program?? Please help..

    <import java.text.NumberFormat;
    import java.util.Scanner;
     
    public class Item
    {
     
    /**
    * Perform any initialization that is required for the Inventory items.
    * 
    */
     
    // Declaring the modifiers for the inventory items.
     
    private String Name; // product name field
    private String ID;	 // products ID number
    private int Quantity;	 // quantity per product
    private double Price; // price per unit from stock
    private String Description; // product's information
    //private String size;	 // product size
    //private in unitsAtHand; // number of units in stock
    private int ReorderLevel = 5;
     
    String newName, newID, newDescription;
    int newQuantity, choice;
    double newPrice;
    int itemsold;
     
     
    Scanner scan = new Scanner(System.in);
     
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
     
     
    //------------------------------------------------------------------------------
    // Create new items with given attributes.
    //------------------------------------------------------------------------------
     
    // Set the constructor. Set up the item by defining its fields. 
    public Item ( String itemName, String itemID, int itemQuantity, double itemPrice, String itemDescription)
    { 
    this.Name = itemName;
    this.ID = itemID;
    this.Quantity = itemQuantity;
    this.Price = itemPrice;
    this.Description = itemDescription;
    //size = itemSize;
    }
     
    public static void printMenu()
    {
    System.out.println("Super Outdoor Store");
    System.out.println("Choose from the following menu.");
     
    System.out.println("1: Enter a name item.");
    System.out.println("2: Remove or discontinue the existing item.");
    System.out.println("3: Check the specific item in stock.");
    System.out.println("4: Show the information about all existing items");
    System.out.println("5: Show the certain product's information.");
    System.out.println("6: Change the existing item.");
    System.out.println("7: Exit");
    System.out.println();
    }
     
     
     
     
    public String getName()
    {
    return Name;
    }
     
    public String getID() 
    {
    return ID;
    }
     
    public int getQuantity()
    {
    return Quantity;
    }
     
    public String getPrice()
    {
    return fmt.format(Price);
    }
     
    public String getDescription()
    {
    return Description;
    }
     
    public void ReorderLevel()
    {
    System.out.println("Super Outdoor Store Inventory");
    System.out.println("Product name: "+ Name + " Quantity " + Quantity + " of the item and their" +
    "re-order level is set to "+ ReorderLevel);
    }
     
    public void infoModify()
    {
     
    System.out.println("Enter the new item name");
    newName = scan.next();
    Name = newName;
     
    System.out.println("Enter the new item ID");
    newID = scan.nextLine();
    ID = newID;
     
    System.out.println("Enter the new item Quantity");
    newQuantity = scan.nextInt();
    Quantity = newQuantity;
     
    System.out.println("Enter the new item price");
    newPrice = scan.nextDouble();
    Price = newPrice;
     
    System.out.println("Enter the new item description");
    newDescription = scan.next();
    Description = newDescription;
     
    //System.out.println("Enter the new item size");
    //String newSize = scan.next();
    }
     
    // -------------------------------------------------------
     
    // Return a string with the information about the item
     
    // -------------------------------------------------------
     
    public String toString ()
     
    {
    /*
    String item;
    if (Name.length() >= 8)
    {
    item = Name + "\t";
    }
    else
    {
    item = Name + "\t\t";
    */
    return (Name + "\t\t" + ID +"\t"+ Quantity +"\t"+ fmt.format(Price) + "\t" + Description);
    // +"\t "+ total value "+ fmt.format(price*quantity));
     
    } 
     
    /*
    return item;
    }*/
    }>

  5. #4
    Junior Member
    Join Date
    May 2012
    Posts
    3
    My Mood
    Grumpy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How can i fix and run my program?? Please help..

    <import java.util.ArrayList;
    import java.util.Scanner;
     
    public class InventorySystem 
    {	
     
    //Create an array and object to add it to the array
    private ArrayList<Item> inventory;
     
     
    public InventorySystem()
    {
    inventory = new ArrayList<Item>(); 
    }
     
    public void addItem( String iName, String iID, int iQuantity, double iPrice, String iDescription)
    {
    Item p = new Item(iName, iID, iQuantity, iPrice, iDescription);
    inventory.add(p);	
    }
     
     
    public void removeItem(String ID)
    {
    Item p = searchItem(ID);
    int index = inventory.indexOf(p);
    if(index >= 0)
    {
    inventory.remove(index);
    if(!ID.equals(inventory))
    {
    System.out.print("Item " + ID + " has been removed from inventory");
    System.out.println();
    }
    }
    else
    System.out.print("Item "+ ID +" is not found! Enter another item");
    }
     
    public Item searchItem(String ID)
    {	
    Item prodct = null;
    for(Item storeI : inventory)
    {
    if(storeI.getID().equals(ID))
    {	
    prodct = storeI;
    }
    }
     
    return prodct;
    }
     
     
    public void newInfo(String ID)
    {
    searchItem(ID);
     
    for( Item storeI : inventory)
    {
    if(storeI.getID().equals(ID))
    {
    storeI.infoModify();
    }
    }
    }
     
    public void listInvt()
    { 
    for(Item myItem : inventory)
    System.out.println(myItem);
    }
     
     
    public void checkQuantity( String ID)
    {
    searchItem(ID);
     
    for(Item item :inventory)
    {
    if(item.getID().equals(ID))
    {
     
    item.ReorderLevel();
    }
     
    }
    }
     
     
    public static void main (String[] args, String y)
    {
     
    Scanner scan = new Scanner(System.in);
    InventorySystem SuperOutdoorStore = new InventorySystem();
     
     
     
     
    String ItemName; 
    String ItemID;
    int ItemQuantity ;
    double ItemPrice = 0;
    String ItemDescription;
    int choice = 0;
    int menu = 0;
     
    //String ItemSize;
    //String itemID;
    // itemAtHand= 0;
    //String itemOrderDate;
    //ArrayList<Item>inventory = new ArrayList<Item>();
     
    while( menu == 0)
    {
    System.out.println();
    System.out.println(" Welcome to Super Outdoor Store");
    System.out.println("Choose from the following menu.");
    Item.printMenu();
    System.out.println();
    System.out.println("Enter your selection: ");
    choice = scan.nextInt();
     
    switch(choice)
    {
    case 1: //Add new product to an inventory system.
    {
     
    String keepAdding = "y";
     
    do
    {
     
     
    System.out.println(" Enter the new product's name: ");
    ItemName =scan.next();
     
    System.out.println(" Enter new product's ID number: ");
    ItemID =scan.next();
    System.out.println("Enter new product's quantity: ");
    ItemQuantity =scan.nextInt();
    System.out.println("Enter new product's price: ");
    ItemPrice =scan.nextDouble();
    System.out.println("Enter new product's description:");
    ItemDescription =scan.nextLine();
    //ItemDescription =scan.nextLine();
     
    SuperOutdoorStore.addItem(ItemName,ItemID, ItemQuantity, ItemPrice, ItemDescription);
     
    System.out.print("Would you like to add more products (y/n)?");
    keepAdding =scan.next();
    }
    while(keepAdding.equals("y"));
     
    System.out.println();
    menu = 0;
    break;
    }
    case 2:	// Remove an item from inventory system
    { 
    System.out.println("Enter product's ID number to remove or discontinue: ");
    String item = scan.next();
    SuperOutdoorStore.removeItem(item);
    menu = 0;
    break;
    }
     
    case 3:	// Search for an specific products in inventory system.	
    {
    System.out.println("Enter product's ID number to list the product information: ");
    String items =scan.next();
     
    System.out.println(SuperOutdoorStore.searchItem(it ems));
    System.out.println();
    menu = 0;
    break;
    }
     
    case 4:	// Give list of all the products in the inventory system.	
    {
    SuperOutdoorStore.listInvt();
    menu = 0;
    break;
    }
     
    case 5:	// Search for an specific products in inventory system.	
    {
    System.out.println("Enter product's ID number to check the inventory: ");
    String ID = scan.next();
    SuperOutdoorStore.checkQuantity(ID);
    System.out.println();
    menu = 0;
    break;
    }	
     
    case 6:	// To modify the existing product in inventory system.	
    {
    System.out.println();
    System.out.println("Enter product's ID number to make the changes: ");
    String ID = scan.next();
    SuperOutdoorStore.newInfo(ID);
    System.out.println();
    menu = 0;
    break;
    }	
     
    case 7:	// Exit the system message.	
    {
    System.out.println("You have finished working with inventory.Thank You!");
    menu = 1;
    break;
    }
    }
    }
    }
     
    }>

  6. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: How can i fix and run my program?? Please help..

    Do you get any error messages when you compile or try to execute the program?

    I don't see a valid main() method.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #6
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can i fix and run my program?? Please help..

    Quote Originally Posted by Norm View Post
    I don't see a valid main() method.
    Norm is right your main method is invalid. Try moving it to its own class and remove the argument 'String y' from it.

    I'm not sure why you have 'String y' in the arguments for you main method in the first place since I can't find where its used. If you were trying to pass a command line argument to your program it will be passed in 'String[] args' thats what its there for.

Similar Threads

  1. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 9th, 2012, 12:47 AM
  2. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 07:29 AM

Tags for this Thread