Please-if anyone is online that can help me with a couple beginner Java programs... I have spent all day looking at them and I just can't figure out what I need to do...
Please help!!
Please help!!
//Inventory.java
//Class created to store item information for Inventory purposes
//Created November 15, 2006
//Modified November 29, 2006
//Audrey A. Paige
//IT315
class Product
{
private String name; // class variable that stores the item name
private int number; // class variable that stores the item number
private long stockQuantity; // class variable that stores the quantity in stock
private double price; // class variable that stores the item price
public Product() // Constructor for the Supplies class
{
name = "";
number = 0;
stockQuantity = 0L;
price = 0.0;
}
public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
{
this.name = name;
this.number = number;
this.stockQuantity = stockQuantity;
this.price = price;
}
public void setItemName(String name) // Method to set the item name
{
this.name = name;
}
public String getItemName() // Method to get the item name
{
return name;
}
public void setItemNumber(int number) // Method to set the item number
{
this.number = number;
}
public int getItemNumber() // Method to get the item number
{
return number;
}
public void setStockQuantity(long quantity) // Method to set the quantity in stock
{
stockQuantity = quantity;
}
public long getStockQuantity() // Method to get the quantity in stock
{
return stockQuantity;
}
public void setItemPrice(double price) // Method to set the item price
{
this.price = price;
}
public double getItemPrice() // Method to get the item price
{
return price;
}
public double calculateInventoryValue() // Method to calculate the value of the inventory
{
return price * stockQuantity;
}
}//end class Product
public class Inventory
{
// main methods begins execution of java application
public static void main( String args[])
{
Product p = new Product("Pencil", 5460, 125, 1.5);
System.out.printf("\n\nItem Name: %s\n",p.getItemName()); //display item name
System.out.printf("Item Number: %s\n",p.getItemNumber()); //display item number
System.out.printf("Quantity in Stock: %s\n",p.getStockQuantity()); //display quantity in stock
System.out.printf("Item Price: $%.2f\n",p.getItemPrice()); //display item price
System.out.printf("Value of Inventory: $%.2f\n",p.calculateInventoryValue()); //display total value of inventory for this item
} // end main method
}//end class Inventory
//Inventory.java
//Class created to store item information for Inventory purposes
//Created November 15, 2006
//Modified November 29, 2006
//Audrey A. Paige
//IT315
class Product
{
private String name; // class variable that stores the item name
private int number; // class variable that stores the item number
private long stockQuantity; // class variable that stores the quantity in stock
private double price; // class variable that stores the item price
public Product() // Constructor for the Supplies class
{
name = "";
number = 0;
stockQuantity = 0L;
price = 0.0;
}
public Product(String name, int number, long stockQuantity, double price) // Constructor for the Product class
{
this.name = name;
this.number = number;
this.stockQuantity = stockQuantity;
this.price = price;
}
public void setItemName(String name) // Method to set the item name
{
this.name = name;
}
public String getItemName() // Method to get the item name
{
return name;
}
public void setItemNumber(int number) // Method to set the item number
{
this.number = number;
}
public int getItemNumber() // Method to get the item number
{
return number;
}
public void setStockQuantity(long quantity) // Method to set the quantity in stock
{
stockQuantity = quantity;
}
public long getStockQuantity() // Method to get the quantity in stock
{
return stockQuantity;
}
public void setItemPrice(double price) // Method to set the item price
{
this.price = price;
}
public double getItemPrice() // Method to get the item price
{
return price;
}
public double calculateInventoryValue() // Method to calculate the value of the inventory
{
return price * stockQuantity;
}
public String toString()
{
return "Name :"+name + "\nNumber"+number+"\nPrice"+price+"\nQuantity"+stockQuantity + "\nValue"+calculateInventoryValue();
}
}//end class Product
public class Inventory2
{
// main methods begins execution of java application
public static void main( String args[])
{
String Products[] = new Products[3];
//instantiate Products array
for (i=0; i<3; ++i)
pencil = new Products ("Pencil", 5460, 125, 1.5);
//Product p = new Product("Pencil", 5460, 125, 1.5);
//System.out.printf("\n\nItem Name: %s\n",products[pencil] + Product.getItemName()); //display item name
//System.out.printf("Item Number: %s\n",products.pencil.getItemNumber()); //display item number
//System.out.printf("Quantity in Stock: %s\n",products.pencil.getStockQuantity()); //display quantity in stock
//System.out.printf("Item Price: $%.2f\n",products.pencil.getItemPrice()); //display item price
//System.out.printf("Value of Inventory: $%.2f\n",products.pencil.calculateInventoryValue()); //display total value of inventory for this item
} // end main method
}//end class Inventory2
Comment