For Part 2, I think you are going just have to go with your own best effort.
For Part 3, try to work out what you are not understanding, and ask
questions. The easiest questions to answer have the form "Why does this
*very* short program do X. I was expecting it to do Y for reasons A, B,
and C.".
Note that posting your actual partly complete homework and asking for
help with it would create ethical problems. Posting a very small program
that brings out some issue you are having does not.
Seehttp://home.earthlink.net/~patricia_shanahan/beginner.htmlfor some
general advice.
Patricia
Hello All,
I have written the app to the best of my ability and would like you to
look it over and let me know if I am at least on the right track and
give any help you deem necessary.
Here is the program:
//InventoryProgram1.java
//import java.util.Scanner; // allow for input
import java.util.Arrays;
import java.util.Scanner;
import java.lang.String;
class Product {
String Name;
int itemNumber;
int numberofunits;
int priceperunit;
public Product (String name, int itemNumber, int numberofunits,
int priceperunit); {
String Name = name;
this.itemNumber = itemNumber;
this.numberofunits = units;
this.priceperunit = price;
computeValueInventory ();
}
private void computeValueInventory () {
Value = Units * price;
}
}
public class InventoryProgram1 //declares public class inventory
{
public static void main(String args []) //starts the program
{
PRODUCT[] = new Product[3];
product[0] = new PRODUCT(1, "StApler",45, 2,
17.99 );//
declares a new item
// number, name
// quantity, and price
product[1] = new PRODUCT(2, "Calanders", 47, 4,
12.99 );
product[2] = new PRODUCT(3, "Toner", 49, 6, 19.99 );
//added changes
Inventory1 x = new Inventory1();
x.sortPRODUCT(product);
}// end main
public void SortPRODUCT(PRODUCT[] the PRODUCT) {
for (int index = 0; index < the PRODUCT.size - 1;
index++) {
String s1 = thePRODUCT[index].getProductName
();
String s2 = thePRODUCT[index] +
1].getProductName
();
if (comparewords(s1, s2)) {
PRODUCT temp = thePRODUCT[index];
thePRODUCT[index] = thePRODUCT
[index + 1];
thePRODUCT[index + 1] = temp;
index = -1;
}
}
}
private boolean comparewords(String s1, String s2) {
boolean islarger = false;
for (int index = 0; index < s1.length(); index++) {
if (index < s2.length()) {
if (s1.toLowerCase().charAT
(index) > s2.toLowerCase().charAT(index)) {
islarger = true;
break;
{
if (s1.toLowerCase().charAT
(index) < s2.toLowerCase().charAT(index) {
break;
{
}else {
return true;
}
}
return islarger;
}
//end of changes
} // end class Inventory1
class PRODUCT // declares class inventory
{
private int itemName;// declares item number as in
private String productTitle;// declares product title as
string
private int onHand; // declares on hand as int
private double productCost;// declares cost as double
public PRODUCT(int stockNumber, String title, int
inStock,
double price) // constructor
{
itemNumber = stockNumber;// intitiates stock
number, title, instock, and
// price
productTitle = title;
onHand = inStock;
productCost = price;
} //
// set PRODUCT StockNumber //sets stock number
public void seItemNumber(int stockNumber)
{
itemNumber = stockNumber;
}
public int getItemNumber() // class item number
{
return itemNumber; // returns item number
} // end method get PRODUCT Item
public void setProductTitle(String title) // set PRODUCT
Title
{
productTitle = title;
}
public String getProductTitle() // gets and returns PRODUCT
Title
{
return productTitle;
}
public void setOnHand(int inStock) // Set on hand
{
onHand = inStock;
}
public int getOnHand() // gets and returns on hand
{
return onHand;
} //
public void setProductCost(double price) // sets product cost
{
productCost = price;
}
public double getProductCost() // gets and returns PRODUCT
cost
{
return productCost;
}
public double value() // calculate the value of stock
{
return productCost * onHand;
}
} // end class Product
It is supposed to handle multiple items, use an array to store the
items, display the information one product at a time, including the
item number, the name of product, the number of units in stock, the
price of each, and the value of the inventory of that product. It
should also display the value of the entire inventory.