Welcome to Dream.In.Code
Become a Java Expert!

Join 150,170 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,289 people online right now. Registration is fast and FREE... Join Now!




Inventory program pt 2

 
Reply to this topicStart new topic

Inventory program pt 2, AAAAHHH!!!! <tears out hair>

Behumat
28 Aug, 2008 - 10:41 AM
Post #1

New D.I.C Head
*

Joined: 28 Aug, 2008
Posts: 5

Can someone help me? I'm so frustrated I'm about ready to quit and start from scratch, but I think I'm close to a working program. Here's my code so far, I'll list the spots where I'm getting errors in bold. I just can't figure out what it is I'm missing here.

java

/*
* Java programming Pt 2. Modify the Inventory Program so the application can
* handle multiple items. Use an array to store the items. The output should
* display the information one product at a time, including the item number, the
* name of the product, the number of units in stock, the price of each unit,
* and the value of the inventory of that product. In addition, the output
* should display the value of the entire inventory.
*/

package invtprgmpt2;

import java.util.Scanner;
import java.util.Arrays;

public class Main
{
public static void main(String[] args)
{

Scanner input = new Scanner(System.in);
//declare product variables
String[] myArray = new String[100];
String productName[] = new String[100]; //product name array
int itemNumber[] = new int[100]; //item number array
int units[] = new int[100]; //unit number array
float priceUnit[] = new float[100]; //priceUnit array
int itemIndex = 0; //product index
float productValue[] = new float[100];
float totalValue = 0;
Arrays.sort(myArray);

//print out request headings
System.out.println( "\nProduct Project Pt2");
System.out.println( "\nEnter Software Information...");
//enter variables
System.out.print( "\nEnter Software Name or stop to quit:" );
productName[itemIndex] = input.nextLine();
//compare user input to termination string
while (productName[itemIndex].equals("stop")) //continue
System.out.print("Enter the item code, if any: ");
itemNumber[itemIndex] = input.nextInt();
System.out.print("Enter the number of software units: ");
units[itemIndex] = input.nextInt();
System.out.print("Enter the price for each unit: ");
priceUnit[itemIndex] = input.nextFloat();
itemIndex = itemIndex + 1; //should increment by 1
input.nextLine(); //clear buffer
System.out.print( "\nEnter Software Name or stop to quit");
} //end while
//print output
// prints output headings
{
System.out.printf( "\n%s\t%s\t%s\t%s\t%s\t%s\n", "Index", "Product #", "Product Name",
"# in Stock", "Unit Price", "Inventory Value");

// method to sort items by name
java.util.Arrays.sort(productName);

// print product list with inventory values
for (int index = 0; index < itemIndex; index++)
System.out.printf( "%5d\t%9d\t%12s\t%10d\t$%10.2f\t$%14.2f\n", index+1, productNumber[index], productName[index],
units[index], priceUnit[index], productValue[index] = ( units[index] * priceUnit[index]));

// add each product value to determine total inventory value
for ( int index = 0; index < itemIndex; index++ )
totalValue += productValue[index];

System.out.printf( "\nTotal inventory value: %.2f\n" , totalValue );

}// end main



}


package invtprgmpt2;

/**
*
* @author Richard Jarke
*/
public class product
{
private int itemNumber;
private String productName;
private int units;
private float priceUnit;


public Product(int itemNumber, String productName, int units, float priceUnit)

{
this.itemNumber = itemNumber;
this.productName = productName;
this.units = units;
this.priceUnit = priceUnit;

} //end constructor

public int getItemNumber()
{
return itemNumber;
}

public void setItemNumber(int itemNumber)
{
this.itemNumber = itemNumber;
}

public float getPriceUnit()
{
return priceUnit;
}

public void setPriceUnit(float priceUnit)
{
this.priceUnit = priceUnit;
}

public String getProductName()
{
return productName;
}

public void setProductName(String productName)
{
this.productName = productName;
}

public int getUnits()
{
return units;
}

public void setUnits(int units)
{
this.units = units;
}

public float getProductValue()
{
float number = getUnits() * getPriceUnit();
return number;
}

}


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

abgorn
RE: Inventory Program Pt 2
28 Aug, 2008 - 10:47 AM
Post #2

Hello Crap for Brains
Group Icon

Joined: 5 Jun, 2008
Posts: 912



Thanked: 5 times
Dream Kudos: 50
My Contributions
code.gif
User is offlineProfile CardPM
+Quote Post

Behumat
RE: Inventory Program Pt 2
28 Aug, 2008 - 11:01 AM
Post #3

