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;
}
}
}
}
}
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
Re: How can i fix and run my program?? Please help..
Code java:
<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;
}*/
}>
Re: How can i fix and run my program?? Please help..
Code java:
<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;
}
}
}
}
}>
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.
Re: How can i fix and run my program?? Please help..
Quote:
Originally Posted by
Norm
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.