New D.I.C Head
*

Joined: 28 Aug, 2008
Posts: 5

CODE
/*
* Java programming Pt 2. Modify the Inventory Program so the application can
* handle multiple items. Use an array to store the items. The output should
* display the information one product at a time, including the item number, the
* name of the product, the number of units in stock, the price of each unit,
* and the value of the inventory of that product. In addition, the output
* should display the value of the entire inventory.
*/

package invtprgmpt2;

import java.util.Scanner;
import java.util.Arrays;

public class Main
{
    public static void main(String[] args)
        {
          
        Scanner input = new Scanner(System.in);
                //declare product variables
        String[] myArray = new String[100];
        String productName[] = new String[100];    //product name array
        int itemNumber[] = new int[100]; //item number array
    int units[] = new int[100]; //unit number array
    float priceUnit[] = new float[100]; //priceUnit array
        int itemIndex = 0; //product index
        float productValue[] = new float[100];
    float totalValue = 0;
        Arrays.sort(myArray);
      
        //print out request headings        
        System.out.println( "\nProduct Project Pt2");
                System.out.println( "\nEnter Software Information...");
                //enter variables
                System.out.print( "\nEnter Software Name or stop to quit:" );
                    productName[itemIndex] = input.nextLine();
                //compare user input to termination string
                    while (productName[itemIndex].equals("stop")) //continue
        System.out.print("Enter the item code, if any: ");
                    itemNumber[itemIndex] = input.nextInt();
        System.out.print("Enter the number of software units: ");
                    units[itemIndex] = input.nextInt();
        System.out.print("Enter the price for each unit: ");
                    priceUnit[itemIndex] = input.nextFloat();
                itemIndex = itemIndex + 1; //should increment by 1
                input.nextLine(); //clear buffer
                System.out.print( "\nEnter Software Name or stop to quit");
        } //end while
        //print output
    // prints output headings
        {
        System.out.printf( "\n%s\t%s\t%s\t%s\t%s\t%s\n", "Index", "Product #", "Product Name",
         "# in Stock", "Unit Price", "Inventory Value");

      // method to sort items by name
      java.util.Arrays.sort(productName);

      // print product list with inventory values
      for (int index = 0; index < itemIndex; index++)
         System.out.printf( "%5d\t%9d\t%12s\t%10d\t$%10.2f\t$%14.2f\n", index+1, productNumber[index], productName[index],
            units[index], priceUnit[index], productValue[index] = ( units[index] * priceUnit[index]));

      // add each product value to determine total inventory value
      for ( int index = 0; index < itemIndex; index++ )
         totalValue += productValue[index];

      System.out.printf( "\nTotal inventory value: %.2f\n" , totalValue );

      }// end main


        
}


package invtprgmpt2;

/**
*
* @author Richard Jarke
*/
public class product
{
    private int itemNumber;
    private String productName;
    private int units;
    private float priceUnit;
        
        
    public Product(int itemNumber, String productName, int units, float priceUnit)
        
        {
        this.itemNumber = itemNumber;
        this.productName = productName;
        this.units = units;
        this.priceUnit = priceUnit;
                
    } //end constructor

    public int getItemNumber()
        {
        return itemNumber;
    }

    public void setItemNumber(int itemNumber)
        {
        this.itemNumber = itemNumber;
    }

    public float getPriceUnit()
        {
        return priceUnit;
    }

    public void setPriceUnit(float priceUnit)
        {
        this.priceUnit = priceUnit;
    }

    public String getProductName()
        {
        return productName;
    }

    public void setProductName(String productName)
        {
        this.productName = productName;
    }

    public int getUnits()
        {
        return units;
    }

    public void setUnits(int units)
        {
        this.units = units;
    }
    
    public float getProductValue()
        {
        float number = getUnits() * getPriceUnit();
        return number;
    }
    
}




User is offlineProfile CardPM
+Quote Post

nick2price
RE: Inventory Program Pt 2
28 Aug, 2008 - 11:07 AM
Post #4

D.I.C Regular
***

Joined: 23 Nov, 2007
Posts: 338



Thanked: 12 times
My Contributions
It would be a lot easier if you posted your code in tags. java.util.Arrays.sort, looking at the api for this, i cant see a method which performs a search on a String[]. And looking at your for loops, looks like you item index is initialised at 0 so you are comparing 0 = 0. Might be wrong on this part though, havnt compiled your code.

And correct me if i am wrong, but i see you end your while loop but i dont see where you open it.

This post has been edited by nick2price: 28 Aug, 2008 - 11:09 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:14AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month